What is STP (Spanning Tree Protocol)?
Learn what Spanning Tree Protocol is, how root bridge election and BPDUs prevent Layer 2 loops, and Rapid STP — interview Q&A.
Expected Interview Answer
Spanning Tree Protocol is a Layer 2 protocol that prevents bridging loops in a switched network with redundant physical links by logically blocking enough ports so that exactly one active path exists between any two switches, while keeping the blocked links ready as backups.
Redundant links between switches are good for resilience but disastrous without control, because Ethernet frames have no TTL and a broadcast can circulate forever, quickly saturating links in a broadcast storm. STP solves this by having switches elect a single Root Bridge (the one with the lowest bridge ID) and then, working outward from it, calculate the lowest-cost path from every other switch to the root. Each switch designates one Root Port (its best path to the root) and Designated Ports on each segment (the best path off that segment toward the root), and any remaining redundant ports are put into a Blocking state so they carry no data traffic but continue to listen for Bridge Protocol Data Units (BPDUs). If an active link fails, a blocked port can transition back through listening and learning states to forwarding, restoring connectivity, though classic STP’s convergence can take up to 50 seconds, which is why faster variants like Rapid STP (802.1w) are used in modern networks.
- Eliminates Layer 2 broadcast storms caused by physical loops
- Keeps redundant links as automatic backups instead of removing them
- Elects a single root bridge to build a consistent loop-free tree
- Rapid STP variants converge in seconds instead of up to 50 seconds
AI Mentor Explanation
STP is like a ground with multiple gates between two stands that, if all left open at once, would let a chanting echo bounce back and forth between the stands endlessly, drowning out the game. So stewards agree on one 'main' gate as the reference point and keep only the minimum necessary gates open for crowd flow, closing the rest but keeping them staffed and ready to reopen if the main gate jams. If the main path floods, a closed gate reopens to restore flow rather than leaving fans stuck. This mirrors how STP blocks redundant links to prevent loops while keeping them as standby paths.
Step-by-Step Explanation
Step 1
Root bridge election
Switches exchange BPDUs and elect the switch with the lowest bridge ID as the Root Bridge.
Step 2
Path cost calculation
Every other switch calculates its lowest-cost path back to the root bridge.
Step 3
Port roles assigned
Each switch designates a Root Port and Designated Ports; redundant ports become Blocking.
Step 4
Failover
If an active link fails, a Blocking port transitions through listening/learning to Forwarding to restore connectivity.
What Interviewer Expects
- Explains why loops are catastrophic on Layer 2 (no TTL, broadcast storms)
- Describes root bridge election and port roles (root, designated, blocking)
- Knows BPDUs are the control messages used for the calculation
- Aware of Rapid STP (802.1w) as the faster-converging successor
Common Mistakes
- Thinking STP removes redundant links instead of blocking them logically
- Confusing STP with routing protocols like OSPF
- Not knowing blocked ports still listen for BPDUs
- Forgetting classic STP’s convergence can take up to 50 seconds
Best Answer (HR Friendly)
“Spanning Tree Protocol stops network switches with redundant cabling from creating a traffic loop that would flood the network with endlessly circulating broadcasts. It works by picking one switch as a reference point and turning off just enough backup links to leave a single clean path, while keeping those backups ready to switch back on automatically if the main path ever fails.”
Code Example
# Create a bridge and enable STP
sudo ip link add name br0 type bridge
sudo ip link set br0 type bridge stp_state 1
# Show STP port states and root bridge info
brctl showstp br0
# Example output shows port state: forwarding, blocking, listening, or learningFollow-up Questions
- What is a BPDU and what information does it carry?
- How does Rapid STP (802.1w) improve on classic STP convergence time?
- What are the differences between root, designated, and blocking ports?
- What is BPDU Guard and why is it used on access ports?
MCQ Practice
1. What is the primary purpose of Spanning Tree Protocol?
STP blocks redundant paths to guarantee a single active path and prevent Layer 2 loops.
2. What message type do switches exchange to run STP?
BPDUs carry the information switches use to elect the root bridge and calculate port roles.
3. What state does a blocked STP port remain in?
A blocking port stays ready by listening for BPDUs while carrying no user data traffic.
Flash Cards
What is STP? — A Layer 2 protocol that blocks redundant links to prevent bridging loops.
What is a root bridge? — The switch with the lowest bridge ID, elected as the reference point for the tree.
What message drives STP? — BPDUs (Bridge Protocol Data Units) exchanged between switches.
Why use Rapid STP? — It converges in seconds versus classic STP’s up to 50-second convergence.