STP_How_They_Select
π§΅ Spanning Tree Protocol (STP) β Complete Technical Notes
A Layer-2 Ethernet network with redundant physical links prevents outages but introduces a major risk: switching loops. When loops occur, BUM traffic (Broadcast, Unknown unicast, Multicast) can circle endlessly, causing broadcast storms, MAC table instability, and network collapse.
Spanning Tree Protocol (STP) prevents loops by building a loop-free logical topology. It keeps some ports active and intentionally blocks others to maintain a single best path through the network.
π¦ 1. STP Core Concept
- Redundant links = good for redundancy
- But redundant paths = potential L2 loops
- STP uses BPDUs (Bridge Protocol Data Units) to identify redundant paths
- STP then:
- Selects a Root Bridge
- Selects Root Ports (one per non-root switch)
- Selects Designated Ports (one per network segment)
- Places all other ports in Blocking state
π¦ 2. STP Decision-Making Algorithm (3 Major Steps)
πΉ Step 1: Root Bridge Election
STP first chooses one switch to act as the Root Bridge (the reference point for the entire STP topology).
How the Root Bridge is chosen
Each switch advertises its Bridge ID (BID) in BPDUs.
Bridge ID (64 bits) = Priority (16 bits) + MAC Address (48 bits)
- Lower BID = higher priority in election
- Default priority = 32768
- If priorities tie β lower MAC address wins
Important Behavior
- Every switch initially believes it is the root
- Election stabilizes once BPDUs converge
PVST+ Note
Cisco networks typically use PVST+ / Rapid PVST+
β‘ One STP instance per VLAN
β‘ Allows different VLANs to have different Root Bridges
β‘ Enables load balancing
πΉ Step 2: Root Port (RP) Selection
Every non-root switch chooses exactly one Root Port (RP).
The Root Port is the port with the lowest-cost path back to the Root Bridge.
Root Port Selection Criteria (strict order)
- Lowest total Root Path Cost
- Link speeds β Cost values (examples):
- 10 Mbps = 100
- 100 Mbps = 19
- 1 Gbps = 4
- 10 Gbps = 2
- Link speeds β Cost values (examples):
- Lowest upstream Bridge ID
- Lowest upstream Port ID
β‘ Only ONE RP per switch
β‘ RP is always in Forwarding state
πΉ Step 3: Designated Port Selection & Blocking
Designated Ports (DP)
Each network segment (collision domain / link) must have exactly one Designated Port.
Rules:
- All ports on the Root Bridge are automatically Designated Ports
- A port facing each switchβs Root Port becomes DP on the opposite side
- On shared segments, the DP is chosen using:
- Lowest Root Path Cost
- Lowest Bridge ID
Non-Designated Ports (Blocking)
Ports that are neither RP nor DP must block.
Blocking means:
- β No frame forwarding
- β No MAC learning
- β Yes β BPDU reception (so topology changes can be detected)
Blocking ensures that redundant links exist physically but are not active logicallyβpreventing loops.
π¦ 3. STP Port States (Original 802.1D)
A port transitions through multiple states before becoming active. This prevents temporary loops during recalculation.
| State | Role | Forwards Frames? | Learns MACs? | Time |
|---|---|---|---|---|
| Blocking | Non-Designated | β No | β No | Stable |
| Listening | Transitional | β No | β No | 15 sec |
| Learning | Transitional | β No | β Yes | 15 sec |
| Forwarding | Root or Designated | β Yes | β Yes | Stable |
β‘ A newly active port takes 30 seconds (15 + 15) before forwarding frames.
π¦ 4. Faster Convergence Mechanisms
β‘ Rapid Spanning Tree Protocol (RSTP / 802.1w)
- Replaces slow timers with handshake-based synchronization
- Converges in 1β3 seconds
- Introduces roles like:
- Alternate Port
- Backup Port
Cisco variant: Rapid PVST+ (per-VLAN rapid STP)
β‘ PortFast
Used on end-host ports.
- Skips Listening & Learning
- Immediately transitions to Forwarding
- Should NOT be used on switch-to-switch links
- Must be combined with BPDU Guard
- If a PortFast port receives a BPDU β port is disabled (err-disabled)
- Protects from accidental loops or rogue switches
π¦ 5. Summary of STP Logic Flow
- Elect Root Bridge
- Choose one Root Port per non-root switch
- Choose one Designated Port per segment
- Everything else β Blocking
- STP builds a loop-free, redundancy-aware, self-healing Layer-2 topology
If a link fails:
- STP recalculates
- Blocked ports may transition to forwarding
- Connectivity is restored without creating loops
π© Use Cases in Interviews
- Explain Layer 2 loop prevention
- Describe bridge ID, root election
- Compare STP vs RSTP
- Discuss PVST+ advantages
- Explain troubles with misconfigured PortFast
- Calculate STP path cost in topology diagrams
π© Real-World Advantages
- Prevents broadcast storms
- Enables physical redundancy safely
- Supports VLAN-specific design (PVST+)
- Provides automatic failover
- Essential for enterprise switching networks
π§Ύ End of Notes β Full STP Coverage
This document is rephrased, original, and safe for public website use.