Spanning Tree Protocol
(STP) Mastery

A comprehensive interactive lesson for network administration students. Master STP concepts, BPDU structure, port states, and root bridge elections.

IEEE 802.1D
Layer 2 Switching
Loop Prevention
RSTP · PVST · MSTP
CompTIA Network+
📖

What is Spanning Tree Protocol?

Understanding the purpose and history of STP

🎯 Learning Objectives After this module you will be able to: define STP and explain why it exists, describe the problems loops cause in Ethernet networks, identify STP variants (STP, RSTP, PVST+, MSTP), and relate STP to the OSI Data Link layer.

🌐 The Loop Problem

Ethernet networks use switches to connect devices. When switches are connected in a redundant topology (multiple paths between switches), a Layer 2 loop can form. This causes:

  • Broadcast storms — frames replicate endlessly
  • MAC table instability — switches learn incorrect ports
  • Multiple frame delivery — hosts receive duplicates
  • Network collapse — 100% bandwidth consumed instantly

🛡️ STP Solution

STP (IEEE 802.1D, 1990) solves the loop problem by logically blocking redundant links while maintaining physical redundancy. It:

  • Elects a single Root Bridge as topology reference
  • Calculates the best path to root from each switch
  • Places redundant links in Blocking state
  • Automatically reconverges when topology changes

OSI Layer 2 — Data Link

STP operates at the Data Link Layer (Layer 2) of the OSI model. It uses BPDU (Bridge Protocol Data Unit) frames with a destination MAC of 01:80:C2:00:00:00 (STP multicast) to communicate between switches.

📜 STP Variants Timeline

StandardFull NameYearConvergenceKey Feature
802.1DOriginal STP199030–50 secLoop prevention baseline
PVST+Per-VLAN STP PlusCisco30–50 secInstance per VLAN (Cisco)
802.1wRapid STP (RSTP)20011–6 secNew port roles, rapid convergence
802.1sMultiple STP (MSTP)20021–6 secMaps multiple VLANs to instances
Rapid PVST+Rapid Per-VLAN STPCisco1–6 secRSTP + per-VLAN (Cisco default)
💡 Industry Note Modern Cisco switches run Rapid PVST+ by default. While original STP is less common today, its concepts are foundational for all variants and are tested on CompTIA Network+, CCNA, and CISSP examinations.
🧠

Core STP Concepts

Key terminology and operational principles

👑 Bridge ID (BID)

Every switch has a unique Bridge ID consisting of:

  • Priority: 2 bytes (default 32768)
  • Extended System ID: VLAN number (optional)
  • MAC Address: 6 bytes (tie-breaker)
BID = Priority (32768) + MAC
e.g., 32768:00:1A:2B:3C:4D:5E

🌳 Root Bridge

The switch with the lowest BID becomes the Root Bridge — the reference point for the entire spanning tree topology. All paths are calculated relative to it.

Best practice: Manually assign the Root Bridge to a high-performance, centrally located core switch using a lower priority (4096 or 8192).

💰 Path Cost

STP calculates the best path to the root based on cumulative port costs. Lower cost = preferred path.

SpeedCost (IEEE)
10 Mbps100
100 Mbps19
1 Gbps4
10 Gbps2

🔌 Port Roles

  • Root Port (RP) — Best path toward root bridge (one per non-root switch)
  • Designated Port (DP) — Best port on each segment toward root (forwards traffic)
  • Non-Designated / Blocked Port — Redundant port placed in Blocking state
  • RSTP adds: Alternate and Backup ports

⏱️ STP Timers

  • Hello Time — 2 sec: How often Root sends BPDUs
  • Forward Delay — 15 sec: Time in Listening and Learning states
  • Max Age — 20 sec: How long to store BPDU info before discarding
⚠️ Convergence Time: STP convergence can take up to 50 seconds (20 + 15 + 15) — a major drawback addressed by RSTP.

🔒 STP Enhancements & Security Features

PortFast Bypasses Listening/Learning on access ports (connected to end devices). Instantly moves to Forwarding.

BPDU Guard Disables a PortFast-enabled port if a BPDU is received — prevents unauthorized switch connections.

Root Guard Prevents external switches from becoming root bridge on a protected port.

Loop Guard Prevents Alternate/Root ports from becoming Designated if BPDUs stop arriving (prevents unidirectional link loops).

🗳️

Root Bridge Election Process

Step-by-step walk-through of how STP selects the Root Bridge

📋 Election Rules (in order of precedence) 1. Lowest Bridge Priority → 2. Lowest Bridge MAC Address (tie-breaker)

🔢 Bridge ID Calculator

Enter switch parameters to compute Bridge IDs and determine the Root Bridge winner.

📐 Root Port Selection (After Root Election)

On each non-root switch, the port with the lowest Root Path Cost becomes the Root Port. Ties are broken by:

  1. Lowest Sender Bridge ID
  2. Lowest Sender Port ID
  3. Lowest Receiving Port ID

🏆 Designated Port Selection

For each network segment, the port with the lowest Root Path Cost on that segment becomes the Designated Port. If costs are equal, the switch with the lower BID wins. All Root Bridge ports are automatically Designated.

🔄

STP Port States

Understanding how ports transition through STP states

DISABLED
Admin off
BLOCKING
Max Age (20s)
LISTENING
Fwd Delay (15s)
LEARNING
Fwd Delay (15s)
FORWARDING
Active ✓

📊 Port State Comparison Table

StateReceives BPDUsSends BPDUsLearns MACsForwards DataDuration
DisabledNoNoNoNoUntil enabled
BlockingYes ✓NoNoNoMax Age (20s)
ListeningYes ✓Yes ✓NoNoFwd Delay (15s)
LearningYes ✓Yes ✓Yes ✓NoFwd Delay (15s)
ForwardingYes ✓Yes ✓Yes ✓Yes ✓Normal operation

⚡ RSTP Port States (Simplified)

RSTP (802.1w) reduces states to just 3:

  • Discarding — Combines Disabled + Blocking + Listening
  • Learning — Same as STP Learning
  • Forwarding — Same as STP Forwarding

🔌 RSTP Port Roles

  • Root Port — Best path to root
  • Designated Port — Best port on segment
  • Alternate Port — Backup to Root Port
  • Backup Port — Backup Designated Port

RSTP achieves rapid convergence through proposal/agreement handshake mechanism.

🎮 Interactive Port State Explorer

Click any port state to learn what happens at that stage.

📦

Bridge Protocol Data Unit (BPDU)

Anatomy of the STP control message

📡 What is a BPDU? BPDUs are special Layer 2 frames exchanged by switches every Hello Time interval (2 seconds) to share STP topology information. They are sent to the STP multicast address 01:80:C2:00:00:00.

🎨 BPDU Frame Visual Map

Each colored block represents a field. Hover for details. Width is proportional to byte length.

📋 Configuration BPDU Fields

FieldSizeValue / Description
Protocol Identifier2 bytesAlways 0x0000 (Spanning Tree Protocol)
Protocol Version1 byte0x00 = STP, 0x02 = RSTP, 0x03 = MSTP
BPDU Type1 byte0x00 = Config, 0x80 = TCN (Topology Change Notification)
Flags1 byteTC bit (bit 0), TCA bit (bit 7); RSTP adds bits 1–6
Root Bridge ID8 bytesPriority + Extended SysID + MAC of Root Bridge
Root Path Cost4 bytesCumulative cost from sender to Root Bridge
Bridge ID8 bytesSender's own Bridge ID
Port ID2 bytesSender's port priority + port number
Message Age2 bytesHops from Root Bridge (in 1/256 sec increments)
Max Age2 bytesMaximum age for stored BPDU info (default 20s)
Hello Time2 bytesHello interval (default 2s)
Forward Delay2 bytesListening/Learning duration (default 15s)

🚩 BPDU Types

  • Configuration BPDU — Sent by Root Bridge every Hello Time; propagated by all switches. Contains full topology info (35 bytes).
  • TCN BPDU (Topology Change Notification) — Sent toward Root when a topology change is detected (1 byte payload).
  • RST BPDU — Used by RSTP; combines config and TCN into single message type.

🏳️ Flags Byte Breakdown

Bit 7
TCA
Bit 6
Agr
Bit 5
Fwd
Bit 4
Lrn
Bit 3
Role
Bit 2
Role
Bit 1
Prop
Bit 0
TC

TC=Topology Change, TCA=TC Ack, Agr=Agreement, Fwd=Forwarding, Lrn=Learning, Prop=Proposal (RSTP bits 1-6)

🔧

STP BPDU Header Builder

Construct a complete BPDU frame field by field

🛠️ Instructions Fill in each field below using the valid values described. Click Build BPDU to generate the hexadecimal representation of your BPDU frame. This mirrors what a real switch would transmit.

🔧 BPDU Frame Constructor

IEEE 802.1D Configuration BPDU — 35 bytes total

2 bytes
1 byte
1 byte
1 byte
2 bytes
6 bytes
4 bytes
2 bytes
6 bytes
2 bytes
2 bytes
2 bytes
2 bytes
2 bytes
🖥️

STP Network Simulator

Watch STP elect a root bridge and converge on a loop-free topology

// STP Simulation Log
Click "Next Step" or "Auto Run" to begin simulation...
📡 Simulation Legend 🟦 = Root Bridge  |  🟩 = Non-root Switch  |  🔴 = Blocked Port  |  🟢 = Forwarding Port  |  RP = Root Port  |  DP = Designated Port
📚

STP Glossary

Key terms and definitions for network administrators

Knowledge Check Quiz

Test your understanding of Spanning Tree Protocol