Quick Summary
- STP prevents Layer 2 loops by logically blocking redundant switch links
- It elects a root bridge and calculates loop-free paths from every switch to the root
- If an active link fails, STP automatically unblocks a backup path
The Loop Problem
Network redundancy is critical -- if a single link fails, you want a backup path so traffic can continue flowing. But at Layer 2, redundant paths create a deadly problem: switching loops. When a switch receives a broadcast frame (like an ARP request), it floods it out all ports except the source. If those ports connect to other switches that are also connected to each other, the broadcast gets copied and forwarded endlessly, creating an infinite loop.
Unlike IP packets, Ethernet frames have no TTL (Time To Live) field. An IP packet will eventually be discarded when its TTL reaches zero, but an Ethernet frame can circulate forever. Within seconds, a single broadcast frame can multiply into millions of copies, consuming 100% of every link's bandwidth. This is called a broadcast storm, and it will bring down an entire network segment. Switches' MAC address tables become corrupted as they see the same source MAC arriving on different ports, CPU utilization spikes to 100%, and legitimate traffic cannot get through.
Spanning Tree Protocol (STP), defined in IEEE 802.1D, solves this by running an algorithm that identifies redundant paths and logically disables (blocks) enough of them to eliminate all loops, while keeping the network fully connected through a single loop-free tree topology.
Interactive: STP On vs. Off
Toggle STP on and off to see the difference. With STP off, watch packets multiply in a broadcast storm. With STP on, one link is blocked and traffic flows cleanly.
Three-Switch Triangle
How STP Works
Elect a Root Bridge
When STP starts, all switches begin sending Bridge Protocol Data Units (BPDUs) to each other. Each BPDU contains the switch's Bridge ID, which is a combination of a priority value (default 32768) and the switch's MAC address. The switch with the lowest Bridge ID becomes the root bridge -- the center of the spanning tree. All other switches calculate their shortest path to the root. Administrators can influence the election by lowering the priority on their preferred root switch.
Determine Port Roles
After the root bridge is elected, every non-root switch designates one port as its root port -- the port with the lowest cost path to the root bridge. On each network segment, one port is chosen as the designated port (the port that forwards traffic for that segment). All other ports that would create loops are placed in blocking state. STP uses a path cost metric based on link speed: 10 Gbps = cost 2, 1 Gbps = cost 4, 100 Mbps = cost 19.
Block Redundant Links
Blocked ports still receive BPDUs but do not forward any user traffic. This eliminates loops while keeping the backup path ready. The resulting topology is a tree rooted at the root bridge, with exactly one active path between any two switches. Traffic can flow freely without risk of broadcast storms. If a link fails, STP detects the loss of BPDUs and transitions the blocked port to forwarding state, restoring connectivity.
Convergence
Classic STP (802.1D) takes 30-50 seconds to converge after a topology change, during which traffic is disrupted. This is because ports transition through Listening (15 seconds) and Learning (15 seconds) states before reaching Forwarding. Rapid Spanning Tree Protocol (RSTP, 802.1w) reduces convergence to 1-3 seconds by using a more sophisticated negotiation process. Most modern networks use RSTP or MSTP (802.1s), which supports multiple spanning trees for different VLANs.
STP Port States
In classic STP, a port transitions through five possible states:
Blocking
The port does not forward any frames. It only listens to BPDUs to detect topology changes. This is the default state for redundant ports that would create loops.
Listening
The port processes BPDUs and participates in the root bridge election. It does not forward frames or learn MAC addresses. This state lasts 15 seconds (forward delay timer).
Learning
The port starts learning MAC addresses from incoming frames to populate the MAC table. It still does not forward user traffic. This state also lasts 15 seconds.
Forwarding
The port is fully operational -- it forwards frames, learns MACs, and processes BPDUs. Only root ports and designated ports reach this state in a stable topology.
Why Broadcast Storms Are Catastrophic
A broadcast storm is not just an annoyance -- it is a complete network outage. When a switching loop exists without STP, a single broadcast frame (such as an ARP request) enters the loop and is copied by each switch to all ports. Each copy re-enters the loop and is copied again. Within milliseconds, the number of frames grows exponentially. A single 64-byte broadcast can generate millions of copies per second, consuming 100% of every link's bandwidth.
The switches themselves become overwhelmed. Their CPUs are consumed processing the flood of frames. MAC address tables thrash as the same source MAC appears on different ports from the looping copies. Management interfaces become unreachable because the management traffic cannot compete with the storm. Even devices not involved in the loop suffer because the broadcast domain is saturated. The only fix is physically disconnecting a cable to break the loop -- and then enabling STP to prevent it from happening again.
Common STP Problems
Unintended Root Bridge
If you do not explicitly set bridge priorities, the switch with the lowest MAC address becomes root -- which might be an old, slow switch. Always configure your core switches with low priority values to control root placement.
STP Disabled on a Port
Some administrators disable STP on access ports for faster convergence (PortFast). This is safe for end-user devices but dangerous if someone accidentally connects a switch to that port, creating an instant loop.
Slow Convergence
Classic STP takes 30-50 seconds to reconverge. During this time, traffic is black-holed. Upgrade to RSTP for sub-second failover, and ensure all switches in the domain support it.
Frequently asked questions about Spanning Tree Protocol
What does STP stand for?
STP stands for Spanning Tree Protocol. It is a Layer 2 protocol defined in IEEE 802.1D that prevents switching loops in Ethernet networks by electing a root bridge and logically blocking enough links to leave one loop-free tree.
Why do Ethernet networks need STP?
Ethernet frames have no TTL field, so any Layer 2 loop causes broadcast frames to circulate forever and multiply, saturating links and corrupting MAC tables. STP removes redundant paths logically so the physical topology can stay redundant for failover, without creating a broadcast storm.
What is the difference between STP, RSTP, and MSTP?
Classic STP (802.1D) converges in 30–50 seconds. RSTP (802.1w) uses proposal/agreement handshakes and converges in under a second. MSTP (802.1s) extends RSTP to map multiple VLANs to a small number of spanning-tree instances, giving better scale than per-VLAN spanning tree.
How is the STP root bridge elected?
Every switch advertises a Bridge ID, which is its priority value combined with its MAC address. The switch with the lowest Bridge ID becomes the root. Operators typically lower the priority on the desired root in the core so the election is deterministic rather than driven by random MAC addresses.
Is STP still relevant in modern networks?
Yes — any L2 network with redundant switch links still needs a spanning-tree protocol, usually RSTP or MSTP. Data centers increasingly replace it with L3 routed designs or fabric protocols like TRILL and SPB, but at the access layer STP remains the standard guard against loops.
Try the switch loop lab
You just learned how STP keeps redundant L2 topologies loop-free. Now work with a real triangle of switches, which the platform runs loop-free as if spanning tree had blocked one link: trace across it, cut links to find which path is enough, and work out which port STP would block. The storm itself stays in the toggle above.
Launch the switch loop lab →