Packet Path/

VLANs, Trunks, and Spanning Tree — Switching Fundamentals

A VLAN is a broadcast domain. A trunk carries many of them. Spanning tree keeps the redundant ones from burning the building down. The three ideas that run every LAN.

Switching · Beginner · 13 min · September 30, 2026

Illustration of two switches with color-coded VLAN segments and a spanning-tree arc
In plain EnglishA switch connects devices, but without VLANs every device hears every other device's chatter — like one giant open-plan office where every conversation interrupts the whole floor. A VLAN splits that switch into separate virtual rooms. A trunk is the hallway that carries many rooms' traffic between switches. Spanning tree is the fire marshal that makes sure those hallways never loop back on themselves and trap traffic circling forever.

The office building analogy

Think of your network as an office building:

Why VLANs exist

Picture a 48-port switch with finance, engineering, and printers all plugged in. Without VLANs, every broadcast from one printer interrupts every host on the switch, and everyone's traffic mingles. A VLAN (virtual LAN) carves the switch into isolated broadcast domains (groups of devices that hear each other's broadcasts, and nobody else's). Same hardware, separate Layer 2 worlds.

Hosts in VLAN 10 talk to each other directly at Layer 2 (the switching layer, which forwards by MAC address). To reach VLAN 20, traffic must go up to Layer 3 — through a router or Layer 3 switch that forwards by IP address. That boundary is the point: isolation without buying more hardware.

Access ports and trunk ports

Switch ports play two roles:

Access ports and trunk ports

Switch ports play two roles:

Port typePurposeHow frames look
AccessOne VLAN, to an end device (PC, printer, server)Untagged — the host never sees VLANs
TrunkMany VLANs, switch-to-switch or switch-to-routerTagged with 802.1Q, except the native VLAN

The 802.1Q tag is a 4-byte header inserted into the Ethernet frame: a 2-byte TPID (tag protocol identifier — the value 0x8100 announces "this frame is tagged") and a 2-byte TCI (tag control information) carrying the 12-bit VLAN ID (1–4094 usable) plus 3 priority bits used for QoS. Tags get stripped when frames exit an access port — hosts stay blissfully unaware that VLANs exist.

Crossing a trunk: the 4-byte tag appears, then disappears PC VLAN 20 SW-1 access: 20 trunk → SW-2 ← trunk access: 20 PC VLAN 20 tag added → ← tag removed untagged tagged (802.1Q) untagged frame 8100 The red tag = TPID 0x8100 + VLAN ID. Hosts never see it.
The tag rides only the trunk. Watch the frame leave PC-1 untagged, gain its red 4-byte badge between the switches, and lose it before reaching PC-2.

The native VLAN trap

Every trunk has one native VLAN whose traffic crosses untagged. If both ends of a link disagree about which VLAN that is, frames from VLAN A arrive at the other side in VLAN B. Silent misdelivery. It is notoriously hard to spot, because pings within a VLAN still work when a link fails over.

Never ship thisKeep user traffic off the default VLAN 1, make native VLANs match on both ends of every trunk, and set modes explicitly: switchport mode trunk / switchport mode access. Cisco's DTP auto-negotiation is a VLAN-hopping attack waiting for a curious neighbor — turn it off with switchport nonegotiate.

Reading a BPDU like a packet capture

Switches hold STP elections by mailing each other BPDUs (Bridge Protocol Data Units) — small multicast frames that say "here is who I think the root is, and how far away it is." Below is an illustrative RSTP BPDU, the way Wireshark would show it. Click any field to see what it means.

0000  00 00 02 02 3c 80 00 00 1b 21 3a 4c 5d 00 00 00   ....<....!:L]....
0010  04 80 00 00 1b 21 3a 4c 5d 7f 80 01 00 01 00 14   .....!:L].........
0020  00 02 00 0f 00                                    .....
OffsetFieldBytes (hex)
0–1
Protocol Identifier — always 00 00A magic number that says "this is spanning tree." Every STP, RSTP, and MSTP BPDU starts with it.
00 00
2
Protocol Version — 02 = RSTP00 is classic 802.1D STP, 02 is Rapid STP (802.1w), 03 is MSTP.
02
3
BPDU Type — 02 = rapid/MSTP BPDU00 is a classic config BPDU, 80 is a topology-change notice.
02
4
Flags — 3c: designated port, forwardingEach bit is a yes/no signal. 0x3c = binary 0011 1100: port role 11 (designated), Learning = 1, Forwarding = 1.
3c
5–12
Root Identifier — who the sender believes is root8 bytes: a 2-byte priority (80 00 = 32768, the default) plus the root's 6-byte MAC address. Lowest combined value wins the election.
80 00 00 1b 21 3a 4c 5d
13–16
Root Path Cost — 4The sender's total cost to reach the root. A cost of 4 = one 1-Gbps hop.
00 00 00 04
17–24
Bridge Identifier — the sender itselfSame format as the Root Identifier: priority + MAC. If this matches the Root Identifier, the sender believes it is the root.
80 00 00 1b 21 3a 4c 5d 7f
25–26
Port Identifier — 80 01Port priority (128, default) + port number (1). The tiebreaker when two ports offer equal-cost paths.
80 01
27–34
Timers — message age, max age, hello, forward delayFour 2-byte values in 1/256-second units: Message Age, Max Age (20s), Hello Time (2s), Forward Delay (15s).
00 01 00 14 00 02 00 0f

Want to watch these on a real wire? Capture on a trunk port and filter stp — the Wireshark filter builder will build the exact display filter for you.

Why spanning tree exists

Redundant links are how networks survive failures. They are also loops — and a loop on a switch fabric is extinction-level. A broadcast frame circles forever, gets copied at every switch, and multiplies: that is a broadcast storm. MAC address tables flap between ports, CPU spikes, and the whole VLAN is effectively dead within seconds.

Spanning Tree Protocol (STP) solves it by electing a root bridge and computing a loop-free tree: every redundant link ends up forwarding or deliberately blocked. Blocked ports wake up when something fails — redundancy you can actually use.

STP convergence: elect a root, block the loop ✕ blocked (alternate) SW-A priority 4096 ♛ ROOT BRIDGE SW-B priority 32768 SW-C priority 32768 root port ↑ ↑ root port designated designated 1 · switches exchange BPDUs 2 · SW-A wins — lowest bridge ID (priority 4096) 3 · loop-free tree: SW-B–SW-C link blocked, ready as backup ● forwarding   ● blocking   ● BPDU in flight
Three switches, three links, one loop. SW-A's priority 4096 beats the 32768 defaults, so it becomes root. The extra B–C link is blocked — still cabled, still ready, forwarding zero traffic until a failure.

Root election and port roles

Bridges elect the root by the lowest bridge ID — a combo of a configurable priority (default 32768, set in steps of 4096) plus the switch's MAC address as the tiebreaker. Then every other bridge picks its shortest path to the root: the port on that path is its root port, each cable segment elects one designated port, and everything else gets blocked.

"Shortest" uses cumulative path cost (modern values): 10 Mbps = 100, 100 Mbps = 19, 1 Gbps = 4, 10 Gbps = 2. Faster pipe, cheaper cost, more likely to be the chosen path.

Classic STP walks ports through Blocking → Listening → Learning → Forwarding with ~15-second timers — roughly 30–50 seconds of darkness after a topology change. Rapid STP (802.1w) converges in seconds by negotiating link by link, and adds alternate and backup port roles so failover is instant.

! pick your root and backup-root ON PURPOSE — lowest MAC wins otherwise
spanning-tree vlan 10 priority 4096
spanning-tree vlan 10 priority 8192   ! on the backup root

! edge ports: skip the 30s wait, die if anyone talks STP back
interface range Gi1/0/1 - 24
 spanning-tree portfast
 spanning-tree bpduguard enable

! never let a downstream switch become root
interface Gi1/0/25
 spanning-tree guard root

Portfast tells the switch "this port leads to a PC, not another switch — skip the waiting and forward immediately." BPDU guard is the seatbelt: if a BPDU ever arrives on a portfast port, the port shuts down instead of risking a loop. Root guard refuses to let a downstream switch advertise a better root through that port.

The checklist that saves real LANs

  1. Place the root. If you did not configure priority, your root bridge is whoever has the lowest MAC — often a closet switch. Set it explicitly.
  2. Portfast only on edge ports. Loops downstream of portfast are unprotected — BPDU guard is the seatbelt.
  3. Verify after changes: show spanning-tree vlan 10 [brief|detail] — find "Root ID" and make sure it is who you expect.
  4. RSTP minimum in 2026. Run rapid per-VLAN or MSTP; nobody waits 50 seconds for convergence on purpose anymore.

The topology, drawn

Here is the building from the analogy: one switch per floor, VLANs 10/20/30 trunked between them, and a router on a stick doing the inter-VLAN routing. Sizing the subnets behind these VLANs is a two-minute job with the subnet calculator.

Three floors, one switch each, VLANs riding the trunks RTR-1 routes between VLANs CORE-SW trunk to router VLAN 10 · Finance VLAN 30 · Printers access ports — untagged access ports — untagged trunks — tagged 802.1Q (VLANs 10, 20, 30) SW-F1 floor 1 VLAN 10 ×2 · VLAN 20 ×1 SW-F2 floor 2 VLAN 20 ×2 · VLAN 10 ×1 SW-F3 floor 3 VLAN 30 ×2 · VLAN 20 ×1 A finance PC on floor 1 reaches a finance PC on floor 2 at Layer 2 — same VLAN, no router involved. Finance → Engineering crosses VLANs, so it goes up to RTR-1. VLAN 10 · Finance VLAN 20 · Engineering VLAN 30 · Printers
The building, wired. Every vertical link is a trunk carrying all three VLANs tagged; every device port is an access port in exactly one VLAN.
Try it yourselfSize the subnets behind these VLANs: the subnet calculator runs the block-size math in seconds. And when you're capturing on a trunk, the Wireshark filter builder builds the exact display filter for STP BPDUs.
Key takeaways
  • VLANs divide one switch into separate broadcast domains — isolation without more hardware.
  • 802.1Q trunks multiplex VLANs; native VLAN mismatch is a classic silent failure.
  • STP elects a root bridge and blocks redundant links to prevent broadcast storms.
  • Use RSTP edge ports and BPDU guard in real deployments.