- ${item}

Spanning Tree Protocol (STP)
The Spanning Tree Protocol (STP) is a network protocol designed to prevent loops in Ethernet networks. Loops can cause broadcast storms, MAC address table instability, and network downtime. STP ensures a loop-free topology by dynamically disabling redundant links while maintaining backup paths for fault tolerance.
Why STP is Needed
In a network with multiple switches and redundant paths, loops can occur when there are multiple active paths between switches. This can lead to:
- Broadcast Storms: Endless circulation of broadcast frames.
- MAC Address Table Instability: Constant changes in the MAC address table due to duplicate frames.
- Network Congestion: Excessive traffic consuming bandwidth and degrading performance.
STP solves these problems by creating a logical tree structure that spans all switches in the network, blocking redundant paths while keeping them available for backup.
How STP Works
STP uses an algorithm called the Spanning Tree Algorithm (STA) to create a loop-free topology. Here’s how it works:
- Elect a Root Bridge:
- The switch with the lowest Bridge ID (BID) is elected as the Root Bridge.
- The BID consists of a priority value (default: 32768) and the switch’s MAC address.
- Determine Root Ports:
- Each non-root switch selects a Root Port, which is the port with the lowest path cost to the Root Bridge.
- Designate Ports:
- On each network segment, the port with the lowest path cost to the Root Bridge is designated as the Designated Port.
- Block Redundant Paths:
- All other ports are placed in a blocking state to prevent loops.
STP Protocol Details
Key Components of STP
Component |
Description |
Bridge ID (BID) |
A unique identifier for each switch, consisting of a priority value and MAC address. |
Path Cost |
A value assigned to each link based on its bandwidth. Lower cost paths are preferred. |
Root Bridge |
The central reference point for the STP topology. All paths are calculated relative to it. |
Root Port |
The port on a non-root switch with the lowest path cost to the Root Bridge. |
Designated Port |
The port on a network segment with the lowest path cost to the Root Bridge. |
Blocking State |
A port state where traffic is blocked to prevent loops. |
STP Port States
State |
Description |
Blocking |
The port does not forward frames but listens to BPDUs (Bridge Protocol Data Units). |
Listening |
The port listens to BPDUs and prepares to forward frames. |
Learning |
The port learns MAC addresses but does not forward frames. |
Forwarding |
The port forwards frames and participates in the active topology. |
Disabled |
The port is administratively shut down. |
STP Operation Steps
- Root Bridge Election:
- All switches exchange BPDUs to determine the Root Bridge.
- The switch with the lowest BID becomes the Root Bridge.
- Root Port Selection:
- Each non-root switch calculates the path cost to the Root Bridge and selects the port with the lowest cost as the Root Port.
- Designated Port Selection:
- On each network segment, the switch with the lowest path cost to the Root Bridge designates its port as the Designated Port.
- Blocking Redundant Paths:
- All other ports are placed in the blocking state to prevent loops.
STP Benefits
- Loop Prevention:
- Ensures a loop-free topology by blocking redundant paths.
- Fault Tolerance:
- Automatically activates backup paths if the primary path fails.
- Network Stability:
- Prevents broadcast storms and MAC address table instability.
- Scalability:
- Supports large networks with multiple switches and redundant links.
STP Variants
- Classic STP (IEEE 802.1D):
- The original STP protocol with slow convergence (30–50 seconds).
- Rapid STP (RSTP, IEEE 802.1w):
- Provides faster convergence (1–2 seconds) by introducing new port states and roles.
- Multiple STP (MSTP, IEEE 802.1s):
- Allows multiple VLANs to be mapped to a single spanning tree instance, reducing resource usage.
STP Configuration Example
Enabling STP on a Cisco Switch
Switch(config)# spanning-tree mode rstp
Switch(config)# spanning-tree vlan 1 priority 4096
Verifying STP Status
Switch# show spanning-tree
STP Frame Format (BPDU)
STP uses Bridge Protocol Data Units (BPDUs) to exchange information between switches. The BPDU frame contains the following fields:
Field |
Description |
Protocol ID |
Always set to 0 for STP. |
Version |
STP version (0 for 802.1D, 2 for RSTP, 3 for MSTP). |
BPDU Type |
Indicates the type of BPDU (Configuration or Topology Change Notification). |
Flags |
Indicates port roles and states. |
Root ID |
The BID of the Root Bridge. |
Root Path Cost |
The total path cost to the Root Bridge. |
Bridge ID |
The BID of the switch sending the BPDU. |
Port ID |
The ID of the port sending the BPDU. |
Message Age |
The time since the BPDU was generated by the Root Bridge. |
Max Age |
The maximum time a BPDU is considered valid. |
Hello Time |
The time interval between BPDUs. |
Forward Delay |
The time spent in the Listening and Learning states. |
STP Convergence
STP convergence is the process of transitioning from one loop-free topology to another when a network change occurs (e.g., a link failure). The steps include:
- Detection: A switch detects a link failure.
- Recalculation: The switch recalculates the best path to the Root Bridge.
- Transition: Ports transition through the Listening and Learning states before reaching the Forwarding state.