Spanning Tree Protocol Basics
Learn how STP blocks redundant paths to prevent loops.
Spanning Tree Protocol Basics is a free Network+ Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Network+ Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Loop Solution
Networks want redundant links for reliability but cannot tolerate the loops they create. Spanning Tree Protocol (STP) solves this. STP automatically detects redundant paths between switches and blocks just enough of them to leave a single loop-free path, while keeping the blocked links ready as backups. This lesson covers the basics of how STP prevents loops without sacrificing redundancy.
The Core Idea
STP builds a logical tree with no loops on top of a physical network that may contain loops. It does this by choosing one path between any two points and disabling the rest. If the active path later fails, STP reactivates a blocked link to restore connectivity. So you get redundancy for resilience and a loop-free shape for safety at the same time.
Electing the Root Bridge
STP first elects a root bridge, the reference switch at the top of the tree. Switches compare a value called the bridge ID, made of a configurable priority plus the switch MAC address. The switch with the lowest bridge ID wins and becomes root. All path calculations are measured relative to this root, so its placement shapes the whole tree.
Choosing Root Ports
Every non-root switch picks one root port: the port with the lowest-cost path back toward the root bridge. Cost is based on link speed, faster links have lower cost. The root port is the switch best route to the top of the tree. Traffic destined for the root or beyond generally leaves through this port.
Designated and Blocked Ports
For each network segment, STP also picks one designated port, the port responsible for forwarding onto that segment. Ports that are neither root nor designated are put into a blocking state. A blocked port does not forward data, which breaks the loop, but it still listens for STP messages so it can take over if the active path fails.
BPDUs
Switches coordinate using BPDUs (Bridge Protocol Data Units), small messages exchanged between switches. BPDUs carry bridge IDs and path costs, letting switches elect the root, calculate paths, and detect topology changes. If BPDUs stop arriving on a blocked port, STP assumes a link failed and may bring that port back into service to restore the path.
Port States
Classic STP moves ports through states: blocking, listening, learning, and forwarding. The transition prevents a port from forwarding too soon and accidentally creating a temporary loop. The downside is delay, around 30 to 50 seconds to fully open a port. This slow convergence motivated faster versions of the protocol.
Rapid Spanning Tree
RSTP (Rapid Spanning Tree Protocol, 802.1w) is the modern improvement. It converges in just a few seconds rather than tens of seconds by streamlining port states and negotiating changes directly between switches. RSTP is backward compatible with older STP and is the default on most current switches, so a failed link is restored far more quickly.
PortFast and BPDU Guard
Two helpful features appear often. PortFast lets an access port connecting an end device skip the waiting states and forward immediately, since a single PC cannot create a loop. BPDU Guard protects those ports by shutting them down if they unexpectedly receive a BPDU, which would mean someone plugged a switch into a port meant for a PC.
interface GigabitEthernet0/4
switchport mode access
spanning-tree portfast
spanning-tree bpduguard enableConvergence and Failover
Convergence is the time STP takes to settle into a stable, loop-free state after a change. When an active link fails, BPDUs stop arriving where expected, STP recalculates, and a previously blocked port transitions to forwarding to restore the path. Classic STP takes tens of seconds to converge; RSTP does it in a few seconds. Faster convergence means shorter outages, which is why RSTP replaced classic STP on modern switches.
Why STP Matters
STP and its faster cousin RSTP run quietly on virtually every managed switch, silently preventing the broadcast storms that loops would cause while preserving backup links. Understanding the root bridge election, port roles, and BPDUs is core Network+ knowledge. When a backup link must take over, it is STP that decides, in seconds with RSTP, how to keep the network loop-free.
Quick Check
Test your STP basics.
Recap
Spanning Tree Protocol (STP) prevents loops while keeping redundant links as backups. It elects a root bridge (lowest bridge ID), picks a root port on each switch toward the root, a designated port per segment, and puts extras into blocking. Switches coordinate with BPDUs. Classic STP is slow; RSTP converges in seconds. PortFast speeds up end-device ports and BPDU Guard protects them.
Frequently asked questions
Is the “Spanning Tree Protocol Basics” lesson free?
Yes — the full text of “Spanning Tree Protocol Basics” is free to read here on the web, and the Network+ Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Network+ Academy course, upgrade to CoddyKit PRO.
What will I learn in “Spanning Tree Protocol Basics”?
Learn how STP blocks redundant paths to prevent loops. You practise Network+ Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Network+ Academy?
No prior experience is required. Network+ Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Spanning Tree Protocol Basics” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Network+ Academy lesson?
Yes. Every Network+ Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- What a VLAN Is and Why It Helps
- Access Ports and Trunk Links
- Why Switching Loops Are Dangerous
- Spanning Tree Protocol Basics