Spanning Tree
A loop-free active topology on a switched LAN. Without it, broadcasts amplify until the LAN dies.
Level: intermediate
What is it?
Spanning Tree Protocol (STP) builds a loop-free active topology for redundant layer-2 Ethernet links. Switches exchange bridge protocol data units, elect a root bridge, and select port roles/states that block some forwarding paths while retaining backups.
Why does it matter?
Redundant L2 links improve resilience, but an unmanaged Ethernet loop can multiply broadcasts and destabilize MAC learning. STP keeps redundancy without allowing all physical links to forward at once.
Mental model
Treat the switches and links as a graph. STP selects one logical spanning tree from the redundant graph, then recalculates after topology changes so loops are avoided.
How it works
- The root bridge is elected using bridge ID, based on priority and MAC-address tie-breaking.
- Path costs help determine root ports and designated ports.
- Blocked/non-forwarding ports provide alternate links that can be activated after a failure.
- Rapid STP and vendor variants improve convergence, but exact timer and edge-port behavior matter.
- PortFast/edge settings should only be applied to appropriate endpoint-facing ports; BPDU protections help prevent accidental switch loops.
Steps
- Switches exchange BPDUs and elect the root bridge.
- Each non-root switch selects a root port for its best path to the root.
- Each segment selects a designated port; redundant ports are placed in non-forwarding states.
- When a link changes, the protocol recalculates and activates a safe alternate path.
Real-world usage
- Designing redundant campus and enterprise switching.
- Diagnosing broadcast storms and unexpected blocked ports.
Common mistakes
- Connecting redundant switches without a loop-control design.
- Enabling edge/PortFast behavior on a switch-to-switch connection without safeguards.
- Assuming a blocked port is broken rather than intentionally preventing a loop.
Interview questions
Why does STP block some healthy physical links?
It removes redundant paths from the active layer-2 forwarding topology so frames cannot circulate indefinitely, while keeping backup links available.
What determines the root bridge?
The switch with the best bridge ID wins, normally based on configured priority and then MAC-address tie-breakers.