Flashing lights on the uplinks, switches with CPU maxed out, a floor whose phones are dropping: this is what a layer 2 loop looks like on a campus network. Building redundant links is easy; the hard part is preventing that redundancy from turning into a loop. Below we compare the STP family (802.1D, 802.1w, 802.1s and Cisco’s PVST+/Rapid PVST+ implementations) in terms of convergence and scale, give root bridge placement and edge port protections with Cisco IOS examples, and show the order to proceed in on the console for topology change problems.
Why does a layer 2 loop bring down the network?
An Ethernet frame has no field like the TTL in an IP packet. A broadcast, multicast or unknown-destination unicast frame that enters a loop is flooded again to all ports by every switch and never dies. The impact is seen within seconds:
- Broadcast storm: Uplinks hit capacity, and the switch CPU can’t process control plane traffic; most of the time your SSH session drops too.
- MAC table instability: The same source MAC is constantly learned from different ports. On Cisco, the trace of this is
%SW_MATM-4-MACFLAP_NOTIFlogs. - Duplicated frames: End devices receive the same frame over and over; ARP and DHCP start behaving inconsistently.
Most loops don’t come from design errors. Two cables plugged into a desktop switch brought to a meeting room, an IP phone’s PC port connected back to the wall outlet, a half-finished port channel configuration: these are the triggers you may encounter. That’s why STP stays on even on a network without a redundant topology.
Once a storm starts, even reaching the switch is hard. Prevention is cheaper than intervention.
Comparing STP, RSTP, MSTP and PVST+
Classic 802.1D STP moves between port states using timers: with defaults, Max Age is 20 seconds and Forward Delay is 15 seconds. For an indirect failure, convergence can take 30–50 seconds. 802.1w RSTP, on the other hand, moves a port to forwarding on point-to-point links without waiting for timers, through the proposal/agreement handshake; thanks to the alternate port role, it switches to the backup path immediately when the root port is lost. RSTP was later incorporated into 802.1D-2004, and MSTP into the 802.1Q standard with 802.1Q-2005.
| Protocol | Number of trees | Convergence | Note |
|---|---|---|---|
| 802.1D STP | Single tree (CST) | 30–50 s | Only for compatibility with old devices |
| PVST+ (Cisco) | One per VLAN | 30–50 s | 802.1D logic, per VLAN |
| 802.1w RSTP | Single tree | Usually sub-second to a few seconds | No per-VLAN load sharing |
| Rapid PVST+ (Cisco) | One per VLAN | Same as RSTP | CPU and BPDU load increase as the number of VLANs grows |
| 802.1s MSTP | One per instance | Same as RSTP | Standard, suitable for multi-vendor environments |
The decision is practical. On a campus made up only of Cisco switches carrying dozens of VLANs, Rapid PVST+ is easy to manage. If switches from different vendors are in the same L2 domain, or there are hundreds of VLANs on trunks, move to MSTP. Classic 802.1D and PVST+ don’t go into a new design. Don’t guess which mode is running; check with show spanning-tree summary; the default mode varies by platform and software version.
Root bridge placement and the priority plan
The root is chosen by Bridge ID: the lowest priority wins, and in a tie, the lowest MAC address. Priority is set in multiples of 4096, because the lower 12 bits are reserved for the extended system ID (the VLAN number). Because the default is 32768, if nobody sets a priority during switch installation, the root lands on the device with the lowest MAC. That’s often the oldest access switch on the campus; all traffic then turns around through that weak box.
Pin the root to the center of the L2 domain, that is, the distribution or collapsed core layer. If you use gateway redundancy (HSRP/VRRP), each VLAN’s STP root and active gateway should be on the same device. Otherwise traffic needlessly loops through the link between the two distribution switches.
! DIST-SW1: root for VLANs 10,30,50, backup root for VLANs 20,40,60
spanning-tree mode rapid-pvst
spanning-tree vlan 10,30,50 priority 4096
spanning-tree vlan 20,40,60 priority 8192
! DIST-SW2: the reverse (root for VLANs 20,40,60, backup for VLANs 10,30,50)
spanning-tree mode rapid-pvst
spanning-tree vlan 20,40,60 priority 4096
spanning-tree vlan 10,30,50 priority 8192
The spanning-tree vlan X root primary macro also works; however, it calculates a value relative to the current root and writes a fixed number into the configuration. Writing the value explicitly is more predictable for standard configuration and audit. Someone looking at the configuration six months later sees on the first line what is root and why.
Edge port protections: PortFast and BPDU Guard
Access ports where users, printers, IP phones and cameras connect are marked as edge ports. PortFast does two things: when the port comes up, it skips the listening/learning stages and moves straight to forwarding, and it doesn’t generate a topology change (TC) notification on state changes. Most people don’t know the second effect. On a campus without PortFast, every time a PC turns on or off, MAC tables are aged out quickly and unnecessary flooding occurs.
BPDU Guard complements PortFast: if a BPDU arrives on an edge port, the port goes err-disabled. A switch plugged in by a user can’t join the topology or become a root candidate.
! Global: BPDU Guard on all PortFast ports
spanning-tree portfast bpduguard default
! Equivalent in newer IOS XE versions:
! spanning-tree portfast edge bpduguard default
interface range GigabitEthernet1/0/1 - 44
switchport mode access
switchport access vlan 10
spanning-tree portfast
! Optional automatic recovery (5 minutes)
errdisable recovery cause bpduguard
errdisable recovery interval 300
When are Root Guard and Loop Guard used?
The two are often confused. They protect against different failures and can’t be used together on the same port.
Root Guard
It’s applied to the distribution switch’s designated ports facing the access layer. If a better (superior) BPDU than the current root arrives on this port, the port is placed in the root-inconsistent state and carries no traffic until the superior BPDU stops. The aim is to prevent a low-priority device added to the access layer from stealing the root role. If you apply Root Guard to an uplink that should be a root port, you break the normal topology with your own hands.
Loop Guard
It’s applied to ports that are expected to receive BPDUs, i.e. root and alternate ports. In a unidirectional fiber failure, no BPDUs arrive from the other side; an unprotected alternate port interprets this as “the path is clear,” moves to designated and a loop forms. Loop Guard keeps the port in the loop-inconsistent state in this case. It’s commonly used together with UDLD (Cisco) on fiber uplinks.
Unidirectional fiber isn’t rare. A dirty connector is enough.
! DIST-SW1: ports facing access switches
interface range TenGigabitEthernet1/1/1 - 8
spanning-tree guard root
! ACCESS-SW: uplinks to distribution (root/alternate ports)
spanning-tree loopguard default
! or per port:
interface TenGigabitEthernet1/1/1
spanning-tree guard loop
MSTP region and instance design
In MSTP, switches share the same trees within a region. For two switches to be counted in the same region, three parameters must be exactly the same: the region name, the revision number and the VLAN–instance mapping. A single VLAN difference drops a switch into a separate region. Only IST (instance 0) information is carried across the region boundary, and the load sharing you planned doesn’t work.
Things to watch in the design:
- Keep the number of instances to the number of paths that really need a different topology. On a campus with two distribution switches, two instances are usually enough: one with DIST-SW1 as root, the other with DIST-SW2.
- Map VLANs that haven’t been created yet to an instance from the start as well. If the mapping changes later, you have to change it on all switches at the same time, and the region splits during the transition.
- Also explicitly set the root of instance 0 (IST); VLANs mapped to instance 0 and communication outside the region run over it.
- The standard allows up to 64 MSTIs to be defined in a region; the number of instances platforms support and the range of usable instance numbers vary by model and software version. In a multi-vendor region, take the limit of the most restricted device as the basis and verify it in the platform’s configuration guide.
spanning-tree mode mst
spanning-tree mst configuration
name CAMPUS-A
revision 3
instance 1 vlan 10,30,50,100-199
instance 2 vlan 20,40,60,200-299
!
spanning-tree mst 0 priority 4096
spanning-tree mst 1 priority 4096
spanning-tree mst 2 priority 8192
show spanning-tree mst configuration digest
The digest value in the show spanning-tree mst configuration digest output must be the same on all switches in the region. In a multi-vendor environment, this is the first value to compare. If the digest is different, the region is different too.
Diagnosing topology changes
When a “the network freezes every few seconds” complaint comes in, one of the first suspects is constantly repeating topology changes. Each TC causes the MAC table to be flushed and brief flooding. To find the source, watch the TC counter and the port the last change came from, and follow the chain toward the root. The order to check on the console:
show spanning-tree summary
show spanning-tree root
show spanning-tree detail | include ieee|occurr|from|is exec
show spanning-tree inconsistentports
show interfaces status err-disabled
show errdisable recovery
show logging | include SPANTREE|MACFLAP
The “Number of topology changes … last change occurred … ago from GigabitEthernet1/0/14” line in the show spanning-tree detail output tells you which port the change came from. Move to the switch connected to that port and repeat the same command. At the end of the chain there’s usually an end device port without PortFast that keeps going up and down, or a physically faulty uplink.
Mistakes you may encounter:
- The root not being planned and landing on an access switch.
- Constant TCs being generated because edge ports lack PortFast.
- The VLAN mapping being different on a single switch in the MSTP region.
- Root Guard being applied to the uplink root port.
- A port shut down by BPDU Guard being reopened without finding the cause.
- Not testing how the boundary between Rapid PVST+ and MSTP behaves in a multi-vendor environment.
Loop prevention can’t be considered separately from the segment plan. For VLAN structure, see the VLAN design in enterprise networks guide; for approaches that reduce dependence on STP, the switch stack, MLAG and vPC comparison; and for combining uplinks into a port channel, the LACP and EtherChannel configuration article. Root placement and the size of the L2 domain depend on the layer architecture; the three-tier and collapsed core comparison covers this decision. The normative definition of MSTP and RSTP behavior is in the IEEE 802.1Q standard; the working group’s page is at IEEE 802.1.
If you want root placement, guard features and MSTP region consistency on your existing campus audited, our VLAN, routing and network segmentation service covers this check.
Frequently asked questions
How should I choose between Rapid PVST+ and MSTP?
On a single-vendor campus with a reasonable number of VLANs that wants separate topology control for each VLAN, Rapid PVST+ is simpler to manage. In a multi-vendor environment, or if hundreds of VLANs are carried on trunks, MSTP is the right choice: it’s a standard and groups VLANs into a small number of instances.
Should I change the priority value on access switches?
No need; leave the default 32768. The real job is to explicitly set a low priority on the core or distribution switches and prevent the root from landing on an access switch by chance.
BPDU Guard shut down a port; what should I do?
First find the device connected to the port; most often it’s a small switch brought to a desk or a miswired device. Don’t open the port before the cause is removed. The port is reopened with shutdown and no shutdown, or when the errdisable recovery timer expires.
Is it possible to turn off STP completely?
Technically possible, not recommended. Even if all uplinks run active-active with stacking, MLAG or vPC, STP should stay on as a safety net. A wrong cable or a misconfigured port channel can create a loop on its own; storm control limits the impact of a storm, but the basic mechanism that breaks the loop by itself is STP.