L2 · switching · reviewed

STP

Spanning Tree Protocol (IEEE 802.1D)

Keeps a switched network free of loops by disabling just enough ports to leave one active path between any two bridges.

Presenter modeEmbed this figure

IEEE 802.1D-2004 §17IEEE 802.1D-2004 §9.3.1IEEE 802.1D-1998

Why it exists

An Ethernet frame carries no hop count. Nothing in it decays, and a bridge that does not know where a destination lives floods the frame everywhere except the port it arrived on. Put those two facts together on a network with a redundant path and a single broadcast circulates indefinitely, multiplying at every junction until the switches stop forwarding anything at all.

The obvious fix — do not cable loops — is the wrong fix, because the loop is the redundancy. Spanning tree keeps the physical loop and disables just enough ports to leave exactly one active path between any two bridges, then re-enables them when something fails. IEEE 802.1D-2004 §17.1

A broadcast storm is not a slow network. Forwarding collapses within seconds and the switches usually become unmanageable, because the CPU is drowning in the same flood.

Electing a root and blocking the loop

Three switches with default settings converge on a loop-free topology in about thirty seconds. Both tiebreaks run.

Three switches, each cabled to the other two. The redundancy is deliberate, and so is the problem: a frame with an unknown destination will be flooded around the triangle forever. SW1. SW2. SW3.

SW1Physical loopSW2SW3100 Mb/s · cost 19100 Mb/s · cost 19100 Mb/s · cost 19
  • Link
  • Blocking
  • Packet in flight
  • Discarded
  • Emphasis
Select a device to read its state. Arrow keys walk the topology.
Text equivalent of this diagram
Devices and links at this step
ElementKindState
SW1switch
SW2switch
SW3switch
SW1SW2linkup · 100 Mb/s · cost 19
SW1SW3linkup · 100 Mb/s · cost 19
SW2SW3linkup · 100 Mb/s · cost 19
1 / 10
t = 0 s

Three switches, each cabled to the other two. The redundancy is deliberate, and so is the problem: a frame with an unknown destination will be flooded around the triangle forever.

Ethernet has no hop count. Nothing in the frame decays, so a single broadcast circulates until a link is pulled. Spanning tree exists to disable enough ports to leave exactly one path between any two bridges.

What changed

  • Physical loop
  • Emphasis on SW1 ↔ SW2
  • Emphasis on SW1 ↔ SW3
  • Emphasis on SW2 ↔ SW3

How it works

Every bridge has an identifier: a 16-bit priority followed by its MAC address. The bridge with the numerically lowest identifier becomes the root, and every other bridge measures itself by its cost back to that root. IEEE 802.1D-2004 §9.2.5

Bridges exchange that view in configuration BPDUs, and compare what they hear in a fixed order: root identifier, then root path cost, then the sending bridge’s identifier, then the sending port’s identifier. The first field that differs settles the comparison; the rest are never consulted. IEEE 802.1D-2004 §17.6

Roles follow from those comparisons. Each non-root bridge picks one root port — its best path to the root. Each segment picks one designated port — the end advertising the superior vector. Any port that is neither blocks, and blocking exactly those ports is what removes the loops. IEEE 802.1D-2004 §17.7

Nothing forwards immediately. A port that will forward first spends 15 seconds listening, then 15 seconds learning, because a bridge that forwarded on the strength of information the rest of the network had not yet received could create the loop it was trying to prevent. IEEE 802.1D-2004 §17.14

Try it

Run the election

Change a priority or a link cost and watch which comparison decides the outcome.

Bridge priority
Link cost

Root: SW1 · Blocked: SW3 on SW2–SW3

  1. root electionSW1 is root: bridge ID 32768.00:1a:2b:00:00:01 is lower than SW2's 32768.00:1a:2b:00:00:02. Priorities are equal, so the MAC address decided.
  2. root portSW2 selects its port on SW1–SW2 as root port (root path cost 19).
  3. root portSW3 selects its port on SW1–SW3 as root port (root path cost 19).
  4. designated portOn SW1–SW2, SW1 is designated over SW2, decided on root path cost.
  5. designated portOn SW1–SW3, SW1 is designated over SW3, decided on root path cost.
  6. designated portOn SW2–SW3, SW2 is designated over SW3, decided on sender bridge ID.
  7. blockedSW3 blocks port 128.6 on SW2–SW3.
Root path cost per bridge
BridgeBridge IDRoot path cost
SW1 (root)32768.00:1a:2b:00:00:010
SW232768.00:1a:2b:00:00:0219
SW332768.00:1a:2b:00:00:0319

On the wire

Constructed examples, encoded from the field table below them — not captured traffic.

The BPDU SW1 sends once it believes it is root: root identifier equals its own bridge identifier, and the root path cost is zero.

IEEE 802.3 MAC frame
Destination 01:80:C2:00:00:00, the Bridge Group Address. A length field, not an EtherType. IEEE 802.1D-2004
IEEE 802.2 LLC
DSAP 0x42, SSAP 0x42, control 0x03 (unnumbered information). IEEE 802.1D-2004
Bridge Protocol Data Unit
The fields below, in network byte order. IEEE 802.1D-2004

Configure it

Make SW1 the root deterministically instead of leaving it to the MAC address.

Cisco IOS-XE 17.12 · Catalyst 9300, Catalyst 9500draft

  1. spanning-tree mode pvst

    Selects per-VLAN 802.1D. Modern Catalyst platforms default to rapid-pvst, so classic STP behaviour has to be asked for.

    Common mistake: Leaving the default and then expecting 30-second transitions. Rapid-PVST converges in under a second and the timers in this config barely matter.

  2. spanning-tree vlan 1 priority 24576

    Lowers the priority one step below the 32768 default, so SW1 wins the election on priority and the address is never consulted.

    Common mistake: Using a value that is not a multiple of 4096. The low 12 bits carry the extended system ID and the command is rejected.

    IEEE 802.1D-2004 §9.2.5

  3. spanning-tree vlan 1 hello-time 2
    spanning-tree vlan 1 forward-time 15
    spanning-tree vlan 1 max-age 20

    The defaults, stated explicitly. Only the root bridge’s timers are used network-wide, so setting these anywhere else changes nothing until that switch becomes root.

    IEEE 802.1D-2004 §17.14

  4. interface GigabitEthernet1/0/1
     spanning-tree cost 19

    Pins the port cost to the 802.1D-1998 value for 100 Mb/s so the walkthrough’s arithmetic holds on a gigabit interface.

    IEEE 802.1D-2004 §17.14

Verify

show spanning-tree vlan 1
The bridge ID line reads “This bridge is the root”.
show spanning-tree vlan 1 detail
Per-port role and state, plus the timers in use.

Caveats

  • IOS-XE runs Rapid-PVST+ by default; `pvst` is chosen here only to observe classic 802.1D timing.
  • Priority is per VLAN. A switch can be root for one VLAN and not another, which is how PVST+ load-shares.

When it breaks

Symptom first, because that is what you have when it happens.

  1. Traffic between two distribution switches takes an odd path through an access switch, and throughput is far below the link speed.

    Narrow it down

    1. Run `show spanning-tree vlan <id>` on a distribution switch and read the root ID.
    2. Compare it to the local bridge ID. If the root is a switch you did not choose, the election fell through to MAC address.
    3. Trace the root port on each switch to see the path traffic is actually taking.

    Cause

    Every switch is at the default priority of 32768, so the lowest MAC address won. That is usually the oldest switch, which is usually at the edge.

    Fix

    Set the intended root to a lower priority (24576 or 4096) and the intended backup one step above it. Never rely on the address.

    IEEE 802.1D-2004 §9.2.5
  2. A host plugged into an access port cannot reach anything for about thirty seconds after link-up, and DHCP fails on boot.

    Narrow it down

    1. Watch the port state with `show spanning-tree interface <port> detail` immediately after link-up.
    2. Confirm it passes through listening and learning before forwarding.
    3. Check whether PortFast (edge port) is configured.

    Cause

    The port is running the full state machine. Two forward delays elapse before it forwards, and the DHCP client gives up first.

    Fix

    Configure the port as an edge port (`spanning-tree portfast`, `edge-port`, or the platform equivalent) so it forwards immediately, and pair it with BPDU Guard so a switch plugged in there is shut down rather than trusted.

    IEEE 802.1D-2004 §17.14
  3. A link failure takes the better part of a minute to recover, even though the interface went down instantly.

    Narrow it down

    1. Establish which port was blocking before the failure.
    2. Confirm that port had to wait for Max Age before it could act.
    3. Add the two forward delays that follow.

    Cause

    A blocked port holds recorded information until Max Age expires. Twenty seconds of ageing plus fifteen listening plus fifteen learning is fifty seconds.

    Fix

    Run RSTP. An alternate port already knows it is the backup and takes over through a proposal and agreement handshake rather than a timer.

    IEEE 802.1D-2004 §17.14
  4. A loop appears on a fibre link that both sides report as up, and the network floods without any obvious topology change.

    Narrow it down

    1. Look for a port that has moved from blocking to forwarding with no corresponding topology change.
    2. Check both ends: one side is receiving BPDUs and the other is not.
    3. Inspect the optics and patching for a broken transmit strand.

    Cause

    The link passes traffic one way only. The end that hears nothing ages out its information, decides it should be designated, and starts forwarding — into a loop the other end still believes is blocked.

    Fix

    Enable Loop Guard on the blocking side, or UDLD, so a port that stops receiving BPDUs enters an inconsistent state instead of assuming it may forward.

    IEEE 802.1D-2004 §17.7
  5. The root changes unexpectedly and the whole network reconverges, traced to a desk port.

    Narrow it down

    1. Check the topology change counters with `show spanning-tree vlan <id> detail`.
    2. Identify the port that reported the last topology change.
    3. Look at what is plugged into it.

    Cause

    Someone attached a small unmanaged or cheap managed switch that sent a BPDU with a low bridge ID, and the network believed it.

    Fix

    Enable BPDU Guard on every edge port so a BPDU shuts the port down, and Root Guard on ports facing other switches that must never become root.

  6. Every topology change is followed by a burst of unicast flooding for around fifteen seconds.

    Narrow it down

    1. Correlate the flooding with topology change notifications.
    2. Confirm the Topology Change flag is set in the BPDUs during the burst.
    3. Check the filtering database ageing time in use.

    Cause

    This is by design, not a fault. While the Topology Change flag is set, bridges age the filtering database using the forward delay rather than the normal 300 seconds, so learned addresses disappear and traffic to them is flooded until it is relearned.

    Fix

    Reduce how often topology changes happen: make edge ports edge ports, so a laptop unplugging does not generate one.

    IEEE 802.1D-2004 §17.19

Design notes

Set the root deliberately. Left alone, every switch keeps the default priority of 32768 and the election falls through to the MAC address, which reliably elects the oldest switch in the building — often an access switch at the edge, which then carries traffic it was never sized for.

The default timers assume a network diameter of seven bridges. Message Age increments at each hop and the BPDU is discarded at Max Age, so a network deeper than that loses information before it propagates. Tune diameter rather than the individual timers; vendors expose a diameter knob that derives a consistent set. IEEE 802.1D-2004 §17.14

Classic 802.1D is worth understanding and is not worth deploying. RSTP replaces the timer wait with an explicit handshake and recovers in well under a second; every platform here runs a rapid variant by default. Learn 802.1D because RSTP is defined as a modification of it, and because the failure modes are identical.

Misconceptions

The switch with the lowest MAC address becomes root.
Only when priorities are equal. The bridge identifier is compared as a whole, priority first. The MAC decides so often simply because nobody changed the priority from 32768. IEEE 802.1D-2004 §9.2.5
A blocked port is disabled.
A blocked port still receives and processes BPDUs. That is the entire point: it is listening for the moment it needs to take over. A disabled port hears nothing and can never take over. IEEE 802.1D-2004 §17.7
Setting hello and forward delay on a switch changes how that switch behaves.
Non-root bridges use the timer values carried in the root’s BPDUs, not their own. Configuring timers on a switch that is not root has no effect until it becomes root — which makes the setting look like it worked right up until it matters. IEEE 802.1D-2004 §17.14
A port configured with priority 128 carries 128 in the BPDU.
The 802.1D-2004 port identifier gives priority only four bits and holds it in steps of 16, so 128 encodes as 8. The CLI shows the configured value and the wire shows the encoded one; both are correct. IEEE 802.1D-2004 §9.2.7
Path cost is derived from bandwidth, so it is the same everywhere.
There are two recommended tables. The 16-bit values from 802.1D-1998 make 100 Mb/s cost 19; the 32-bit values from 802.1D-2004 make it 200,000. Many platforms still default to the short table, so two vendors can compute different costs for the same link until one is told otherwise. IEEE 802.1D-2004 §17.14

More walkthroughs

Losing a link to the rootfailure

SW1–SW2 fails. Recovery takes up to fifty seconds, and watching where that number comes from is the argument for RSTP.

Choosing the root, instead of inheriting itdesign-choice

Defaults elect an access switch and drag inter-distribution traffic through it. One priority command fixes it.

Four switches, every priority left at 32768. ACC1 is the oldest device in the building, and manufacturing order gave it the lowest MAC address. DIST1: Bridge ID 32768.00:1a:2b:00:0d:01. DIST2: Bridge ID 32768.00:1a:2b:00:0d:02. ACC1 (2011): Bridge ID 32768.00:0c:29:00:a1:01. ACC2: Bridge ID 32768.00:1a:2b:00:a2:02.

DIST1Bridge ID: 32768.00:1a:2b:00:0d:01DIST2Bridge ID: 32768.00:1a:2b:00:0d:02ACC1 (2011)Lowest MACBridge ID: 32768.00:0c:29:00:a1:01ACC2Bridge ID: 32768.00:1a:2b:00:a2:0210 Gb/s · cost 21 Gb/s · cost 41 Gb/s · cost 41 Gb/s · cost 4
  • Link
  • Blocking
  • Packet in flight
  • Discarded
  • Emphasis
Select a device to read its state. Arrow keys walk the topology.
Text equivalent of this diagram
Devices and links at this step
ElementKindState
DIST1switchBridge ID: 32768.00:1a:2b:00:0d:01
DIST2switchBridge ID: 32768.00:1a:2b:00:0d:02
ACC1 (2011)switchBridge ID: 32768.00:0c:29:00:a1:01
ACC2switchBridge ID: 32768.00:1a:2b:00:a2:02
DIST1DIST2linkup · 10 Gb/s · cost 2
DIST1ACC1 (2011)linkup · 1 Gb/s · cost 4
DIST2ACC2linkup · 1 Gb/s · cost 4
ACC1 (2011)ACC2linkup · 1 Gb/s · cost 4
1 / 6
Before

Four switches, every priority left at 32768. ACC1 is the oldest device in the building, and manufacturing order gave it the lowest MAC address.

What changed

  • DIST1: Bridge ID → 32768.00:1a:2b:00:0d:01
  • DIST2: Bridge ID → 32768.00:1a:2b:00:0d:02
  • ACC1 (2011): Bridge ID → 32768.00:0c:29:00:a1:01
  • ACC2: Bridge ID → 32768.00:1a:2b:00:a2:02
  • Emphasis: Lowest MAC

Terms

Bridge identifier
Eight octets identifying a bridge: a settable 16-bit priority followed by the 48-bit bridge address. Compared as a single number, priority first.
Root bridge
The bridge with the lowest bridge identifier. Every path in the active topology is measured as a cost back to it, and all of its ports are designated.
Root port
The single port on a non-root bridge with the lowest-cost path to the root. Every non-root bridge has exactly one.
Designated port
The one port on each segment that forwards toward the root on that segment’s behalf. Every segment has exactly one.
Path cost
The cost of reaching the root, accumulated on receiving ports. Two recommended tables exist: 16-bit values from 802.1D-1998 and 32-bit values from 802.1D-2004.
BPDU
Bridge protocol data unit. The 35-octet message bridges exchange to agree on the active topology, sent to the Bridge Group Address 01:80:C2:00:00:00.

Check yourself

  • Three switches all have bridge priority 32768. SW1 is 00:1a:2b:00:00:01, SW2 is …:02, SW3 is …:03. Which becomes root?
  • What does a blocked (alternate) port do with a BPDU it receives?
  • You set forward delay to 4 seconds on an access switch that is not the root. What changes?
  • A blocked port must take over after a link failure elsewhere. With default timers, how long before it forwards?
  • A port is configured with priority 128. What value appears in the BPDU?
  • Traffic between two distribution switches is crossing two access switches, even though a direct 10 Gb/s link exists and is up. What is the most likely cause?
  • What does a Topology Change Notification BPDU tell the root?
  • Two switches from different vendors compute different costs for the same 100 Mb/s link. Why?