Skip to content

Spanning Tree Protocol (STP)

Switches forward broadcast frames (ARP requests, DHCP discovers, etc.) to all ports except the one they arrived on. In a loop, broadcasts circulate forever:

Switch A ─────── Switch B
│ │
└──────────────────
(redundant link)
ARP broadcast enters Switch A:
→ Switch A sends it to Switch B via both links
→ Switch B receives 2 copies, sends each to Switch A via both links
→ Switch A receives 4 copies...
→ Broadcast storm! Network saturates in milliseconds.

This crash happens in seconds and is invisible until the network dies. STP prevents it by blocking redundant links while keeping them available as failover.


STP builds a loop-free logical topology by electing a root bridge and blocking the least-preferred ports on redundant paths.

All switches exchange BPDU (Bridge Protocol Data Units) messages. The switch with the lowest Bridge ID wins and becomes the Root Bridge.

Bridge ID = Priority (2 bytes) + MAC Address (6 bytes)
Default priority = 32768
Lower priority = preferred
If same priority, lower MAC address breaks the tie
Terminal window
# Check STP root and port roles (Cisco IOS)
show spanning-tree
# On Linux with brctl (software bridge)
brctl showstp br0

On every non-root switch, STP selects the Root Port - the port with the lowest-cost path to the Root Bridge.

Path cost by link speed:

SpeedSTP Cost (802.1D)
10 Mbps100
100 Mbps19
1 Gbps4
10 Gbps2
Section titled “Step 3: Block Designated Ports on Redundant Links”

After all root ports are elected, any remaining active links would create loops. STP blocks the inferior port on each such segment:

Root Bridge (Switch A)
│ (Root port on Switch B)
Switch B ─── Switch C (Root port on Switch C)
│ │
└───────────────┘
(one of these ports becomes BLOCKING)
StateDurationWhat happens
Blocking20s (MaxAge)Receives BPDUs but doesn’t forward frames
Listening15s (Forward Delay)Processes BPDUs, doesn’t forward frames
Learning15s (Forward Delay)Processes BPDUs, learns MAC addresses, doesn’t forward
ForwardingUntil topology changeFully operational
DisabledN/APort is admin down

RSTP converges in 1-2 seconds instead of 30-50. Key improvements:

AspectSTP (802.1D)RSTP (802.1w)
Convergence time30-50 seconds1-2 seconds
Port states5 (blocking/listening/learning/forwarding/disabled)3 (discarding/learning/forwarding)
Port rolesRoot / Designated / BlockingRoot / Designated / Alternate / Backup
BPDU originOnly Root Bridge generates BPDUsEach switch generates its own
NegotiationTimer-basedProposal/Agreement handshake
Backward compatibleN/AYes - degrades to STP if legacy switch detected

RSTP pre-designates Alternate Ports (backup root port paths) that can immediately transition to Forwarding if the current root port fails - no waiting for timers.


Cisco’s PVST+ runs a separate STP instance per VLAN. This allows different VLANs to have different root bridges and different blocked ports - enabling load balancing across redundant links:

VLAN 10: Root is Switch A, link A→C is blocked
VLAN 20: Root is Switch B, link B→C is blocked
Traffic flows:
VLAN 10: A → B (direct)
VLAN 20: B → A (direct)
Both links are in use!

IEEE standard equivalent: MSTP (802.1s) - Multiple Spanning Tree, maps VLANs to instances.


For ports connected to end devices (not other switches), waiting through STP states wastes 30 seconds on every reboot.

Terminal window
# Cisco: Enable PortFast on an access port
interface GigabitEthernet0/1
spanning-tree portfast # skip Listening and Learning - go straight to Forwarding
# BPDU Guard: if a BPDU is received on a PortFast port, shut it down
# (protects against someone plugging a switch into an access port)
spanning-tree bpduguard enable

Terminal window
# Cisco - see current STP topology
show spanning-tree vlan 10
# See which ports are blocking
show spanning-tree blockedports
# Check if root bridge is the expected one
show spanning-tree | include Root
# See STP events (topology changes cause MAC table flushes → traffic floods)
show spanning-tree detail | include changes
# Linux software bridge
bridge link show
brctl showstp br0

Common STP problems:

SymptomLikely Cause
Network freezes for 30s when a device connectsSTP reconvergence; enable PortFast on access ports
Intermittent MAC flapping in switch logsTopology change happening repeatedly - investigate rogue switch or link flap
Unexpected root bridgeSomeone accidentally set a lower priority on a server’s bridged interface
Broadcast stormLoop exists - STP not running on a switch in the path, or STP disabled