On this page 22 sections
- What Spanning Tree Protocol is
- Why Layer 2 loops are dangerous
- Lab topology — three switches in a triangle
- Key STP concepts
- Step 1 — how the Root Bridge is elected
- Make SW1 the Root Bridge
- Step 2 — how a non-root switch chooses its Root Port
- Understand STP path cost
- Step 3 — how Designated Ports are selected
- Step 4 — which port gets blocked in the triangle?
- Verify every port role
- STP port states and RSTP behavior
- Configure Rapid PVST+
- Lab 1 — observe an already blocked link
- Lab 2 — demonstrate failover
- Lab 3 — what happens when STP is disabled?
- Change which switch becomes root
- Change STP path selection
- PortFast and BPDU Guard
- Common STP mistakes
- STP verification quick reference
- Workshop questions
What Spanning Tree Protocol is
Spanning Tree Protocol (STP) prevents Layer 2 forwarding loops when switches have redundant physical connections. Instead of removing cables, STP keeps some links from forwarding ordinary user traffic so that the active Layer 2 topology is loop-free.
If an active link fails, STP can recalculate the topology and make a previously blocked path available.
STP does not aggregate bandwidth. It selects a loop-free topology; LACP is a different technology used to combine compatible physical links into one logical connection.
Why Layer 2 loops are dangerous
Unlike IP packets, Ethernet frames do not have a normal hop-count or TTL field that limits the number of Layer 2 switches they can cross.
With redundant active paths, a broadcast or unknown unicast may circulate and be copied repeatedly. Consequences include:
- Broadcast storms: excessive copies of broadcast frames consume bandwidth.
- MAC address flapping: a switch learns the same source MAC on different ports repeatedly.
- Duplicate frames: hosts may receive multiple copies of traffic.
- Network instability: links and switch CPUs can become overwhelmed.
Lab topology — three switches in a triangle
There are three physical links, forming a cycle. STP must prevent all three from forwarding user traffic at once.
[ SW1 ]
/ \
Fa0/1 Fa0/1
/ \
[ SW2 ]-----[ SW3 ]
Fa0/2 Fa0/2
SW1 Fa0/1 <-> SW2 Fa0/1
SW1 Fa0/2 <-> SW3 Fa0/1
SW2 Fa0/2 <-> SW3 Fa0/2
Use three Cisco 2960 switches.
Attach one PC to SW2 and one PC to SW3 on free access ports.Key STP concepts
- BPDU: Bridge Protocol Data Unit, used by switches to exchange spanning-tree information.
- Bridge ID (BID): value containing the configured bridge priority, extended system ID (typically the VLAN ID in PVST), and bridge MAC address.
- Root Bridge: the switch with the lowest Bridge ID for that spanning-tree instance.
- Root Path Cost: cumulative STP cost of the best path toward the Root Bridge.
- Root Port (RP): the non-root switch's best port toward the Root Bridge.
- Designated Port (DP): the port selected to forward toward a particular Layer 2 segment.
- Alternate Port: a backup path toward the root in RSTP; normally discarding.
- Port state: whether a port forwards frames, learns MAC addresses, or is kept from forwarding.
Terminology note: classic 802.1D STP commonly describes a blocked port as *blocking*. Rapid STP (802.1w/RSTP) uses *discarding*; the roles and states are not identical between versions.
Step 1 — how the Root Bridge is elected
Look for Root ID and Bridge ID. On the Root Bridge, the switch reports that it is the root for the instance.
show spanning-tree vlan 1
show spanning-tree rootMake SW1 the Root Bridge
Use root primary on the intended root and root secondary on a backup switch, not both on the same switch. These commands adjust priority; they are not continuously enforced root-election guarantees.
enable
configure terminal
hostname SW1
spanning-tree vlan 1 priority 4096
end
show spanning-tree vlan 1configure terminal
spanning-tree vlan 1 priority 8192
endconfigure terminal
spanning-tree vlan 1 priority 12288
endspanning-tree vlan 1 root primary
spanning-tree vlan 1 root secondaryStep 2 — how a non-root switch chooses its Root Port
Each non-root switch normally chooses exactly one Root Port per STP instance. This port offers the best received path toward the Root Bridge.
Root Port selection compares the best spanning-tree information. In a typical triangle, use this practical order:
1. Lowest total Root Path Cost through the port.
2. Lowest sender Bridge ID if the costs tie.
3. Lowest sender Port ID if still tied.
4. Lowest local Port ID if all preceding comparisons tie.
The Root Bridge itself has no Root Port: its eligible ports are normally Designated Ports.
Understand STP path cost
A path's cost is the sum of the STP port costs along the route to the Root Bridge. Cisco platforms can use different cost methods, so always verify the actual values.
Common short-cost examples used in entry-level Cisco labs:
| Link speed | Typical short STP cost |
| --- | ---: |
| 10 Mbps | 100 |
| 100 Mbps | 19 |
| 1 Gbps | 4 |
| 10 Gbps | 2 |
show spanning-tree vlan 1
show spanning-tree interface fastEthernet 0/1 detailStep 3 — how Designated Ports are selected
Each Layer 2 segment needs a Designated Port, which advertises the best spanning-tree information toward that segment.
To choose between competing ports, STP prefers:
1. The port advertising the lowest Root ID.
2. The port advertising the lowest path cost to the root.
3. The port belonging to the lowest sender Bridge ID.
4. The port with the lowest sender Port ID.
On the link connecting two non-root switches, the switch with the better advertised information wins the Designated Port role. The other side may become a non-forwarding backup port.
Step 4 — which port gets blocked in the triangle?
Assume all three inter-switch links use the same speed, and we have configured:
| Switch | Configured priority | Expected role |
| --- | ---: | --- |
| SW1 | 4096 | Root Bridge |
| SW2 | 8192 | Non-root switch |
| SW3 | 12288 | Non-root switch |
The expected result is:
```text
SW1 (ROOT)
/ \
DP / \ DP
/ \
RP/ \RP
SW2-----------SW3
DP ALT/BLK
SW1 -> SW2: forwarding
SW1 -> SW3: forwarding
SW2 -> SW3: SW2 designated/forwarding;
SW3 alternate/discarding (or blocking in classic STP)`
Why SW3 blocks its port toward SW2: both SW2 and SW3 have a direct path of equal cost to the root SW1. On their shared link, their root costs tie, so the lower Bridge ID of SW2 wins the Designated Port election. SW3's port on that link is not needed for the active tree.
The cable is not disconnected and the interface is not administratively shut down. STP prevents normal user data forwarding on the redundant port while retaining a backup path.
Verify every port role
Typical abbreviations in classic Cisco output include Root, Desg, and Altn for the root, designated, and alternate roles. Actual state labels depend on the STP variant and software.
show spanning-tree
show spanning-tree vlan 1
show spanning-tree root
show spanning-tree interface fastEthernet 0/2 detail
show interfaces statusSTP port states and RSTP behavior
Classic 802.1D STP uses these states:
- Blocking: does not forward user frames or learn source MACs.
- Listening: participates in topology decisions without forwarding or learning.
- Learning: builds the MAC address table without forwarding user frames.
- Forwarding: forwards user frames and learns MACs.
- Disabled: not participating.
RSTP (802.1w) combines the non-forwarding states into discarding, plus learning and forwarding. Rapid convergence depends on port roles and link conditions.
Configure Rapid PVST+
Check which STP modes are supported by your selected Packet Tracer switch image.
enable
configure terminal
spanning-tree mode rapid-pvst
end
show spanning-tree summary
show spanning-tree vlan 1Lab 1 — observe an already blocked link
1. Build the triangle with three switches and two PCs.
2. Leave STP enabled; set SW1, SW2, and SW3 priorities as shown.
3. Wait for convergence, then run show spanning-tree vlan 1 on every switch.
4. Identify the root, root ports, designated ports, and non-forwarding port.
5. Ping between the PCs. Connectivity should work through the active tree.
6. Explain why physically redundant connections do not imply that every link forwards user traffic.
Lab 2 — demonstrate failover
With STP enabled, disconnect the SW1–SW3 cable and observe:
1. SW3 loses its direct Root Port path to SW1.
2. SW3 can reach SW1 through SW2.
3. The SW2–SW3 link is brought into the active forwarding tree after convergence.
4. The PC-to-PC ping may pause briefly and then recover.
Reconnect the cable and verify that STP selects the appropriate loop-free topology again. The exact convergence delay depends on the STP mode and simulation.
Lab 3 — what happens when STP is disabled?
Restore STP on all three switches. If needed, return to Rapid PVST+ with spanning-tree mode rapid-pvst.
enable
configure terminal
no spanning-tree vlan 1
endconfigure terminal
spanning-tree vlan 1
end
show spanning-tree vlan 1Change which switch becomes root
Changing the root changes the preferred tree even when no physical cable has moved.
configure terminal
spanning-tree vlan 1 priority 0
end
show spanning-tree vlan 1Change STP path selection
The example cost is for experimentation. Compare the new cumulative Root Path Cost with the other route; do not assume this command automatically makes the configured port the Root Port.
configure terminal
interface fastEthernet 0/1
spanning-tree vlan 1 cost 50
end
show spanning-tree vlan 1PortFast and BPDU Guard
Do not enable PortFast blindly on inter-switch links.
configure terminal
interface fastEthernet 0/10
switchport mode access
spanning-tree portfast
spanning-tree bpduguard enable
endCommon STP mistakes
- Thinking the switch with the highest priority number becomes root. Lowest wins.
- Thinking the switch with the most ports automatically becomes root.
- Confusing the Root Bridge with a Root Port.
- Expecting the Root Bridge to have a Root Port.
- Assuming STP blocks an entire switch instead of a specific port in a given instance.
- Assuming the same port is always blocked regardless of bridge priorities and path costs.
- Confusing
blocking(classic STP state) withalternate(RSTP role). - Leaving STP disabled after a loop demonstration.
STP verification quick reference
show spanning-tree
show spanning-tree vlan 1
show spanning-tree root
show spanning-tree summary
show spanning-tree interface fastEthernet 0/1 detail
show mac address-tableWorkshop questions
1. Which switch wins if all three switches use the default STP priority?
2. Does the Root Bridge have a Root Port?
3. How does a non-root switch choose its Root Port?
4. On the SW2–SW3 link, why does SW2 become the Designated Port?
5. What changes after the direct SW1–SW3 link fails?
6. Why is disabling STP dangerous even when normal pings initially work?
Next topic: LACP — turn multiple physical links between the same two switches into one logical EtherChannel.