STP – Spanning Tree Protocol Explained
โก Smart Summary
Spanning Tree Protocol (STP) is a Layer 2 link-management standard, IEEE 802.1D, that prevents switching loops in networks with redundant links by electing a root bridge and placing backup ports into a blocking state.

What is STP?
Spanning Tree Protocol (STP) is a link management protocol designed to support redundant links while preventing switching loops in the network. It is a Layer 2 protocol that runs on bridges and switches and must be enabled on the switch interfaces. IEEE standardized it as IEEE 802.1D.
Why do we need STP?
Redundant links improve fault tolerance, but without a loop-prevention mechanism they can also create dangerous switching loops. Here are the situations where Spanning Tree Protocol becomes important:
- The reliability (fault tolerance) of the network increases significantly through the introduction of redundancy.
- Switches flood traffic out of all ports when it must reach a destination that is not yet known.
- Broadcast and multicast traffic is forwarded out of every port except the one on which it arrived.
- STP creates a loop-free logical topology from a physical topology that contains loops.
How STP works? Example
Spanning tree uses an algorithm to search for the redundant links in the LAN and select the best paths. It places every link into either a forwarding or a blocking state.
After this process, links without a redundant alternative remain in the forwarding state. Redundant links that were not selected as the best path are set to blocking. Spanning Tree never uses multiple links to the same destination, so it provides no load-sharing.
Types of STP
Here are the different types of Spanning Tree Protocols:
| Standard | Description | Abbreviation |
|---|---|---|
| IEEE 802.1D | Loop prevention; automatic reconfiguration of the tree after any change; slow convergence (up to 50 seconds) | STP |
| IEEE 802.1w โ Rapid Spanning Tree Protocol | Improved STP with faster convergence; backward compatible with STP | RSTP |
| IEEE 802.1Q โ Virtual LAN | Defines one common spanning tree for all VLANs | CST |
| Cisco proprietary โ Per-VLAN Spanning Tree | One STP instance per VLAN; PVST+ is an improved variant of PVST | PVST+ |
| Cisco proprietary โ Per-VLAN Rapid Spanning Tree | Rapid, per-VLAN convergence | PVRST+ / R-PVST+ |
| IEEE 802.1s โ Multiple Spanning Tree Protocol | Multiple VLANs mapped to a single STP instance | MSTP |
Criteria for Spanning Tree
Three criteria decide which interfaces are placed in the forwarding state:
- All interfaces on the root bridge are put in a forwarding state.
- For bridges that are not the root bridge, the port closest to the root bridge (lowest path cost) is put in a forwarding state.
- The bridge with the lowest path cost to the root bridge on a segment is known as the designated bridge.
Stages of STP Protocol
A Spanning Tree port transitions through several states before it forwards traffic, as the diagram below shows:
Blocking State
A blocking port is a non-designated port that never participates in frame forwarding. Its timer is 20 seconds (the max-age value). An interface always enters the blocking state when you enable STP.
Listening State
The listening state is the first transitional state a port enters after blocking. Here the port determines whether it should participate in frame forwarding. The listening state performs the following functions:
- Discards frames received on the port
- Does not learn MAC addresses
- Receives BPDUs
Learning State
The learning state prepares the port to participate in frame forwarding. A port enters the learning state from the listening state and performs the following functions:
- Discards frames received on the port
- Receives BPDUs
- Learns MAC addresses
Forwarding State
A port in the forwarding state forwards frames. It enters the forwarding state from the learning state and performs the following functions:
- Receives and forwards frames received on the port
- Learns MAC addresses
- Receives BPDUs
Disabled State
A disabled port does not participate in the Spanning Tree because it is administratively shut down; its timing is unlimited. A disabled interface performs the following functions:
- Discards frames received on the port
- Does not learn MAC addresses
- Does not receive BPDUs
Important terms used in Spanning Tree Protocol
Here are some important terms used in STP:
Bridge
A bridge is an important component of STP that connects two or more LAN segments.
Root Bridge (RB)
The root bridge offers an interconnection point for all segments, and every bridge in a LAN has a path to it. STP selects the root bridge automatically, though a network administrator can change it when required.
Non-Root Bridge (NRB)
A non-root bridge is any bridge that is not the root bridge.
Root Port (RP)
The root port is the port that leads toward the root bridge.
Designated Port (DP)
Every LAN segment has one designated port. Each bridge receives frames on its designated port and forwards them through its root port toward the root bridge.
Port ID
The port ID helps decide the root port. It consists of a configurable 1-byte priority value and a unique port number for each bridge.
Path Cost (PC)
Path cost helps decide the best topology in terms of forwarding speed; a lower-bandwidth link carries a higher cost. STP uses path cost to choose the shortest route to the root bridge.
Non-Designated Port
A non-designated port is a switch port that is blocked, also called a blocked or alternate port. It cannot forward frames to the next switch and does not populate the MAC address table.
RSTP
Rapid Spanning Tree Protocol (RSTP) is a network protocol that ensures a loop-free topology for Ethernet networks and converges much faster than the original STP.
Bridge Protocol Data Units (BPDU)
Spanning Tree Protocol requires network devices to exchange messages so they can form a loop-free logical topology. These messages are called BPDUs (Bridge Protocol Data Units). Each network device sends BPDUs to share topology information.
BPDUs help switches do the following:
- Select a single switch to act as the root of the spanning tree.
- Calculate the shortest path from each switch to the root switch, designating one switch as closest to the root for every LAN segment.
- Select one port on each switch as its root port (if it is not the root switch).
- Identify the ports that are part of the spanning tree as designated ports.
- Block the non-designated ports.
Configuration BPDU
A configuration BPDU carries the bridge ID of the root device, the bridge ID of the transmitting bridge, and an identifier of the transmitting port.
Topology Change Notification (TCN) BPDU
A TCN BPDU is sent by a switch toward the root bridge when it detects a change in the network topology, such as a link going up or down. The root bridge then instructs every switch to shorten its MAC address-table aging time so that stale entries are cleared quickly.
Differences between STP and RSTP
The table below highlights the key differences between STP and RSTP:
| STP | RSTP |
|---|---|
| In STP, a bridge only sends out a BPDU when it receives one on its root port from the root bridge. | RSTP enables each switch to send out a BPDU at every hello interval. |
| STP defines two port roles: root port and designated port. | RSTP adds two more roles: the alternate port and the backup port. |
STP Port States Reference Table
The following table summarizes each STP port state, whether it processes BPDUs, and whether it learns MAC addresses:
| State | Description | Process BPDUs | Learn MAC |
|---|---|---|---|
| Init | Initialization of a port. | No | No |
| Disabled | Administrative state that does not participate in standard STP operations. | No | No |
| Blocking | The port does not forward Ethernet frames. | Yes (receives and processes BPDUs only) | No |
| Listening | The loop-free topology is computed in this state, and the port is assigned its role. | Yes (sends and receives BPDUs) | No |
| Learning | An additional state that delays frame forwarding to avoid flooding the network. | Yes | Yes (populates the MAC address table) |
| Forwarding | Normal operation, forwarding Ethernet frames. | Yes | Yes |

