Skip to content
Adam Spera

Spanning Tree Protocol (STP)

For an intro to 802.1D Spanning-Tree, checkout CertBros Explanation for an excellent conceptual start.

Remember, like most Layer 2 protocols, LOWER values are better!

Keep in mind that 802.1D Spanning-Tree is only ever implemented on modern network switches using PVST+. This enhancements allows a spanning-tree instance to run per VLAN. This means that each VLAN has its own spanning-tree process and topology— but devices can only handle up to 128 instances.

Most of this document is focused on PVST+ spanning-tree operation, with a section for Rapid-PVST+ for [[Rapid Spanning-Tree Protocol (RSTP)]] operations at the end. A separate document will be made for [[Multiple Spanning-Tree (MST)]].

BPDUs are special Layer 2 messages forwarded by switches downstream to share STP information. These messages are used to:

  • Elect the Root Bridge
  • Determine the best path to the Root
  • Prevent loops by defining port roles

There are two main types:

TypeDescription
ConfigurationUsed in standard STP for root election and updates.
Topology Change Notification (TCN)Alerts the network of a topology change.

The “best path” is what is called a Path Cost, or a Root Cost.

  1. Each switch adds its the receiving ports cost to the cost received in a BPDU.
    1. For example, if a non-root switch receives a BPDU from the root bridge with a cost of 0, it will then look at the received interfaces bandwidth, and add that equivalency value to the root cost when forwarding it downstream.
  2. It then forwards the BPDU with the updated root cost to other switches.
  3. Each switch uses this info to:
    • Choose the Root Port (best path to Root Bridge)
    • Elect Designated Ports on each segment

Port Cost is a numerical value assigned to each interface based on its bandwidth, used by STP to select the lowest-cost path to the Root Bridge.

There are two path cost calculation methods:

Link Bandwidth(Short) Cost(Long) Cost
10 Mbps1002,000,000
100 Mbps19200,000
1 Gbps420,000
10 Gbps22,000
100 GbpsN/A200
1 TbpsN/A20

Use the following configuration to use the Long port costs:

spanning-tree pathcost method long

Use the following configuration to custom configure a port cost for an interface:

spanning-tree cost <1-200000000>
spanning-tree vlan 1 cost <1-200000000>

Note: if you do not specify which VLAN, it will apply to all VLANs on that interface.

Devices running STP will first negotiate and determine who the Root Bridge is in the network. To do this, they perform the following steps:

  1. All switches assume they are the Root Bridge initially. Each switch sends out BPDUs containing its own Bridge ID (Bridge Priority (default is 32768) + VLAN ID + ":" + MAC Address).

  2. As switches receive BPDUs from other switches, they compare them to their current best-known BPDU (themselves if first received). If a switch receives a superior BPDU (one with a lower Bridge ID), it stops claiming to be root and forwards that superior BPDU instead. Note that when forwarding it alters values like root costs etc.

  3. Eventually, all switches agree on the same root bridge, the switch with the lowest Bridge ID.

For example, in the following topology, SW2 has the lowest MAC address, which is appended to the Bridge Priority, so it becomes the Root Bridge.

SwitchPriorityMAC AddressBridge ID
SW13276800:11:22:33:44:0332768.00:11:22:33:44:03
SW23276800:11:22:33:44:0132768.00:11:22:33:44:01 ← 🏆
SW33276800:11:22:33:44:0232768.00:11:22:33:44:02

Spanning-tree priority values can only be configured in increments of 4096. Making its configurable range to be 0-61440.

(config)#spanning-tree vlan 1 priority ?
% Bridge Priority must be in increments of 4096.
% Allowed values are:
0 4096 8192 12288 16384 20480 24576 28672
32768 36864 40960 45056 49152 53248 57344 61440

There are three ways to configure a devices spanning-tree priority:

(config)# spanning-tree vlan 1 priority 4096
(config)# spanning-tree vlan 1 root primary
(config)# spanning-tree vlan 1 root secondary

The command that uses root primary will take the current known Root Bridge’s priority, and set its own priority to TWO intervals less than, so: mypriority - 8192.

The command that uses root secondary will take the current known Root Bridge’s priority, and set its own priority to ONE intervals less than, so: mypiority - 4096.

All ports on the Root Bridge are Designated ports (forwarding state).

Each remaining switch will select ONE of its interfaces to be its Root Port (forwarding state).

The Root Port Selection process is as follows:

  1. Lowest Root Cost - BUT what if they have the same Root Cost?
  2. Lowest neighbor Bridge ID - BUT what if they have the the Bridge ID (two ports to the same switch)?
  3. Lowest neighbor Port ID - The Port ID is a value assigned to all ports, with a numerical value per port as the decimal: Port Priority (128) + "." + Port Number.

Each remaining collision domain will select ONE interface to be a Designated Port (forwarding state). The other port in the collision domain will be Blocking (**non-designated).

The Blocking Selection process is as follows:

  1. LOCAL interface with lowest Root Cost - becomes Designated and the neighbor Blocks.
    • BUT what if its a tie?
  2. LOCAL switch with the lowest Bridge ID - becomes Designated and the neighbor Blocks.

Below is an excellent example of this election process from Jeremy’s IT Lab - Part 1 (30 minutes in).

JeremySTP-P1

The general flow of an 802.1D STP environment in terms of timers is as follows:

  1. Failure Occurs
  2. Max Age (20s) — Wait to detect failure.
  3. Forward Delay (15s) — Listening…
  4. Forward Delay (15s) — Learning…
  5. Port becomes Forwarding
TimerDefaultUsed By
Hello2 secondsRoot Bridge
Forward Delay15 secondsAll Bridges
Max Age20 secondsAll Non-Root Bridges
! STP & RSTP
(config)# spanning-tree vlan 1 hello-time <1-10>
(config)# spanning-tree vlan 1 max-age <6-40>
(config)# spanning-tree vlan 1 forward-time <4-30>
! RSTP
(config)# spanning-tree mode rapid-pvst
(config)# interface Ethernet1/1
(config-if)# spanning-tree link-type point-to-point

CertBros Explanation CBT Micro-Nugget Jeremy’s IT Lab - Part 1 Jeremy’s IT Lab - Part 2 Jeremy’s IT Lab - Algorithm Jeremy’s IT Lab - Analyzing CBT Nuggets - CCIE L2 Cisco Press STP Whitepaper INE Course - Switched Campus Kevin Wallace - Deep Dive