Root bridge election, port roles, and loop prevention across 4 switches — click any link to fail/restore it
This simulator visualizes the Spanning Tree Protocol (STP) operating on a small 4-switch network with two redundant links. It shows how STP elects a root bridge by lowest Bridge ID, determines root ports and designated ports along the lowest-cost path to that root, and blocks the remaining redundant links to guarantee a loop-free logical topology — then lets you fail any link to watch STP/RSTP reconverge in real time.
Physical redundancy — multiple cabled paths between switches — is desirable for reliability, but Ethernet frames have no TTL field and switches flood unknown-unicast and broadcast frames out every port. Without a loop-prevention protocol, a redundant physical loop causes those frames to circulate endlessly, duplicating exponentially and consuming all available bandwidth within seconds — a broadcast storm that can take down an entire Layer 2 segment. Spanning Tree Protocol (IEEE 802.1D) solves this by computing a loop-free logical tree over the physical topology and administratively blocking any link not part of that tree.
First, every switch exchanges BPDUs (Bridge Protocol Data Units) advertising its Bridge ID (a priority value plus its MAC address); the switch with the lowest Bridge ID is elected root bridge — in this simulation, SW-1 with priority 4096. Second, every non-root switch determines its Root Port: the single port offering the lowest-cost path back to the root. Third, for every network segment, the switch offering the lowest-cost path to the root on that segment becomes the Designated Port for that segment; any other port on that segment is blocked to prevent a loop.
Legacy 802.1D STP takes up to 30–50 seconds to converge after a topology change, cycling every affected port through Listening (15s) and Learning (15s) states before Forwarding — a real availability problem for modern networks. Rapid Spanning Tree Protocol (RSTP, IEEE 802.1w) redesigns the state machine and introduces the Alternate Port role: a pre-computed backup for the root port that can transition to forwarding in under a second when the primary path fails, which is what this simulator's link-failure toggle demonstrates.
The Bridge ID is actually priority (4 bits, in multiples of 4096) concatenated with the switch's MAC address (or system ID extension for per-VLAN Bridge IDs). If priorities tie, the switch with the numerically lowest MAC address wins the root election — MAC address only ever acts as a tie-breaker, never the primary criterion.
Blocking only stops the port from forwarding data frames — it continues to listen for BPDUs. This lets STP instantly detect if the primary path fails (because expected BPDUs stop arriving on a segment) and transition the blocked port back to forwarding, providing automatic failover without any manual recabling.
BPDU Guard immediately disables (err-disable) an access port the instant it receives a BPDU, since end-user devices should never be running STP. It protects against a user accidentally daisy-chaining an unmanaged switch that could otherwise participate in — and potentially disrupt — the spanning tree topology.
Per-VLAN Spanning Tree (PVST+, a Cisco enhancement) runs a separate spanning tree instance per VLAN, allowing different VLANs to use different links as their forwarding path for load balancing. Multiple Spanning Tree Protocol (MSTP, 802.1s) achieves similar load-balancing benefits by mapping multiple VLANs to a smaller number of spanning tree instances, reducing the BPDU/CPU overhead of running one instance per VLAN.
Try our Enterprise IT Networks Studio
More calculators, simulators, and guides for this discipline.