TTR Networks

What is STP?

Spanning Tree Protocol

STP (Spanning Tree Protocol) lets switches detect loops in a layer-2 network and block just enough ports to break them, preventing broadcast storms.

Ethernet frames have no hop count or TTL, so if switches are connected in a loop, a broadcast circulates forever, multiplying at every switch until the network collapses: a broadcast storm. Loops are often wanted, though, for redundancy. STP, originally standardised as IEEE 802.1D, keeps the redundant links but leaves only a loop-free tree active. Switches exchange messages called BPDUs and elect a root bridge, the one with the lowest bridge ID (a configurable priority, 32768 by default, followed by the switch's MAC address). Every other switch picks its root port, the port with the lowest cost path to the root. On each link, one end is the designated port, which forwards onto it. Any port that is neither is put into a blocking state. If a link fails, the tree is recalculated and a blocked port can start forwarding. Classic STP can take 30 to 50 seconds to do that, so most networks now run Rapid Spanning Tree (RSTP), which converges in seconds, or Multiple Spanning Tree (MSTP), which can run separate trees for groups of VLANs.

Most managed switches run some form of STP by default; a Linux bridge does not unless you enable it. Leave it on. Ports that connect only to end devices are usually configured as edge ports (PortFast on Cisco) so they start forwarding immediately, often with BPDU guard to shut the port if a switch is plugged in. A frequent design mistake is not choosing the root bridge, letting the oldest switch with the lowest MAC become root and drag traffic through it. STP has nothing to do with OSPF's SPF despite the similar name. The Switching basics lesson explains loops and why STP should stay enabled.

Lessons that use STP

  • Switching basics: layer 2, VLANs and IP addressingBeginner · 40 min

    How a switch learns MAC addresses and floods broadcasts, how IP subnets and default gateways decide where packets go, how VLANs split a switch into separate networks, and how trunks and a router connect them. Built on a real switch, three PCs and a VyOS router.

Related terms