Spanning Tree Protocol (STP) - Complete Cisco Networking Tutorial
CCNA 200-301 | Switching and Wireless | Beginner to Advanced
1. Introduction to Spanning Tree Protocol (STP)
Spanning Tree Protocol (STP) is a Layer 2 network protocol designed to prevent switching loops in Ethernet networks.
In enterprise networks, switches are often connected through multiple redundant links to provide high availability. However, redundant connections can create Layer 2 loops if all paths forward traffic simultaneously.
STP prevents these loops by identifying redundant network paths and placing selected switch ports into a non-forwarding state while maintaining alternative paths for redundancy.
STP is defined by the IEEE 802.1D standard.
Why is STP Required?
Without STP, Layer 2 loops can cause:
Broadcast storms
MAC address table instability
Duplicate Ethernet frames
Excessive CPU utilization on switches
Network congestion
Complete network outages
Example:
Consider three switches connected in a triangle.
If all links forward traffic, a broadcast frame originating from one switch may circulate repeatedly through the network.
Because Ethernet frames do not have a Time-to-Live (TTL) field, the frames can continue circulating until the loop is removed.
STP automatically prevents this condition by blocking redundant forwarding paths.
2. STP Network Topology
Legend:
DP — Designated Port
RP — Root Port
ALT — Alternate Port
FWD — Forwarding
BLK — Blocking/Discarding
The topology assumes equal-speed Gigabit Ethernet links and the configured bridge priorities shown above.
Network Devices
| Device | Role | STP Priority |
|---|---|---|
| SW1 | Root Bridge | 4096 |
| SW2 | Non-root switch | 8192 |
| SW3 | Non-root switch | 16384 |
Interface Connections
| Device | Interface | Connected To |
|---|---|---|
| SW1 | Gi0/1 | SW2 Gi0/1 |
| SW1 | Gi0/2 | SW3 Gi0/1 |
| SW2 | Gi0/2 | SW3 Gi0/2 |
All connections operate as 802.1Q trunk links carrying VLAN 10.
3. How Spanning Tree Protocol Works
STP creates a loop-free logical topology through a series of decisions.
Step 1 — Root Bridge Election
All switches exchange Bridge Protocol Data Units (BPDUs).
STP elects the switch with the lowest Bridge ID as the Root Bridge.
Step 2 — Root Port Selection
Every non-root switch selects its best path toward the Root Bridge.
The interface providing this path becomes the Root Port.
Step 3 — Designated Port Selection
Each network segment elects a Designated Port responsible for forwarding traffic toward that segment.
Step 4 — Blocking Redundant Paths
Any redundant port that is not selected for forwarding is placed into a non-forwarding state.
Step 5 — Network Convergence
STP maintains a loop-free forwarding topology and recalculates paths when network changes occur.
4. Root Bridge Election
The Root Bridge is the central reference point of the spanning-tree topology.
Every switch participating in an STP instance exchanges information to determine which switch has the lowest Bridge ID.
Bridge ID Components
The Bridge ID contains:
Bridge Priority
Extended System ID, when used
Switch MAC Address
Root Bridge Selection Rules
Lowest Bridge Priority wins.
If priorities are equal, the lowest MAC address wins.
Example
| Switch | Configured Priority | Root Election |
|---|---|---|
| SW1 | 4096 | Root Bridge |
| SW2 | 8192 | Non-root |
| SW3 | 16384 | Non-root |
SW1 becomes the Root Bridge because it has the lowest configured priority.
For VLAN 10 with the extended system ID enabled, the operational priority displayed by Cisco IOS is 4106.
Important Points
STP priorities are normally configured in increments of 4096.
The default configured bridge priority is 32768.
A Root Bridge has no Root Port.
All active STP ports on the Root Bridge are Designated Ports for their respective segments.
5. STP Port Roles
5.1 Root Port (RP)
The Root Port provides the best path from a non-root switch toward the Root Bridge.
Characteristics:
Normally one Root Port per non-root bridge per STP instance.
Selected based on the best received spanning-tree information.
Forwards traffic after convergence.
Changes when network topology or path cost changes.
Example:
SW2 Gi0/1 connects directly to SW1.
SW2 selects Gi0/1 as its Root Port.
5.2 Designated Port (DP)
A Designated Port is selected to provide the best path toward the Root Bridge for a network segment.
Characteristics:
Forwards data frames.
Sends designated BPDUs.
Exists on each active LAN segment.
All active ports on the Root Bridge are Designated Ports.
Example:
On the SW2–SW3 link, SW2 Gi0/2 becomes the Designated Port because SW2 advertises better spanning-tree information than SW3.
5.3 Non-Designated Port
In traditional IEEE 802.1D STP, a port that is neither a Root Port nor a Designated Port remains in the Blocking state.
In Rapid STP, alternate paths are identified using the Alternate Port role.
Example:
SW3 Gi0/2 is the redundant path toward SW2.
With SW1 as root and equal-cost direct uplinks, SW3 Gi0/2 remains blocked/discarding.
This prevents a Layer 2 loop.
6. STP Port States
Traditional IEEE 802.1D STP uses five port states.
| State | Learns MAC | Forwards Data | Description |
|---|---|---|---|
| Blocking | No | No | Prevents loops |
| Listening | No | No | Participates in STP calculations |
| Learning | Yes | No | Learns source MAC addresses |
| Forwarding | Yes | Yes | Forwards user traffic |
| Disabled | No | No | Port is not participating |
6.1 Blocking
The port does not forward normal user traffic or learn source MAC addresses.
It processes BPDUs to maintain spanning-tree information.
6.2 Listening
The port participates in STP and prepares for forwarding.
It does not learn MAC addresses or forward user traffic.
6.3 Learning
The switch begins learning source MAC addresses from received frames but still does not forward user traffic.
6.4 Forwarding
The port forwards normal user traffic and learns MAC addresses.
6.5 Disabled
The interface does not participate in the active spanning-tree topology.
STP Convergence
For classic 802.1D STP with default timers, a port transitioning through Listening and Learning normally spends:
Listening: 15 seconds
Learning: 15 seconds
This gives approximately 30 seconds before forwarding for such a transition. Certain topology changes and failure scenarios can take longer, commonly around 50 seconds with default settings.
7. STP Path Cost
STP uses path cost to determine the best path toward the Root Bridge.
A lower total Root Path Cost is preferred.
Common Short Path Cost Values
| Link Speed | STP Cost |
|---|---|
| 10 Mbps | 100 |
| 100 Mbps | 19 |
| 1 Gbps | 4 |
| 10 Gbps | 2 |
These are the traditional short path cost values. Modern platforms may use the IEEE long path cost method, which has different values.
Example
SW3 has two possible paths to SW1.
Path 1: Direct
SW3 → SW1
Total cost = 4
Path 2: Through SW2
SW3 → SW2 → SW1
Total cost = 4 + 4 = 8
SW3 selects its direct connection to SW1 because it has the lower path cost.
Its connection to SW2 becomes the redundant non-forwarding path.
8. STP Configuration - Cisco Switches
Lab Objective
Configure three Cisco switches with VLAN 10, enable Rapid PVST+, and establish SW1 as the Root Bridge.
Rapid PVST+ is used for this practical lab because it is a common Cisco implementation of Rapid Spanning Tree Protocol (RSTP).
SW1 - Root Bridge Configuration
enable
configure terminal
hostname SW1
vlan 10
name USERS
exit
spanning-tree mode rapid-pvst
spanning-tree vlan 10 priority 4096
interface GigabitEthernet0/1
description CONNECTION_TO_SW2
switchport mode trunk
switchport trunk allowed vlan 10
no shutdown
exit
interface GigabitEthernet0/2
description CONNECTION_TO_SW3
switchport mode trunk
switchport trunk allowed vlan 10
no shutdown
exit
end
write memorySW2 - Configuration
enable
configure terminal
hostname SW2
vlan 10
name USERS
exit
spanning-tree mode rapid-pvst
spanning-tree vlan 10 priority 8192
interface GigabitEthernet0/1
description CONNECTION_TO_SW1
switchport mode trunk
switchport trunk allowed vlan 10
no shutdown
exit
interface GigabitEthernet0/2
description CONNECTION_TO_SW3
switchport mode trunk
switchport trunk allowed vlan 10
no shutdown
exit
end
write memorySW3 - Configuration
enable
configure terminal
hostname SW3
vlan 10
name USERS
exit
spanning-tree mode rapid-pvst
spanning-tree vlan 10 priority 16384
interface GigabitEthernet0/1
description CONNECTION_TO_SW1
switchport mode trunk
switchport trunk allowed vlan 10
no shutdown
exit
interface GigabitEthernet0/2
description CONNECTION_TO_SW2
switchport mode trunk
switchport trunk allowed vlan 10
no shutdown
exit
end
write memoryNote: Interface names differ between Cisco switch models. Change the interface names to match your lab hardware. Some models also require explicit trunk encapsulation selection when both ISL and 802.1Q are supported.
9. STP Verification
9.1 Verify Root Bridge
Execute on SW1:
show spanning-tree vlan 10Representative output:
VLAN0010
Spanning tree enabled protocol rstp
Root ID Priority 4106
Address 0011.1111.1111
This bridge is the root
Bridge ID Priority 4106
Address 0011.1111.1111
Interface Role Sts Cost
------------ ---- --- ----
Gi0/1 Desg FWD 4
Gi0/2 Desg FWD 4What to verify:
SW1 reports
This bridge is the root.Both interfaces are Designated Ports.
Both interfaces are forwarding.
The operational bridge priority reflects the configured priority and VLAN ID.
9.2 Verify SW2 STP Roles
SW2# show spanning-tree vlan 10Representative interface output:
Interface Role Sts Cost
------------ ---- --- ----
Gi0/1 Root FWD 4
Gi0/2 Desg FWD 4What to verify:
Gi0/1 is the Root Port.
Gi0/2 is the Designated Port.
Both ports are forwarding.
9.3 Verify SW3 STP Roles
SW3# show spanning-tree vlan 10Representative interface output:
Interface Role Sts Cost
------------ ---- --- ----
Gi0/1 Root FWD 4
Gi0/2 Altn BLK 4What to verify:
Gi0/1 is the Root Port.
Gi0/2 is the Alternate Port.
Gi0/2 is discarding user traffic, preventing a switching loop.
SW1 remains the Root Bridge.
10. STP Failover and Convergence
Scenario - Primary Uplink Failure
Suppose the direct connection between SW1 and SW3 fails.
Before Failure:
SW3 Gi0/1 → Root / Forwarding
SW3 Gi0/2 → Alternate / DiscardingSW3 normally reaches SW1 directly.
Failure Simulation
On SW3:
configure terminal
interface GigabitEthernet0/1
shutdown
endExpected Behavior
SW3 loses its direct connection to SW1.
STP recalculates the available forwarding topology.
SW3 selects the path through SW2.
SW3 Gi0/2 becomes the Root Port.
SW3 Gi0/2 transitions to forwarding.
Network connectivity can continue through SW2.
After Failure:
SW3 → SW2 → SW1
SW3 Gi0/2 → Root / ForwardingVerification
SW3# show spanning-tree vlan 10Expected interface state:
Gi0/2 Root FWDRestore Primary Uplink
configure terminal
interface GigabitEthernet0/1
no shutdown
endAfter convergence, SW3 should prefer its direct lower-cost connection to SW1 again.
11. STP Protection Features
Cisco switches support additional features to improve STP stability and security.
11.1 PortFast
PortFast allows appropriate edge interfaces connected to end devices to enter forwarding immediately.
interface GigabitEthernet0/10
switchport mode access
spanning-tree portfastRecommended for: End-user PCs, printers, and other appropriate edge devices.
11.2 BPDU Guard
BPDU Guard prevents unexpected bridging devices from participating through protected edge ports.
interface GigabitEthernet0/10
spanning-tree bpduguard enableWhen a BPDU is received, the interface is placed into the err-disabled state.
11.3 Root Guard
Root Guard prevents a downstream switch from unexpectedly becoming the Root Bridge.
interface GigabitEthernet0/2
spanning-tree guard rootApply it only on suitable designated ports where superior BPDUs should not appear.
11.4 Loop Guard
Loop Guard protects against switching loops caused by the unexpected loss of BPDUs.
interface GigabitEthernet0/2
spanning-tree guard loopWhen expected BPDUs disappear under qualifying conditions, Loop Guard places the affected port into a loop-inconsistent state.
STP Protection Comparison
| Feature | Primary Purpose |
|---|---|
| PortFast | Faster edge connectivity |
| BPDU Guard | Prevent unauthorized switch connections |
| Root Guard | Prevent unwanted root election |
| Loop Guard | Prevent loops caused by BPDU loss |
| BPDU Filter | Suppress BPDU exchange under configured conditions |
12. STP Troubleshooting
Scenario 1 - Incorrect Root Bridge
Problem: An unexpected switch becomes the Root Bridge.
Verification:
show spanning-tree root
show spanning-tree vlan 10Solution:
Configure the intended Root Bridge with a lower Bridge Priority.
spanning-tree vlan 10 priority 4096Scenario 2 - Unexpected Blocking Port
Problem: An uplink is blocked when forwarding was expected.
Verification:
show spanning-tree vlan 10
show spanning-tree interface gi0/2 detailCheck:
Root Bridge identity
STP path costs
Port roles
Bridge priorities
Neighbor bridge information
Scenario 3 - STP Topology Changes
Problem: Frequent topology changes affect network stability.
Verification:
show spanning-tree detail
show loggingCheck:
Interfaces flapping
Unstable fiber links
Incorrect trunk connectivity
Unexpected bridging devices
Access ports without PortFast
Scenario 4 - BPDU Guard Err-Disabled Port
Problem: An access interface unexpectedly stops forwarding.
Verification:
show interfaces status err-disabled
show loggingSolution:
Identify and remove the unexpected BPDU source before recovering the interface.
configure terminal
interface GigabitEthernet0/10
shutdown
no shutdown
end13. Important STP Verification Commands
| Command | Purpose |
|---|---|
show spanning-tree | Display STP information |
show spanning-tree vlan 10 | Display STP for VLAN 10 |
show spanning-tree root | Identify the Root Bridge |
show spanning-tree summary | Show STP summary information |
show spanning-tree detail | Display detailed STP information |
show spanning-tree interface gi0/1 detail | Verify a specific interface |
show spanning-tree inconsistentports | Identify STP-inconsistent interfaces |
show interfaces trunk | Verify trunk operation |
show logging | Examine STP-related events |
14. STP vs RSTP vs MSTP
| Feature | STP | RSTP | MSTP |
|---|---|---|---|
| IEEE Standard | 802.1D | 802.1w | 802.1s |
| Convergence | Relatively slow | Faster | Faster |
| Port States | 5 | 3 | 3 |
| Root Bridge Election | Yes | Yes | Per instance |
| Alternate Port | Not separately named | Yes | Yes |
| Multiple VLAN Mapping | No, standard single tree | No, standard single tree | Yes |
| Recommended Use | Legacy networks | Modern switching | Larger multi-VLAN networks |
RSTP and MSTP are incorporated into later revisions of IEEE 802.1Q.
Cisco Rapid PVST+ runs a separate rapid spanning-tree instance per VLAN, whereas MSTP maps multiple VLANs to common spanning-tree instances.
15. Lesson Summary
Spanning Tree Protocol is an essential Layer 2 technology used to maintain loop-free Ethernet networks.
STP elects a Root Bridge, selects the best forwarding paths, and blocks redundant links that could otherwise create switching loops.
Important concepts include:
Root Bridge election
Bridge ID and priorities
Root and Designated Ports
STP path cost calculation
Port states and convergence
Redundant link failover
PortFast, BPDU Guard, Root Guard, and Loop Guard
STP configuration, verification, and troubleshooting
Understanding STP is essential for CCNA certification, enterprise network administration, Cisco switching troubleshooting, and advanced networking technologies such as RSTP, Rapid PVST+, and MSTP.
Learn More with Network Guide Academy
Master Cisco Networking with practical tutorials, real-world network topologies, device-by-device configuration examples, troubleshooting guides, and hands-on labs.
Website: https://networkguideacademy.com
Network Guide Academy — Learn Networking from Fundamentals to Production.
