Spanning Tree Protocol (STP): Preventing loops in switch networks
In short: A method that prevents loops in Ethernet networks with several switches by logically switching off surplus connections.
In more detail: If switches are connected by more than one cable between two points, a loop forms. Ethernet frames have no lifetime, so they could circulate there endlessly and paralyse the network (broadcast storm). STP (IEEE 802.1D) picks a loop-free tree from all connections and keeps the rest ready as backup.
In Depth
The problem: loops
A switch forwards broadcasts to all ports except the one they arrived on. If there are two paths between two switches, each sends the broadcast back over both paths, and the packets multiply. Unlike IP, an Ethernet frame has no TTL field that eventually stops the packets. A broadcast storm can make a network unusable within seconds.
How STP works
- The switches exchange small messages (BPDUs) and elect a root bridge, usually the one with the lowest bridge ID (priority plus MAC address).
- Every other switch determines the port with the cheapest path to the root bridge (root port).
- One designated port is chosen per network segment.
- All remaining ports are put into the blocking state: they do not forward data but keep listening.
Failure and switchover
If an active link fails, the switches notice by the missing BPDUs and activate a blocked port. Classic STP needs roughly 30 to 50 seconds for this. RSTP (IEEE 802.1w, Rapid Spanning Tree) usually switches in under a second and is the standard today. Vendors also offer their own variants, such as PVST+ with one tree per VLAN.
In practice
Deliberately built redundancy (two cables between two switches) is desirable and only becomes safely usable through STP. On ports for end devices one often enables PortFast or edge ports so they become active immediately, and BPDU Guard so that switches connected there cannot change the topology. Alternatives for avoiding loops are link aggregation (several cables as one logical link) and routing instead of switching.
See also: Layer 2 switch, VLAN, MAC addresses