Networking - Spanning Tree Protocol (STP)

Spanning Tree Protocol (STP) is a Layer 2 (Data Link Layer) network protocol designed to prevent loops in Ethernet networks with redundant links. It was developed by Dr. Radia Perlman in the 1980s and standardized by the IEEE as 802.1D.

In simple terms:

STP ensures that in a network with multiple redundant paths, there is only one active logical path between switches at any time, preventing broadcast storms, frame duplication, and MAC table instability.


1. Need for STP

In Ethernet networks, redundant links are often used to provide fault tolerance and high availability.

However, redundancy can create switching loops, which lead to:

  • Broadcast storms (frames circulating endlessly).

  • Multiple frame copies reaching destinations.

  • MAC address table instability (constantly changing entries).

STP eliminates these issues by logically blocking some redundant links, ensuring only one active path exists between any two devices.


2. Definition

Spanning Tree Protocol (STP) is a network protocol that builds a loop-free logical topology for Ethernet networks. It uses a tree-like structure (spanning tree) that spans all switches in the network, ensuring a single active path while keeping backups ready in case of link failures.


3. Objective of STP

  • Prevent Layer 2 loops

  • Maintain network redundancy for fault tolerance

  • Automatically reconfigure when topology changes

  • Provide stable network connectivity


4. How STP Works

STP works by:

  1. Electing a Root Bridge (the central switch).

  2. Selecting the best path from each switch to the Root Bridge.

  3. Blocking redundant paths to prevent loops.

  4. Recalculating the tree dynamically if a failure occurs.

Step-by-Step Process

Step 1: Elect the Root Bridge

  • All switches exchange Bridge Protocol Data Units (BPDUs) to decide which switch will be the Root Bridge.

  • The switch with the lowest Bridge ID (BID) becomes the Root Bridge.

Bridge ID (BID) = Bridge Priority (default 32768) + MAC Address
→ Lower BID = Higher priority.

Step 2: Determine Root Ports

  • Every non-root switch determines its Root Port — the port with the lowest cost path to the Root Bridge.

Step 3: Determine Designated Ports

  • On each network segment, one switch port is chosen as the Designated Port — the port providing the lowest path cost to the Root Bridge.

Step 4: Block Redundant Ports

  • Any port that is neither a Root Port nor a Designated Port becomes a Blocked Port.

  • Blocked ports do not forward traffic but can become active if the topology changes.


5. STP Port States

STP ports transition through several states before becoming active or blocked.

Port State Function Can Forward Traffic?
Blocking Listens for BPDUs only; does not forward frames. No
Listening Participates in BPDU exchange to prevent loops. No
Learning Learns MAC addresses but does not forward data. No
Forwarding Forwards user data and learns MAC addresses. Yes
Disabled Administratively shut down (not in STP topology). No

6. STP Timers

Timer Default Value Purpose
Hello Time 2 seconds Interval between BPDU transmissions by the Root Bridge.
Forward Delay 15 seconds Time spent in Listening and Learning states.
Max Age 20 seconds Time before outdated BPDU information is discarded.

Total convergence time ≈ 50 seconds (Max Age + 2 × Forward Delay).


7. Bridge Protocol Data Units (BPDUs)

BPDUs are special frames that switches exchange to share information about the network topology.

Types of BPDUs:

  1. Configuration BPDU: Used for STP calculations and Root Bridge election.

  2. Topology Change Notification (TCN) BPDU: Sent when a topology change occurs (e.g., a link goes down).

BPDU Fields Include:

  • Root Bridge ID

  • Sender Bridge ID

  • Path Cost to Root

  • Timer values (Hello, Max Age, Forward Delay)


8. STP Path Cost Calculation

Each switch port has a path cost based on its link speed. The total cost to reach the Root Bridge is the sum of the individual link costs.

Link Speed Path Cost (IEEE 802.1D)
10 Mbps 100
100 Mbps 19
1 Gbps 4
10 Gbps 2

Lower path cost = Preferred path


9. Example of STP Operation

Consider three switches connected in a triangle:

     [Switch A]
       /     \
      /       \
 [Switch B]---[Switch C]
  • All three have redundant links (which can form a loop).

  • STP elects one as the Root Bridge (say, Switch A).

  • Each non-root switch (B and C) determines its Root Port.

  • One redundant link (e.g., between B and C) is blocked to break the loop.

  • If the active link fails, the blocked port becomes active, maintaining connectivity.


10. STP Port Roles

Port Role Function
Root Port (RP) Port with the best path cost to the Root Bridge.
Designated Port (DP) Port with the best path cost on a LAN segment.
Blocked Port (BP) Redundant port that prevents loops.
Alternate/Backup Port Standby ports that can become active during failures.

11. STP Variants

STP Type IEEE Standard Description
STP (Classic) 802.1D Original Spanning Tree Protocol.
RSTP (Rapid STP) 802.1w Faster convergence (3–5 seconds).
MSTP (Multiple STP) 802.1s Allows multiple VLANs to share the same spanning tree instance.
PVST+ (Per-VLAN STP) Cisco Proprietary Runs one STP instance per VLAN.
Rapid PVST+ Cisco Proprietary Combines RSTP with per-VLAN topology.

12. Rapid Spanning Tree Protocol (RSTP – 802.1w)

RSTP is an evolution of STP offering faster convergence and improved port roles.

  • Convergence time reduced to 3–5 seconds.

  • Introduces port roles: Alternate, Backup, and Edge ports.

  • Uses handshake mechanisms instead of timers for faster transitions.

  • Backward compatible with STP.


13. Multiple Spanning Tree Protocol (MSTP – 802.1s)

MSTP allows grouping multiple VLANs into a single spanning tree instance to reduce CPU and memory usage.

  • Improves performance in VLAN-rich environments.

  • Reduces number of STP instances.

  • Backward compatible with RSTP and STP.


14. Advantages of STP

  1. Prevents Layer 2 Loops:
    Ensures a loop-free network even with redundant paths.

  2. Provides Redundancy:
    Keeps backup links ready in case of failure.

  3. Automatic Reconfiguration:
    Adapts dynamically to topology changes.

  4. Vendor Interoperability:
    IEEE standard ensures multi-vendor support.

  5. Supports Network Scalability:
    Enables large Layer 2 topologies with redundancy.


15. Disadvantages of STP

  1. Slow Convergence (in classic STP):
    Takes up to 50 seconds to reconfigure after a failure.

  2. Inefficient Bandwidth Usage:
    Redundant links are blocked and unused until needed.

  3. Complex Troubleshooting:
    Misconfigurations or multiple spanning trees can cause instability.

  4. Scalability Issues:
    Classic STP can be slow and inefficient in very large networks.


16. STP vs RSTP vs MSTP

Feature STP (802.1D) RSTP (802.1w) MSTP (802.1s)
Convergence Time 30–50 sec 3–5 sec 3–5 sec
BPDU Transmission Only by Root Bridge All switches All switches
VLAN Support Single instance Single instance Multiple instances
Compatibility Legacy Backward compatible Backward compatible
Efficiency Low Higher Highest

17. Real-World Applications

  • Enterprise LANs: To prevent loops in networks with multiple switches.

  • Campus Networks: For redundancy and failover between switch blocks.

  • Data Centers: Combined with VLANs for secure, resilient topologies.

  • Service Provider Networks: Ensuring redundant Ethernet links remain stable.


18. Example Scenario

Imagine a company network with three core switches and multiple redundant uplinks.
Without STP, a broadcast packet could loop endlessly, consuming bandwidth and crashing the network.

With STP:

  • One switch becomes the Root Bridge.

  • Redundant ports are blocked to form a loop-free logical topology.

  • If a link fails, the blocked port automatically unblocks, restoring connectivity — all without manual intervention.


19. Conclusion

Spanning Tree Protocol (STP) is an essential mechanism for maintaining loop-free, reliable, and redundant Ethernet networks. Although it can be slow in its classic form, newer versions like RSTP and MSTP offer faster convergence and better scalability.

In essence, STP ensures that redundant links enhance reliability without causing network loops, making it a cornerstone of modern Layer 2 network design.