VLANs, Trunking, and Spanning Tree
"I think that I shall never see / a graph more lovely than a tree. / A tree whose crucial property / is loop-free connectivity." — Radia Perlman, "Algorhyme" (1985)
A switch does exactly one thing well: it forwards frames inside a broadcast domain. That is a feature until the domain grows too large. Every ARP request, every DHCP discover, every broadcast from a chatty printer interrupts every device on the segment. The standard fix is not a bigger switch or a faster link; it is to build several logical networks on top of the same physical one. That is a VLAN.
This chapter covers the two ideas that make Layer 2 scale: VLANs, which divide one physical switch into several broadcast domains, and spanning tree, which keeps redundant paths between those domains from turning into loops. The two are usually taught together because they fail together: a trunk misconfiguration can leak traffic between VLANs, and a missing loop guard can take down every VLAN at once.
One Switch, Several Networks
A VLAN, or Virtual LAN, is a broadcast domain implemented in software (IEEE 802.1Q). Ports can be assigned to different VLANs, and the switch keeps their traffic separate even though the ports share the same hardware. A frame belonging to VLAN 10 is never flooded to ports in VLAN 20.
This is the same isolation subnetting gives you at Layer 3, moved down to Layer 2. A company can put engineering, guest Wi-Fi, and IP cameras on three VLANs, each with its own subnet, while using the same physical switches. A compromised camera cannot broadcast into the engineering segment, and a broadcast storm in one VLAN does not reach the others.
The isolation is not a security boundary by itself. It reduces the blast radius and makes policy enforceable, but a determined attacker on a misconfigured trunk can sometimes cross it. Treat the VLAN as the wall and the ACL or firewall between VLANs as the lock.
The 802.1Q Tag
The obvious question is how a frame tells the switch which VLAN it belongs to. The answer is a small tag inserted into the Ethernet header by IEEE 802.1Q:
+------+------+------+---------+------------+---------+------+
| Dst | Src | TPID | TCI | EtherType | Payload | FCS |
| 6 B | 6 B | 2 B | 2 B | 2 B | ... | 4 B |
+------+------+------+---------+------------+---------+------+
VLAN ID (12 bits, 1-4094)
The tag is four bytes. The TPID (0x8100) says "a VLAN tag follows." The TCI carries three fields: a 3-bit Priority Code Point used for QoS, a 1-bit Drop Eligible Indicator, and the 12-bit VLAN ID. Twelve bits allow IDs 1 through 4094; 0 and 4095 are reserved.
A port configured as an access port belongs to one VLAN and usually sends untagged frames — the devices plugged into it know nothing about VLANs. A trunk port carries many VLANs between switches or to a router, and every frame on it carries a tag except frames in the native VLAN. That is how one cable between two switches can carry the whole campus.
The native VLAN is the one VLAN whose frames are sent untagged on a trunk. It exists for compatibility, and it is a classic source of trouble: if the two ends disagree about which VLAN is native, frames silently land in the wrong network. On a well-run network it is changed to an unused VLAN and left alone. QinQ (802.1ad) stacks a second tag, which is how providers extend VLAN space beyond 4,094 or keep customer tags separate from their own.
[Switch A] === trunk (tags 10, 20, 30) === [Switch B]
| | |
access 10 access 20 access 30
Routing Between VLANs
A VLAN is a Layer 2 boundary, so devices in different VLANs cannot reach each other without a router. There are two common designs. Router-on-a-stick uses one physical link to the router, configured as a trunk with a subinterface per VLAN; the router tags and untags traffic as it routes between subnets. A Layer 3 switch does the same thing internally through switch virtual interfaces, routing between VLANs at wire speed, which is what most campuses and data centers use today.
Either way, the rule is the same: VLANs create the separation, and a Layer 3 device decides what is allowed to cross it. The separation is only as good as the router's rules.
Spanning Tree: Keeping the Loop From Eating the Network
Redundancy creates a new problem. Connect two switches with two cables, and a broadcast frame has two paths. Ethernet has no TTL, so the frame loops forever, multiplying every time it crosses a switch. Within seconds, the network is saturated and unusable. This is a broadcast storm, and it is one of the fastest ways to take down a LAN.
Spanning Tree Protocol (IEEE 802.1D) solves it by turning a looped physical topology into a loop-free logical tree. Switches exchange BPDUs (Bridge Protocol Data Units), elect one root bridge — the one with the lowest bridge ID, a priority plus a MAC address — and then every other switch chooses the best path to that root. Ports that would create a loop are put into a blocking state, so they carry no data. If a link fails, spanning tree reconverges and unblocks an alternate path.
Classic STP is slow: convergence can take 30 to 50 seconds, and ports pass through blocking, listening, learning, and forwarding. RSTP (Rapid Spanning Tree, 802.1w) cuts that to a few seconds with explicit port roles (root, designated, alternate, backup) and a proposal/agreement handshake. MSTP (802.1s) runs one tree per group of VLANs instead of one tree per VLAN, which keeps large networks manageable. Cisco's PVST+ runs a separate tree per VLAN, which gives finer control at the cost of more BPDUs.
Operational guards matter as much as the algorithm. BPDU Guard disables an access port that suddenly receives a BPDU, which stops a user from plugging in a switch and becoming the root. Root Guard prevents a downstream switch from taking over as root. Loop Guard blocks a port that stops receiving BPDUs instead of letting it forward into a loop. Data centers sometimes avoid spanning tree altogether with MLAG or EVPN/VXLAN fabrics, but the underlying problem — a loop is free, and Ethernet has no TTL — is the same one they are designing around.
What to Remember
VLANs let one physical switch act like several. Trunks let several VLANs share one cable. STP keeps redundant Layer 2 paths from becoming loops. None of these ideas changes what a frame is; they are all ways of controlling where that frame is allowed to go.
Layer 3 scales by routing; Layer 2 scales by dividing. VLANs and spanning tree are the tools that keep the divided part from collapsing into one big loop.
Frequently Asked Questions
Can two devices in different VLANs talk without a router? No. They are in different broadcast domains and different subnets. A Layer 3 device — a router or a Layer 3 switch — must route between them, and its ACLs decide whether that traffic is allowed.
Why do I need a trunk instead of just one cable per VLAN? A trunk carries many VLANs over one link, which is what makes VLANs practical between switches. One cable per VLAN would work but defeats the purpose of sharing infrastructure.
If spanning tree blocks a port, is that link wasted? It is on standby, not gone. If the active path fails, STP reconverges and the blocked port takes over. That is the point of paying for redundant cabling.
Is a VLAN the same thing as a subnet? Not exactly. A VLAN is Layer 2; a subnet is Layer 3. In practice they are usually mapped one-to-one, but a VLAN can carry multiple subnets and a subnet can span VLANs in unusual designs. The common, clean design is one VLAN per subnet.
Further Reading
- IEEE 802.1Q — Bridges and Bridged Networks (VLAN tagging)
- IEEE 802.1D — Media Access Control Bridges (spanning tree)
- Radia Perlman, "An Algorithm for Distributed Computation of a Spanning Tree in an Extended LAN," ACM SIGCOMM Computer Communication Review, 1985.
- Radia Perlman, Interconnections: Bridges, Routers, Switches, and Internetworking Protocols, chapters on bridging and spanning tree.
- Cisco, Campus LAN and Wireless LAN Solution Design Guide (VLAN and STP design sections).
Fun Facts and Notes
- The 12-bit VLAN ID gives 4,094 usable VLANs, which is why large providers invented Q-in-Q: stacking two tags to extend the space.
- Spanning tree was invented by Radia Perlman in the 1980s. Her poem about it, "Algorhyme," is one of the few pieces of protocol documentation written in verse.
- A broadcast storm can saturate a gigabit link in well under a second. This is why "just add another cable for redundancy" without STP is a gamble, not a design.
- The native VLAN exists mostly for backward compatibility with devices that do not understand tags. On a well-run network it is often changed to an unused VLAN and left alone.