Spanning Tree Protocol

term

networking

The Layer 2 protocol that blocks redundant switch links to prevent loops, keeping exactly one active path between any two points.

Prevents switching loops by computing a loop-free tree across a redundant mesh and blocking the links outside it. Ethernet has no time-to-live field, so a loop is fatal rather than merely inefficient.

A switched network needs redundant links so a failure does not isolate anything, and Ethernet cannot survive them: a frame with no time-to-live field will circulate forever, and a broadcast will multiply on every pass until the network is a solid wall of copies. Radia Perlman's answer in 1985 was an algorithm that takes an arbitrary mesh and computes a loop-free tree over it, blocking the links not in the tree and keeping them ready. She wrote it in about a week and summarised it in a poem, Algorhyme, which is the only IEEE standard anyone has committed to memory.

How it works. Switches elect a root bridge by comparing bridge IDs - a configurable priority followed by the MAC address, which means that with default priorities the oldest switch in the building usually wins, because low MAC addresses were assigned earlier. Every other switch finds its lowest-cost path to the root, that port becomes its root port, one switch on each segment owns the designated port, and everything else is blocked. Classic STP moves ports through blocking, listening, learning and forwarding, governed by a hello of 2 seconds, a max age of 20 and a forward delay of 15, which is why a topology change costs somewhere between thirty and fifty seconds. That was acceptable when the alternative was a broadcast storm and unacceptable by the time anyone ran voice over it.

The versions, and why each exists. RSTP (802.1w, later folded into 802.1D-2004) collapses the port states to discarding, learning and forwarding, adds alternate and backup port roles so a replacement path is precomputed rather than discovered, and negotiates directly with its neighbour instead of waiting for timers to expire - converging in seconds rather than tens of seconds. MSTP (802.1s, later 802.1Q-2005) addresses a different problem: one tree for the whole network means every VLAN follows the same path and half your links carry nothing. MSTP maps groups of VLANs to a small number of instances, so different VLANs can use different physical paths and the blocked links start earning their keep. Cisco arrived at the same need earlier and differently, with PVST running an instance per VLAN, then PVST+ for 802.1Q trunks, then Rapid PVST+ adding the RSTP behaviour - an approach that is simple to reason about and expensive at scale, because a thousand VLANs means a thousand state machines.

The accessories tell you where it hurts. PortFast exists because a printer does not need thirty seconds of listening and learning. BPDU Guard exists because PortFast on a port somebody later plugs a switch into is how you lose an afternoon, and Root Guard because a small switch under a desk should not be allowed to win a root election it technically qualifies for. Loop Guard covers the case where a link goes unidirectional and a blocked port stops hearing the BPDUs that were keeping it blocked - which is the failure that turns redundancy into an outage. Every one of these is a patch over the same underlying fact: the protocol trusts what it hears, and a network is full of things that can stop being heard.

And the successors. Shortest Path Bridging (802.1aq) and TRILL both replace the tree with a routed fabric, so all links forward and traffic takes the shortest path instead of the tree path. Neither displaced spanning tree in the enterprise, because a protocol that has run in every switch for three decades is not replaced by a better one, only by a different architecture - which is what modern leaf-and-spine with routing to the host actually is. Spanning tree did not lose. It was outlived.

All glossary entries