How Spanning Tree Protocol (STP) Works

1️⃣ The Problem: Why Do We Need STP?

In a redundant Layer 2 network, multiple paths exist between switches to improve reliability. However, this can cause switching loops, leading to:

🚨 Broadcast Storms – Frames endlessly circulate, consuming bandwidth.
🚨 MAC Table Instability – Switches receive frames on multiple interfaces, confusing MAC address learning.
🚨 Multiple Frame Copies – The same frame reaches the destination multiple times.

Example: A Loop Without STP


2️⃣ STP: The Solution to Prevent Loops

Spanning Tree Protocol (STP) ensures a loop-free topology by:
✅ Electing a Root Bridge.
✅ Assigning Port Roles (Root, Designated, Blocking).
✅ Blocking redundant paths while keeping a backup route ready.


3️⃣ Step-by-Step: How STP Works

Step 1: Root Bridge Election

📝 Bridge ID = Priority (Default: 32768) + MAC Address
✅ Lower priority wins (MAC address used as a tiebreaker).


Step 2: Assigning Port Roles

Once the Root Bridge is chosen, all switches determine the best path to reach it.

🔹 Root Port (RP) – The best path to the Root Bridge (lowest cost).
🔹 Designated Port (DP) – The forwarding port on each segment.
🔹 Blocking Port (BP) – Redundant path, blocked to prevent loops.

STP Path Cost (Default IEEE 802.1D)

Link SpeedSTP Cost
10 Mbps100
100 Mbps19
1 Gbps4
10 Gbps2

✅ The lower the cost, the better the path!


Step 3: Ports Transition Through STP States

To prevent loops, STP gradually transitions ports through different states:

1️⃣ Blocking – Listens for BPDUs but does NOT forward traffic.
2️⃣ Listening – Processes BPDUs, but still no forwarding.
3️⃣ Learning – Starts learning MAC addresses.
4️⃣ Forwarding – Fully operational, forwarding traffic.

🚨 Total Convergence Time: 50 sec (STP), <6 sec (RSTP)!


Step 4: Handling Network Changes

If a link fails, STP automatically reconfigures by:

✅ This prevents downtime while maintaining a loop-free network.


4️⃣ STP Variants for Faster Convergence

STP TypeFeaturesConvergence Time
STP (802.1D)Standard, slow (50 sec)50 sec
RSTP (802.1w)Rapid recovery, new port roles<6 sec
MSTP (802.1s)Optimized for multiple VLANs<6 sec
PVST+ (Cisco)Per-VLAN STP instance50 sec (STP) / Fast (PVST+)

5️⃣ STP Troubleshooting Commands

🔍 Check STP Status

Switch# show spanning-tree

🔍 Check Root Bridge

Switch# show spanning-tree root

🔍 Check Active Ports

Switch# show spanning-tree interface GigabitEthernet0/1

Conclusion

Spanning Tree Protocol (STP) prevents loops in a redundant Layer 2 network by selecting a Root Bridge, assigning port roles, and blocking unnecessary paths.

renjithbs Avatar

Posted by

Leave a comment