Module 4.5 55 minIntermediate

Spanning-Tree Protocol (STP & RSTP)

STP prevents L2 loops by electing a Root Bridge and blocking redundant links. This chapter covers the BPDU exchange, port roles and states, the Bridge ID, and Rapid Spanning-Tree improvements.

Course plan — preview

What you'll learn

  • Explain why L2 loops are catastrophic and how STP prevents them.
  • Identify the Root Bridge from a set of Bridge IDs.
  • Compare STP, PVST+, RPVST+, and MST.
  • Use PortFast and BPDU Guard correctly on access ports.

Why a loop is fatal at L2

Ethernet frames have no TTL. Send a single broadcast into a network with a loop, and switches flood it forever — multiplied each time it crosses a switch. Within seconds, every link saturates with copies of the same frame, the network collapses, and no useful traffic gets through. STP exists to make redundant L2 paths safe.

A loop does three kinds of damage at once. Broadcasts multiply into a storm. The MAC address table never settles, because the same source address keeps arriving on different ports. And a host receives the same unicast frame more than once. Spanning tree fixes all three the same way: every cable stays plugged in, but just enough ports are logically blocked that exactly one path remains between any two switches. When a forwarding link fails, a blocked port takes over.

Root Bridge election

Every switch has a Bridge ID = priority (default 32768) + base MAC. The switch with the lowest Bridge ID becomes the Root Bridge. All other switches calculate their shortest path (root cost) to the root, then block any port that would create a redundant path.

In per-VLAN spanning tree the 16-bit priority field is split: a 4-bit configurable priority and a 12-bit sys-id-ext that carries the VLAN ID. You can only set the priority in multiples of 4096 (0, 4096, 8192 … 61440) — a value such as 20500 is rejected — and show spanning-tree prints configured priority + VLAN ID.

So spanning-tree vlan 30 priority 4096 is displayed as 4126, and the default for VLAN 10 is 32768 + 10 = 32778. To take over as root, set a priority at least one 4096 step below the current root's; matching it only ties, and the tie is then decided by the lower MAC. The priority keyword is per-VLAN: spanning-tree vlan <id> priority <value>.

Every port also has a cost, set by its speed (the table below). Switches add these costs up to measure how far each one is from the root. The lab, like most textbooks, uses the short 802.1D values: 19 for Fast Ethernet, 4 for Gigabit.

SpeedCost (legacy 802.1D)Cost (long 802.1t)
10 Mbps1002,000,000
100 Mbps19200,000
1 Gbps420,000
10 Gbps22,000
100 Gbps—200

11 more sections in this chapter, plus a 4-question quiz and a hands-on lab.

Course plan

Modules 2–8 are part of the Course & Lab Pass and All-Access Max — start with a free account

You can see the title, summary, learning objectives and the opening sections. The rest of this chapter, like all of modules 2–8, comes with the Course & Lab Pass and All-Access Max. A free account opens Module 1: How Networks Work end-to-end and saves your labs — start there, no card required.

  • Read every chapter in Module 1 — How Networks Work
  • Save labs of up to 5 devices
  • Save up to 3 topologies
  • See the full course syllabus + chapter titles

Free account · no card required · compare plans any time

Build it step by step