Why STP Exists
Layer 2 networks with redundant paths form loops. Ethernet frames have no TTL field — unlike IP packets, a looping Ethernet frame never expires. A broadcast frame entering a loop multiplies exponentially as each switch floods it to all ports — within seconds, all bandwidth is consumed (broadcast storm). Switches' MAC tables also become unstable as MAC addresses appear to move between ports rapidly (MAC flapping).
STP (IEEE 802.1D) solves this by logically blocking redundant paths while keeping them available for failover. The blocked path activates automatically if the primary path fails, providing resilience without permanent loops.
STP Operation and Port States
STP elects a root bridge — the switch with the lowest Bridge ID (priority + MAC address). Default priority is 32768; lower priority = better chance of becoming root. All other switches calculate the lowest-cost path to the root bridge. Ports on the lowest-cost paths become designated or root ports; redundant ports enter blocking state.
STP port states (802.1D): Blocking (receives BPDUs only, discards data frames, not forwarding), Listening (processes BPDUs, 15 seconds), Learning (learns MAC addresses but not forwarding data, 15 seconds), Forwarding (normal operation), Disabled (administratively shut down). Convergence time: 30–50 seconds total.
RSTP (802.1w — Rapid STP): the modern replacement, converges in 1–2 seconds. Introduces new port roles: Alternate (blocked alternate to root) and Backup (redundant on same segment). RSTP is backward compatible with STP. Virtually all modern deployments use RSTP.
STP Port Roles and Features
Root port: the port on each non-root switch that has the best path to the root bridge (forwarding). Designated port: the port on each network segment that is closest to the root bridge (forwarding). Non-designated port: a redundant port that is blocked to prevent loops.
PortFast (Edge port in RSTP): immediately transitions access ports to forwarding state — eliminates 30-second delay for end-device connections. Only use on access ports connected to end devices. BPDU Guard: disables a PortFast port if it receives STP BPDUs — prevents rogue switches or user-connected hubs from affecting STP topology. Root Guard: prevents a port from becoming a root port — protects the STP root bridge placement.
MSTP (Multiple Spanning Tree Protocol, 802.1s): allows multiple VLANs to be mapped to different spanning tree instances — enables load balancing across redundant links by having different VLANs use different blocked ports.