Free tech learning for everyone, from basics to pro

Routing & SwitchingNetworking SecurityIntermediate

Spanning tree in practice: port states, path cost, PortFast and BPDU Guard

In short: Spanning tree keeps a switched network loop-free by blocking redundant ports. Classic STP takes 30 to 50 seconds to bring a port up; RSTP takes about a second. Path cost picks each switch's route to the root. PortFast, BPDU Guard and Root Guard make edge ports fast and keep rogue switches from disrupting the tree.

Port states and roles

Spanning tree elects a root bridge and blocks just enough ports to remove loops. How a port behaves depends on its state (what it does with frames) and its role (its job in the tree).

Classic STP port statesBlockingup to 20 sListening15 sLearning15 s, fill tableForwardinguser traffic
Figure 1. A port running classic 802.1D spanning tree waits through listening and learning before it forwards, which is why a new link can take 30 to 50 seconds to pass traffic.
Classic STP (802.1D) stateRSTP (802.1w) stateLearns MACs?Forwards frames?
Disabled, Blocking, ListeningDiscardingNoNo
LearningLearningYesNo
ForwardingForwardingYesYes

RSTP roles are root (best path to the root), designated (forwards onto a segment), alternate (a ready backup path to the root) and backup (a spare on a shared segment). Classic timers are 2-second hellos, a 20-second max age and 15-second forward delay. RSTP uses a quick handshake between switches instead, so it normally converges in about a second. On Cisco, run spanning-tree mode rapid-pvst.

Path cost and the root port

Each non-root switch picks the port with the lowest total path cost to the root as its root port. Ties are broken by the lowest sender bridge ID, then the lowest sender port ID.

SpeedShort cost (802.1D-1998)Long cost (802.1t)
100 Mbit/s19200,000
1 Gbit/s420,000
10 Gbit/s22,000
100 Gbit/snot distinct200

Use the same method (spanning-tree pathcost method long) on all switches.

Choosing the root bridge

Always choose the root on purpose: make your core or distribution switch the root for each VLAN, with a second switch as backup. Otherwise the oldest switch with the lowest MAC address might become root and pull traffic through a slow path.

spanning-tree mode rapid-pvst
spanning-tree vlan 10,20,30 root primary      ! on the core switch
spanning-tree vlan 10,20,30 root secondary    ! on the backup core
show spanning-tree vlan 10
show spanning-tree summary

Protecting the tree

Spanning tree protectionPortFastedge ports forward nowBPDU Guardshut port on BPDURoot Guardkeep root in coreLoop Guardstop one-way loopsStorm controllimit broadcastsUDLDdetect one-way links
Figure 2. Features that make spanning tree faster on edge ports and protect it from mistakes and rogue switches.
  • PortFast lets access ports for PCs, printers and phones go straight to forwarding. It avoids DHCP timeouts at boot and stops topology change floods every time a PC restarts. Use it only on ports facing end devices.
  • BPDU Guard shuts down (err-disables) a PortFast port if a BPDU arrives, meaning someone plugged in a switch. Pair it with PortFast everywhere.
  • Root Guard on distribution ports facing access switches blocks any port that receives a superior BPDU, so no downstream switch can become root.
  • Loop Guard stops a blocked port from moving to forwarding just because BPDUs stopped arriving, which can happen with a one-way fibre fault.
interface range GigabitEthernet1/0/1 - 46
 switchport mode access
 spanning-tree portfast
 spanning-tree bpduguard enable
errdisable recovery cause bpduguard
errdisable recovery interval 300

Real-world example: a staff member brought a small switch from home and connected two of its ports to two wall sockets to "get more speed". Without protection this created a loop and a broadcast storm across the floor. With BPDU Guard enabled, both access ports went err-disabled within a second, the rest of the network carried on, and the logs showed exactly which sockets to visit.

Common mistakes: enabling PortFast on a port that connects to another switch, which can create a temporary loop; using BPDU filter globally to "quieten" logs, which silently disables protection; letting different switches run different spanning tree modes without a plan; and never checking which switch is actually the root. Run show spanning-tree root on a few switches after every change to confirm the root bridge is where you expect it, and record the result in your documentation.

Practice

A PC takes about 30 seconds to get a network connection after boot, and DHCP sometimes fails. What should you enable?
PortFast on its access port (with BPDU Guard), so the port forwards immediately instead of waiting through listening and learning.
Which feature shuts a port down if it receives any BPDU?
BPDU Guard.
A switch has two paths to the root: one 1 Gbit/s link direct, and two 1 Gbit/s links via another switch. Using short costs, which is the root port?
The direct link: cost 4, compared with 4 + 4 = 8 via the other switch.

Key takeaways

  • Classic STP passes through blocking, listening and learning; RSTP converges in about a second.
  • RSTP port roles: root, designated, alternate and backup.
  • The root port is the lowest total path cost to the root; set the root bridge deliberately.
  • PortFast plus BPDU Guard on every end-device port.
  • Root Guard keeps the root in the core; Loop Guard stops one-way link loops.
Tracks your learning on this device only. See your progress on the learning paths.

About the author

Mohamed Fayas

Founder of FM TecHub. CCNA certified, with a BTEC HND in Network Engineering, and BEng (Hons) in Computer Networking and Cloud Security. He writes practical, plain-English guides on networking, security and cloud.

More about the author

Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.

Stay up to date by email

New notes, tools and security news from FM TecHub, explained simply. Free.

We only use your email to send these updates. See our privacy policy.