Switching, VLANs, and Layer 2 Segmentation Questions
Layer 2 switching and segmentation: MAC learning, aging and forwarding (including unknown-unicast flooding and cut-through versus store-and-forward), VLAN design and 802.1Q trunking (tag format, native VLAN, DTP trunk negotiation, VTP, voice VLAN, private VLANs, Q-in-Q), spanning tree (STP, RSTP, MST and edge protection such as PortFast, BPDU guard and root guard), EtherChannel/LACP and MLAG, multicast handling with IGMP snooping, and the hand-off between layer 2 and layer 3 (SVIs, router-on-a-stick, routed ports). Covers access and trunk port configuration and verification, switch-level fault diagnosis (trunk and native VLAN mismatches, MAC flapping, broadcast storms, bundles that will not form), campus, small-office and data-centre VLAN plans, and migrating or renumbering VLANs with minimal downtime. Boundary: attack and defense mechanics (MAC flooding, DHCP snooping, ARP inspection, VLAN hopping), routing protocol configuration, VXLAN/EVPN overlays, fabric and whole-campus topology choice, device automation, and the generic layered troubleshooting method are covered elsewhere.
Compare the ways a network can route between VLANs, covering the router-on-a-stick, the SVI on a multilayer switch and a routed port. Start with how a layer 2 switch differs from a layer 3 switch when forwarding.
Sample Answer
Direct answer
A layer 2 switch forwards frames by destination MAC address using its MAC address table, and only inside a VLAN. A layer 3 (multilayer) switch does that too, and additionally routes packets between subnets by looking up the destination IP address in a routing table. Inter-VLAN routing can be done by a router on a trunk (router-on-a-stick), by an SVI (switch virtual interface, a routed interface for a VLAN) on a multilayer switch, or on a routed port (a physical port switched to layer 3). For a campus I would use SVIs for the VLAN gateways and routed ports for uplinks; router-on-a-stick only for a small branch.
Layer 2 versus layer 3 forwarding
| Layer 2 switching | Layer 3 routing | |
|---|---|---|
| Looks at | Destination MAC | Destination IP |
| Table | MAC address table | Routing table |
| Scope | One VLAN, one broadcast domain | Between subnets |
| Frame header | Unchanged | Rewritten for the next hop |
A host sending to a different subnet addresses the frame to its default gateway's MAC address and the destination IP to the far host. The gateway removes the old frame header, looks up the IP, and builds a new frame for the next hop.
The three methods
| Method | How it works | Cisco IOS | Best for |
|---|---|---|---|
| Router-on-a-stick | One router interface is a trunk with a subinterface per VLAN | interface GigabitEthernet0/0.10, encapsulation dot1Q 10, ip address 10.10.10.1 255.255.255.0 | Small branch, light inter-VLAN traffic |
| SVI on a multilayer switch | A routed interface for each VLAN inside the switch | ip routing, interface vlan 10, ip address 10.10.10.1 255.255.255.0 | VLAN gateways in a campus |
| Routed port | The port is taken out of layer 2 and given an IP | no switchport, ip address ... | Uplinks to core or firewall, point-to-point links |
What the lines mean:
interface GigabitEthernet0/0.10creates a subinterface, a virtual interface carved out of the router's one physical port, here one per VLAN (the.10is just a label that is conventionally the VLAN number).encapsulation dot1Q 10tells that subinterface to send and accept 802.1Q-tagged frames (frames carrying a VLAN tag) for VLAN 10 only.ip address 10.10.10.1 255.255.255.0makes the subinterface the default gateway of VLAN 10's subnet.- The parent physical interface carries no IP address itself and must be enabled with
no shutdown, otherwise none of its subinterfaces come up. - On the multilayer switch,
ip routingturns on the routing function,interface vlan 10is the SVI, the virtual gateway interface for VLAN 10, andno switchportturns a physical port into a routed port.
Router-on-a-stick: the switch port toward the router must be a trunk allowing the routed VLANs. Cisco's Catalyst 9300 VLAN guide has a Layer 3 subinterfaces chapter, so a 9300 can itself run subinterfaces; the router in this layout can therefore be a router or a multilayer switch, but with SVIs available a multilayer switch has no reason to hairpin traffic through one link. In this design all inter-VLAN traffic crosses one physical link. A flow from VLAN 10 to VLAN 20 enters the router tagged 10 and leaves tagged 20 on the same link, so it uses the link once in each direction. On a 1 Gbps full-duplex trunk the aggregate routed rate across all VLANs cannot exceed 1 Gbps in either direction.
SVI: routing happens inside the switch, so inter-VLAN traffic does not leave the box, and it scales with the switching hardware. Each VLAN needs one SVI, so the number of VLANs you route is the number of SVIs. Cisco's Catalyst 9300 Layer 3 subinterfaces chapter lists a maximum of 1000 SVI interfaces and says not to configure more than 4,000 Layer 3 interfaces in total (routed physical interfaces, SVIs and subinterfaces); limits differ by platform and release, so check the documentation for yours. For a campus with a few dozen VLANs per switch these ceilings are far away. An SVI needs ip routing globally.
Routed port: no VLAN and no gateway sharing; it is a plain IP interface and is the clean way to join a distribution switch to a core.
Worked example
PC 10.10.10.10 (VLAN 10) pings 10.10.20.20 (VLAN 20). With an SVI gateway: the PC ARPs for 10.10.10.1, sends the frame to the switch's MAC, the switch finds the destination subnet connected on interface vlan 20, ARPs for the host, and forwards in a new frame. With router-on-a-stick the same exchange crosses the trunk to the router and back. Trace it with illustrative values, VLAN 10 on 10.10.10.0/24, VLAN 20 on 10.10.20.0/24, router subinterfaces .10 (10.10.10.1) and .20 (10.10.20.1), PC1 10.10.10.10 and PC2 10.10.20.20:
- PC1 ARPs for its gateway 10.10.10.1 in VLAN 10; the router's Gi0/0.10 answers with the router's MAC (call it R).
- PC1 sends a frame with destination MAC R and destination IP 10.10.20.20. The switch adds the VLAN 10 tag and sends it up the trunk.
- The router receives it on subinterface .10 (tag 10 matches
encapsulation dot1Q 10), finds 10.10.20.0/24 connected on subinterface .20, and ARPs for 10.10.20.20 with tag 20. - It builds a new frame, source MAC R, destination MAC PC2, tag 20, and sends it out the same physical port.
- The switch removes the tag and delivers it to PC2's VLAN 20 access port.
The trunk carried the packet twice (in tagged 10, out tagged 20); with an SVI that hop never leaves the switch.
Trade-offs and pitfalls
Pick SVIs plus routed uplinks unless a router is all you have. Apply ACLs on the SVI or firewall, because routing between VLANs with no policy removes the segmentation. If the branch grows past what one link can carry, move the gateways to a multilayer switch.
A new colleague from the server team asks what a VLAN actually is and why the network team keeps asking to use them. Explain it in plain terms and say what changes for broadcasts, security boundaries and day-to-day operations once a network is split into VLANs.
Sample Answer
Direct answer
A VLAN (virtual local area network) is a way to split one physical switch network into several separate logical networks. Each VLAN is its own broadcast domain: a broadcast sent by one machine (a frame addressed to every device, such as an ARP or DHCP request) is delivered only to ports in the same VLAN. Think of one open-plan office floor that gets partitioned into rooms: same building and same wiring, but a shout stays inside its room, and getting from one room to another requires walking through a door (a router or layer 3 switch).
What changes once the network is split
Broadcasts. On a flat network every ARP (Address Resolution Protocol: "who has this IP address, tell me your MAC address") and every DHCP (Dynamic Host Configuration Protocol: automatic IP address assignment) discover reaches every host. With VLANs those broadcasts stop at the VLAN edge. Each VLAN is normally one IP subnet, so ARP only ever resolves addresses inside the sender's own subnet, and traffic to anything else is sent to the default gateway's MAC address. (A subnet is a block of IP addresses that share a prefix, such as 10.10.10.0/24; the default gateway is the router address a host sends to when the destination is outside its own subnet.)
Security boundaries. A VLAN gives you separation at layer 2: a server in VLAN 10 cannot be reached by a direct frame from a laptop in VLAN 20. Traffic between VLANs has to be routed, and the routing point (a firewall, a router, or the switch's layer 3 interface) is where you apply access control lists (ACLs: permit/deny rules). The boundary is only as strong as that routing point: if the gateway routes everything between VLANs with no ACL, the VLANs separate broadcasts but not risk. A VLAN is a segmentation tool, not a firewall.
Day-to-day operations.
- Moving a person or server to another network is a port configuration change, not a recabling job.
- Every VLAN needs its own subnet, its own default gateway, and its own DHCP scope (the pool of addresses the DHCP server may hand out for that subnet). A DHCP server in another subnet is reached through a DHCP relay agent on the gateway, which forwards the broadcast as unicast to the server.
- Switches are joined by trunk links that carry many VLANs over one cable, each frame labelled with its VLAN number. A VLAN missing from a trunk is the classic "works on this switch, dead on that one" fault.
- Shared environments with several tenants (customers or business units on the same switches) usually start with one VLAN per tenant, paired with separate routing instances (VRFs, virtual routing and forwarding tables: each tenant gets its own private routing table on the same router) or separate firewall policy per tenant. For example, tenants A and B may both use 192.168.1.0/24, which is an overlapping address plan. Each tenant's VLAN lands in its own VRF, so 192.168.1.10 in tenant A and 192.168.1.10 in tenant B never collide, because the router looks up each in a different table, and any traffic between tenants is allowed only where you deliberately permit it.
Worked example
A site has 600 devices: 200 servers, 200 user devices (199 PCs plus the shared printer) and 200 IP phones. Flat, they all share one subnet. A subnet of 2^h addresses has 2^h - 2 usable addresses (minus the network and broadcast addresses), where h is the number of host bits, so it must satisfy 2^h - 2 >= 600. With h = 9, 2^9 - 2 = 510, which is too small; with h = 10, 2^10 - 2 = 1022, which fits. Host bits are 32 minus the prefix length, so h = 10 means a /22. Every broadcast then reaches the other 599 devices. Split into three VLANs of 200 devices each, each subnet needs 2^h - 2 >= 200: h = 7 gives 126 (too small), h = 8 gives 254, so a /24 per VLAN:
| VLAN | Purpose | Subnet | Usable addresses |
|---|---|---|---|
| 10 | Servers | 10.10.10.0/24 | 254 |
| 20 | Users (PCs and the printer) | 10.10.20.0/24 | 254 |
| 30 | Voice | 10.10.30.0/24 | 254 |
A broadcast now reaches 199 other devices instead of 599, and the printer in VLAN 20 no longer sees server chatter. (Addresses and counts here are illustrative.) The users-to-servers path crosses the gateway, where an ACL can permit only the application ports the users need.
Trade-offs and pitfalls
- More VLANs means more gateways, DHCP scopes and trunk allowed-lists to keep consistent. Name and document them.
- Do not treat a VLAN as a security control by itself. Leaving unused ports in a default VLAN, or trunking user VLANs carelessly, weakens the separation.
- Keep VLAN size sensible: a VLAN stretched across the whole campus enlarges the failure domain (a layer 2 loop affects every switch it touches).
A 10,000-user company with three campuses wants a VLAN design that separates users, servers, management and guests. How do you decide how many VLANs to create and how large each broadcast domain should be, where do you place the layer 3 boundary and DHCP, and how does the choice between many small VLANs and fewer large ones play out day to day?
Sample Answer
Direct answer
Create VLANs by trust zone and by physical failure domain, never by org chart. Cap each user broadcast domain at a /23 (510 usable addresses) and plan it to about 60 percent occupancy at peak, so a /23 carries roughly 306 devices. Keep every VLAN inside one building, put the layer 3 boundary (the SVI, the switch virtual interface that acts as the VLAN's default gateway) on the building distribution pair, and run DHCP centrally with relays on each SVI. Give each campus one summarisable internal address block, and keep guests in a separate range outside it. Choose NAC-driven dynamic VLAN assignment for users and guests so the VLAN follows the person, not the wall jack. NAC (network access control) is a server that checks who or what has plugged in and tells the switch which VLAN to use, and it speaks to switches over RADIUS, a standard authentication protocol.
How many VLANs and how big each broadcast domain is
A VLAN is one broadcast domain: every broadcast (ARP requests, DHCP discovers) reaches every host in it, and every host's MAC address lands in the table of every switch that carries it. So two inputs set the count: trust zones (which traffic needs a firewall or ACL between it) and a size ceiling (how much broadcast noise and failure blast radius you accept).
Trust zones, each its own VLAN (and subnet) in every building. Users, servers and management are drawn from one internal address block per campus; guests come from a separate range outside it:
- Users (employees and managed laptops/phones).
- Servers (local file/print/application servers; the big server estate lives in the data center).
- Management (switch, access point and controller management addresses; reachable only from an admin jump host).
- Guests (internet only, client isolation meaning guest devices cannot talk to each other on the Wi-Fi, own address range).
Restricted classes such as contractors and quarantined devices are extra NAC roles in the same scheme.
Size ceiling. There is no standard for "maximum hosts per VLAN"; this is an engineering rule of thumb. I use /23 for user VLANs: 2^(32-23) - 2 = 510 usable addresses, planned to 60 percent peak occupancy (0.6 x 510 = 306 devices) so growth and DHCP lease churn do not exhaust the scope. A /24 gives 254 usable addresses; a /22 doubles the broadcast domain to 1,022.
Worked example, 10,000 users over three campuses. Assume two network devices per user (a laptop and a phone on Wi-Fi). Campus A has 4,000 users, B 3,500, C 2,500.
| Campus | Users | Devices (x2) | User VLANs at 306 each | Peak fill per VLAN |
|---|---|---|---|---|
| A | 4,000 | 8,000 | 27 | 58.1% |
| B | 3,500 | 7,000 | 23 | 59.7% |
| C | 2,500 | 5,000 | 17 | 57.7% |
| Total | 10,000 | 20,000 | 67 |
The 67 is the minimum that the capacity ceiling allows, because it assumes every VLAN is filled to 306. The physical layout can only raise it: a floor with 150 devices gets its own VLAN sized /24 rather than sharing a /23 with another building. For example, if campus A's 8,000 devices sit on 60 floors, that is 60 VLANs of about 133 devices each (8,000 / 60), roughly 52 percent of a /24's 254 usable addresses, rather than the 27 minimum. A /18 holds 64 /24 blocks, so the address plan below still fits. Use the table to size the floor and the layout to set the real count. Add roughly three more VLANs per building, one each for local servers, management and guests; the point-to-point links between switches are routed ports and need no VLAN.
Where the layer 3 boundary and DHCP go
Layer 3 boundary. Terminate user VLANs on the building distribution pair, with the VLAN confined to that building (access switches trunk to the distribution pair only; no VLAN spans buildings, and none spans campuses). Why: a spanning tree loop or broadcast storm stays inside one building, and inter-building and inter-campus links carry routed traffic only. Each building's local-server VLAN terminates on that building's distribution pair like the others, and the data-center server estate terminates on the data-center pair, both behind firewall policy. Management VLANs terminate on the distribution pair but are only routable from the admin jump host range. Guests terminate in a separate routing context (a VRF, virtual routing and forwarding instance, or directly on the firewall) whose only route leads to the internet, so a guest has no path to 10.0.0.0/8 even if an ACL is mistyped. Guests still need DHCP and DNS, so the guest SVIs relay to a guest DHCP service, and point guests at a resolver, that live inside that guest context (on the firewall or in a small DMZ server), not to the internal data-center servers; otherwise the only-route-to-the-internet rule would be broken.
DHCP. Run two DHCP servers in the data center configured for failover for all the internal VLANs, not one DHCP server per VLAN (guest scopes are served inside the guest context, described above). A client that has no address yet can only broadcast, and broadcasts do not cross subnets, so each SVI acts as a relay: it forwards the client's broadcast to the server as a unicast. On Cisco IOS this is the ip helper-address command in SVI configuration (the Cisco guide example is interface vlan 1, ip address ..., ip helper-address 172.16.1.2). The relay stamps the SVI's address into the request (the giaddr field, the relay agent IP address in the DHCP message), which is how the server knows which scope to answer from: per RFC 2131 it allocates from the subnet that contains giaddr. Example with the excerpt below: the request arrives with giaddr 10.8.64.1, the server finds the scope 10.8.64.0/23 that contains that address, and leases the client an address from it, such as 10.8.64.57 (illustrative). Excerpt for one user VLAN (Cisco IOS; the vlan, name, interface vlan, ip address and ip helper-address forms are the ones in Cisco's configuration guides):
vlan 101
name USERS-A-BLDG1-F1
interface vlan 101
ip address 10.8.64.1 255.255.254.0
ip helper-address 10.200.10.10
For redundancy of the relay itself, check your platform's documentation for listing a second server; the scope design below does not depend on it. Make guest scopes use short leases (the right value is a site choice, for example one hour) because guest devices come and go and a /23 fills with stale leases otherwise.
Addressing that summarises per campus
Using Python's ipaddress module to check the plan:
| Purpose | Campus A | Campus B | Campus C |
|---|---|---|---|
| Campus block | 10.8.0.0/16 | 10.9.0.0/16 | 10.10.0.0/16 |
| Management block (one VLAN per building) | 10.8.0.0/24 | 10.9.0.0/24 | 10.10.0.0/24 |
| Local servers block (one VLAN per building) | 10.8.8.0/24 | 10.9.8.0/24 | 10.10.8.0/24 |
| User VLANs | 10.8.64.0/18 carved into 32 x /23 | 10.9.64.0/18 | 10.10.64.0/18 |
| Guest block (one VLAN per building) | 172.20.0.0/23 | 172.20.2.0/23 | 172.20.4.0/23 |
Checks: a /18 holds 32 /23 blocks, which covers A's 27, B's 23 and C's 17 user VLANs. The three campus blocks sit inside 10.8.0.0/14 (10.11.0.0/16 stays reserved for a fourth site). Route summarisation means advertising one route that stands for many: 10.8.0.0/16 covers every internal campus A subnet, meaning users, local servers and management (65,536 addresses), so the WAN and data center hold one route per site, or the single 10.8.0.0/14 for the company, instead of one route per VLAN. The guest ranges sit inside 172.20.0.0/21 (private space under RFC 1918's 172.16.0.0/12) and deliberately outside 10.0.0.0/8, so "deny 10.0.0.0/8" on the guest edge is one line, and the guest ranges are summarised and filtered on their own, apart from the campus blocks. Users that need a /24 instead of a /23 take half a block and the rest stays free. The per-campus management, server and guest blocks are carved per building: for example, a four-building campus could split its guest /23 into four /25s (126 usable addresses each) and its management /24 into four /26s (illustrative sizes), so no VLAN spans buildings and the campus still summarises as one block.
NAC-driven dynamic VLAN assignment for users and guests
Network access control (NAC) authenticates each device with IEEE 802.1X (the port-based authentication standard: the switch port stays closed to everything except authentication until the device proves its identity) and the RADIUS server answers with the VLAN to place it in. When authentication succeeds, the RADIUS server's Access-Accept reply carries the VLAN, for example (VLAN ID illustrative):
Access-Accept
Tunnel-Type = VLAN (13)
Tunnel-Medium-Type = 802 (6)
Tunnel-Private-Group-ID = "101"
The switch then puts that port into VLAN 101. RFC 3580 defines the three attributes: Tunnel-Type = VLAN (13), Tunnel-Medium-Type = 802 (value 6 in RFC 2868's list), and Tunnel-Private-Group-ID = the VLAN ID as a string (12 bits, 1 to 4094). So the same access port puts an employee laptop in USERS-A-BLDG1-F1, a contractor in a restricted VLAN and an unmanaged device in a quarantine or guest VLAN. Guests normally arrive through a guest SSID (wireless network name) or a captive portal (a web page that intercepts a new device and asks it to sign in or accept terms) that lands them in the guest VLAN. The consequences for the design:
- The VLAN number returned must exist on the access switch and be trunked to the distribution pair, so the role VLANs are defined per building and the NAC policy returns the building's own VLAN ID.
- Decide what the port does when RADIUS is unreachable or rejects the device (fail open to guest, fail closed, or keep the last VLAN). That choice is a business decision recorded before rollout.
- Role-based VLANs multiply the VLAN count by roles per building, which is another reason to cap roles at a handful and use ACLs or group-based policy for finer separation instead of more VLANs.
Many small VLANs versus fewer large ones, day to day
| Concern | Many small (/24 or smaller) | Fewer large (/22 and up) |
|---|---|---|
| Broadcast and ARP load | Low per host | Higher; every host hears every broadcast |
| Failure blast radius | One closet or floor | A loop or storm hits thousands of devices |
| DHCP | More scopes and SVIs to build and track | Fewer scopes, but one scope exhaustion hits many users |
| Policy | Easy to filter per floor or role at the SVI | Coarse, firewalling is by large group |
| Troubleshooting | A subnet tells you the floor | Needs a MAC or port lookup to locate a host |
| Wireless roaming | A roam across VLANs changes IP unless the wireless controller tunnels the client's traffic back to an anchor, the controller where its original VLAN lives, so the address survives | Same VLAN across APs keeps the IP |
| Operations | More objects to automate | Fewer objects, harder incidents |
Recommendation: small-to-medium VLANs (/24 to /23) per building with the ceiling above, because incident size is the cost that hurts and object count is cheap once VLANs, SVIs and DHCP scopes come from templates. What would flip it: a Wi-Fi design that needs one subnet across a whole building (keep the large VLAN there and cap it at /22 with controller-based roaming), or an overlay fabric (such as VXLAN, a tunnelling scheme that carries layer 2 over layer 3) where stretching a segment no longer means a spanning tree domain.
Pitfalls
- Letting a VLAN span campuses "for convenience": one loop then takes down three sites.
- Numbering VLANs inconsistently so the ID tells nobody the building or role (the ID scheme is documented and automated).
- Leaving unused ports in the default VLAN 1 (the default VLAN created at system initialization) or using it for management.
- Sizing the DHCP scope to the headcount instead of the device count: the 10,000 users in this example are 20,000 devices.
Explain how an Ethernet switch learns MAC addresses and decides where to send a frame. Cover what happens when the destination is unknown, and what that flooding means for a large broadcast domain.
Sample Answer
Direct answer
A switch learns by reading the source MAC address of every frame it receives and recording "this address lives behind this port, in this VLAN" in its MAC address table (also called the CAM table, after content-addressable memory, the fast lookup hardware that holds it). It forwards by looking up the destination address. A known unicast destination goes out one port only. An unknown unicast destination, a broadcast, or a multicast (unless the switch filters multicast, for example with IGMP snooping) is flooded out every other port in the same VLAN. A MAC address is the 48-bit hardware address of a network card.
How learning and forwarding work, in order
- A frame arrives on port Gi1/0/5 in VLAN 10 with source MAC
aaaa.aaaa.aaaa. The switch adds or refreshes the entry (VLAN 10,aaaa.aaaa.aaaa, Gi1/0/5) and resets that entry's age timer. - It looks up the destination MAC in the same VLAN's table. The table is effectively per VLAN: the same MAC may appear in two VLANs on two ports.
- Three outcomes:
- Known, on a different port: forward out that one port only.
- Known, on the port the frame arrived on: filter (drop). The destination is behind the same port, for example a hub or a downstream switch, and already saw the frame.
- Unknown: flood out all ports in that VLAN except the one it arrived on (the ingress port, meaning the port a frame enters by).
- Entries age out. The usual Cisco default is 300 seconds, set with
mac address-table aging-time <seconds>(check the platform's command reference for the permitted range and for what a value of 0 does). Static entries (mac address-table static) never age.
Per-entry fields and special destinations
| Item | What the table or switch holds | Why it matters |
|---|---|---|
| VLAN | The VLAN ID the address was learned in | Same MAC can exist in several VLANs |
| MAC address | 48-bit address from the frame source field | The lookup key |
| Port | Ingress port (or port-channel) | Where to send known unicast |
| Type | Dynamic (learned, ages) or static (configured, never ages) | Static pins a server or blocks moves |
| Age | Time since the entry was last refreshed by a frame from that source | Idle entries expire after the aging time |
- Broadcast (destination
ffff.ffff.ffff) is never learned as a source and is always flooded within the VLAN: every host must process it. - Multicast, where the switch does no multicast filtering, is flooded within the VLAN, because no multicast address ever appears as a source. A switch can be given a feature to restrict it to interested receivers (IGMP snooping, where the switch listens to hosts' group-join messages), which is outside the table described here.
What flooding means for a large broadcast domain
A broadcast domain is every port that receives a broadcast sent by any one host, which on a switch is one VLAN. Flooding turns each unknown unicast, broadcast and multicast frame into N-1 copies (if the VLAN has N active ports, one copy leaves every port except the one the frame arrived on, so a 24-port VLAN produces 23 copies of every flooded frame). Every host in the VLAN spends CPU on broadcasts (ARP, DHCP discovery, some discovery protocols), and every switch-to-switch link carries all of it. If the topology has a layer 2 loop that spanning tree has not blocked, flooded frames circulate forever and multiply (a broadcast storm), and the MAC table thrashes because the same source address keeps appearing on different ports.
Worked example: unknown unicast and aging
Host A (aaaa.aaaa.aaaa, port 1) sends to host B (bbbb.bbbb.bbbb, port 2) on a fresh 4-port switch in one VLAN.
- A's first frame is an ARP request to the broadcast address. The switch learns A on port 1, then floods to ports 2, 3 and 4.
- B replies, unicast to A. The switch learns B on port 2 and, because A is known, sends the reply out port 1 only. Ports 3 and 4 never see it.
- A now sends to B: both are known, so each frame goes out exactly one port.
- If B stays silent for 300 seconds (the default aging time) its entry expires. A's next frame to B is an unknown unicast and floods again until B transmits something.
Mitigating excessive flooding
- Shrink the flood scope: keep broadcast domains small. One VLAN per function, with a layer 3 boundary between them, bounds the flood scope. A /24 (254 usable addresses) per VLAN is a common ceiling in campus designs because broadcast load grows with host count.
- Prevent loops: keep spanning tree healthy so flooded frames cannot circulate. On user ports enable PortFast (the port goes straight to forwarding, skipping the listening and learning states) together with BPDU guard (if the port ever receives a spanning-tree BPDU, meaning a switch has been plugged in, the switch shuts the port into the err-disabled state). A stray switch then cannot change the topology.
- Stop table flooding attacks: cap MAC addresses per access port. Port security, the switch feature that limits how many and which MAC addresses a port may learn, has a default limit of one secure MAC address per port, raised with
switchport port-security maximum <value>. The default violation mode is shutdown (error-disabled), and restrict or protect modes drop offending frames instead. This also blunts a MAC flooding attack, where an attacker fills the table with fake sources so legitimate destinations become unknown and are flooded. - Avoid asymmetric paths that leave a destination unlearned. A switch learns only from frames it sees B send. Suppose A sends to B through switch sw-1, but B's replies travel back over a different path that never passes through sw-1. sw-1 never sees B as a source, so it never learns B's port and floods every frame addressed to B, for as long as the asymmetry lasts. Fix the path so replies cross sw-1, or add a static entry for B.
- Size the aging time to the traffic. Lengthening it above 300 seconds reduces re-flooding for quiet hosts but slows stale-entry cleanup after a host moves.
Trade-offs and pitfalls
- Learning is from the source only. A host that never transmits is never learned and always gets flooded traffic.
- A host that moves ports is relearned on its next frame. If the old entry has not aged, traffic misdirects only until that frame arrives.
- A MAC table has finite capacity. When a table is full, behaviour on new sources depends on the platform, so check the datasheet rather than assuming.
Why does a switched network with redundant links need a loop-prevention protocol at all? Describe what actually happens on the wire without one, and how the protocol keeps the redundancy usable.
Sample Answer
Direct answer
Ethernet has no hop counter in its frame header, and a switch floods broadcasts, multicasts and frames to unknown destinations out of every port except the one they arrived on. With redundant links and no loop prevention, those frames circulate forever and multiply, which is a broadcast storm. STP (Spanning Tree Protocol) keeps the redundant cabling but logically blocks enough ports to leave a loop-free tree, and unblocks one if a forwarding link fails.
What happens on the wire without it
- A host sends an ARP broadcast. Switch 1 floods it out every other port, including both links toward the other switches.
- Each switch that receives a copy floods it out all its other ports, including the next loop link, so the copy comes back around.
- Each pass duplicates the frame onto every extra link, so copies multiply. In a full mesh of four switches the starting broadcast leaves on 3 links (3 copies) and each copy is re-flooded on 2 other links, giving 3, 6, 12, 24, 48 ... 1536 copies after 10 hops (3 x 2^9).
- Links and switch CPUs fill with duplicate frames, legitimate traffic is crowded out, and every hop is also delivered to hosts.
- The MAC address table (source MAC to port mapping) keeps changing: the same source MAC is seen arriving on different ports, so unicast frames follow the flapping entries and arrive duplicated or in the wrong place.
With only two parallel links between two switches, each broadcast yields two copies that circle forever in opposite directions, and every new broadcast adds two more, so the loop is permanent even without exponential growth.
How STP keeps the redundancy usable
- Switches exchange BPDUs (bridge protocol data units, small hello messages sent between switches). Each switch has a bridge ID: 2 bytes of priority (default 32768) followed by the switch's 6-byte MAC address, compared as one number. The switch with the lowest bridge ID becomes the root bridge, the reference point every other switch measures from.
- Every other switch keeps the single lowest-cost path to the root: the port on that path is its root port. Each link between two switches (a segment) also gets one designated port, the end that is closer to the root, and that port forwards.
- Every remaining port is blocked: it receives BPDUs but forwards no user traffic, which cuts every loop.
Worked example with illustrative numbers: three switches A, B and C in a triangle, all links 1 Gbps (path cost 20,000 each under Cisco's long cost method), all at default priority 32768, with MACs 0011.1111.1111 (A), 0022.2222.2222 (B) and 0033.3333.3333 (C). Priorities tie, so the lowest MAC decides and A is root. B reaches A directly at cost 20,000, or via C at 20,000 + 20,000 = 40,000, so B's root port is the direct link; C does the same. On the B-C segment both switches offer a cost of 20,000 to the root, another tie, so the lower bridge ID wins: B's end is designated and forwards, C's end is blocked. The A-B and A-C links forward and the B-C link is cut at C, so the triangle becomes a loop-free path.
4. BPDUs continue on blocked links. Cisco's defaults are a 2 second hello, 15 second forward delay and 20 second max age. If a forwarding link fails and the blocked port stops hearing a better BPDU, classic STP waits the max age (20 s, how long a switch keeps the last BPDU before declaring it stale) and then passes through listening (15 s, the port discards user traffic and only takes part in the election) and learning (15 s, it still discards user traffic but starts building its MAC table). Each of those 15 s stages is one forward delay, so the worst case is roughly 50 seconds (20 + 15 + 15). Rapid PVST+ (the default mode in Cisco's Catalyst 9300 guide) uses a proposal and agreement handshake, in which two neighbouring switches agree directly with each other that a link is safe to forward on, instead of waiting on those timers, so it recovers much faster.
5. To avoid wasting the blocked link, per-VLAN spanning tree (PVST+, one separate spanning tree per VLAN) elects a root per VLAN. Picture an access switch X with one uplink to switch 1 and one to switch 2, and switches 1 and 2 linked to each other. Make switch 1 root for VLAN 10 and switch 2 root for VLAN 20. For VLAN 10, X's best path to the root is the uplink to switch 1, so the uplink to switch 2 blocks for VLAN 10; for VLAN 20 it is the other way round. Each uplink forwards for one VLAN and blocks for the other, so both carry traffic.
Trade-offs and pitfalls
STP trades capacity for safety: blocked links carry nothing until a failure. Do not disable it to get the bandwidth back; use a port-channel (EtherChannel, several physical cables bundled and treated as one link) so parallel links are one forwarding port, or route at layer 3. Edge ports that could receive a rogue switch need BPDU guard, because an unmanaged switch cabled into two wall ports is the everyday way a loop appears.
Unlock Full Question Bank
Get access to all 9 Switching, VLANs, and Layer 2 Segmentation interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.