Blog • SHM Soft

Spanning Tree Protocol (STP): How It Works and Troubleshooting

Spanning Tree Protocol is the quiet protocol that stops your office network from collapsing. It runs on almost every switch, and when it goes wrong, the symptoms are dramatic: total outages, slow starts, and ports that never come up. This guide explains how STP works and how to troubleshoot it.

Published 28 November 2026 • SHM Soft

If you plug two switches together with two cables, you might expect the network to get faster. Instead, it can collapse completely. Broadcasts loop around forever, the switches fill up, and nothing gets through. This is a Layer 2 loop, and it is one of the fastest ways to take a network down. The Spanning Tree Protocol, or STP, exists to stop it from happening.

STP is a protocol that runs on switches and blocks the extra paths that would create loops, while keeping them ready as backups. It works automatically, and most of the time you never notice it. But when it is misconfigured or misbehaving, it causes some of the most confusing network problems there are. This guide explains how STP works, what goes wrong, and how to fix it, in plain words with the commands you need.

Network cables connected to a switch for spanning tree protocol

What Is Spanning Tree Protocol, and Why Do We Need It?

Networks need redundancy. If one cable fails, another should take over, so work does not stop. But redundancy creates a problem at Layer 2. Unlike IP packets, Ethernet frames have no time-to-live field, so a frame that loops will circle forever. A single broadcast frame can be copied again and again until the network is flooded. This is called a broadcast storm, and it can bring a whole office network down in seconds. Switches also get confused by loops: they see the same device on several ports at once, and their address tables keep changing, so frames go to the wrong place.

STP solves this by creating a loop-free path through the network. It works out which links to use and which to block, so there is exactly one active path between any two points. The blocked links are not dead: they are backups. If an active link fails, STP unblocks a backup and traffic flows again. You get redundancy without loops, which is exactly what a reliable network needs. That is why STP runs by default on switches from every vendor, and why it is essential knowledge for anyone who manages a network.

Root bridge, BPDUs, and port roles

STP works by electing a root bridge, which is the central switch that all other switches measure their distance from. The election uses the Bridge ID, which is made up of a priority number and the switch's MAC address. The switch with the lowest Bridge ID becomes the root. By default, every switch has a priority of 32768, so the one with the lowest MAC address wins, which is rarely the switch you would choose. That is why the first thing a network engineer does is set the priority by hand, so the right switch becomes the root.

Switches talk to each other using messages called BPDUs, or Bridge Protocol Data Units. The root bridge sends a Hello BPDU out of every port every 2 seconds, and other switches forward it on. These messages carry what switches need to work out the topology: who the root is, how far away it is, and which ports should forward and which should block. Root ports lead towards the root bridge, designated ports lead away from it, and non-designated ports are the ones blocked to prevent a loop.

Ports also move through states: blocked, listening, learning, and forwarding. In classic STP, moving from blocked to forwarding takes about 30 to 50 seconds, because each transition state lasts 15 seconds by default. That is why a computer plugged into a switch can take a while to connect. Rapid STP, or RSTP, was created to fix this: it converges in seconds, and it is the version most networks use today.

Common STP Problems and Their Symptoms

The most dramatic STP problem is a loop that STP failed to prevent. The symptoms are unmistakable: the whole network slows to a crawl or stops, switch lights blink frantically, and the CPU usage on switches shoots up. This usually happens when STP is turned off on a switch, when a switch is connected that does not run STP, or when a misconfigured port lets BPDUs through that should be blocked. If your network suddenly collapses after someone plugs in a new switch or a cable, suspect a loop first.

The second common problem is a wrong root bridge. If the switch with the lowest priority is a small, slow switch in a cupboard instead of your main core switch, all traffic takes a long, slow path through it. The network works, but it is slow, and nobody knows why. The fix is to set the root priority properly: make your main switch the root with a low priority, and your backup switch the secondary root. On Cisco switches, the command is spanning-tree vlan 1 root primary for the root and spanning-tree vlan 1 root secondary for the backup.

The third problem is slow convergence. When a link fails, classic STP can take 30 to 50 seconds to unblock a backup path, and during that time, traffic stops. Rapid STP fixes this by converging in a few seconds. If your network still runs classic STP, switching to Rapid STP is an easy improvement. The command on Cisco switches is spanning-tree mode rapid-pvst. Our guide on how to configure a Cisco router covers the Cisco command line basics you need for these commands.

An Ethernet switch with ports used in spanning tree protocol troubleshooting

Troubleshooting STP Step by Step

Start by finding the root bridge. On a Cisco switch, run show spanning-tree and look for the root ID and the bridge ID. If they match, this switch is the root. If they do not match, the output tells you which switch is the root and which port leads to it. Check every switch in the network and confirm that the root is the switch you expect. If it is not, set the priority properly. Also check that all switches agree on the root. If two switches each think they are the root, BPDUs are not getting through, and there is a link or VLAN problem between them.

Next, check the port states. Run show spanning-tree vlan 1 or the VLAN you are investigating, and look at the role and state of each port. A port that should be forwarding but is stuck in blocking may be connected to a switch with a better path, or it may be receiving BPDUs from an unexpected device. A port that flaps between states may have a bad cable or a duplex mismatch. Check the port's error counters with show interfaces and look for errors or collisions, which point to a physical problem rather than an STP one.

Check the topology change count too. A high count means the network keeps reconverging, usually because a link is flapping. Find that port and fix it. Also check BPDU guard, which shuts down a port if it receives a BPDU. If a port is shut down, check whether someone plugged a switch into a port meant for a computer.

If you see a loop, find it fast. Look for the switch with the highest CPU usage and the most blinking lights, and check which ports are flooding. Disconnect the most recently added cable or switch, and see if the network recovers. Then reconnect things one at a time until the problem returns. That is the fastest way to find the faulty link. For a deeper look, capture traffic on a switch port and look for the same broadcast frame appearing again and again, which confirms a loop. Our guide to network troubleshooting commands explains the diagnostic approach that works for STP problems too.

Best Practices: PortFast, BPDU Guard, and Root Guard

Three features make STP safer and faster, and you should use all of them. PortFast lets a port go straight to forwarding when a device connects, skipping the 30-second listening and learning delay. Use it only on ports connected to end devices like computers and printers, never on ports connected to other switches, because skipping the checks on a switch port can create a loop. The command is spanning-tree portfast on the interface, or spanning-tree portfast default to enable it on all access ports at once.

BPDU guard works with PortFast. It shuts down a PortFast port if it ever receives a BPDU, which means someone plugged a switch into a port meant for a computer. This stops a new switch from creating a loop by accident. Enable it with spanning-tree bpduguard enable on the interface, or spanning-tree portfast bpduguard default globally. When BPDU guard triggers, the port goes into an error-disabled state, and you need to fix the cause and re-enable it with a shutdown and no shutdown.

Root guard protects your root bridge. It is set on ports that should never become the root, and if a switch on the other end tries to claim to be the root, the port is blocked. This stops a small switch plugged in by mistake from taking over as root and slowing the whole network. Use it on ports that face away from the core, especially in areas where people can plug things in. Together, PortFast, BPDU guard, and root guard turn STP from a protocol that can cause problems into one that prevents them. If your office network has STP trouble that keeps coming back, it is worth a proper review. Our managed IT services team can check your switches, fix the configuration, and document it properly.

Watch on YouTube: Free CCNA | Spanning Tree Protocol (Part 1) | Day 20 | CCNA 200-301 Complete Course

STP is quiet until it breaks — then it is loud

Spanning Tree Protocol does its job silently on almost every network, and most of the time you will never think about it. But when it goes wrong, the whole network can go down in seconds. Knowing how it works, setting the root bridge properly, and using PortFast, BPDU guard, and root guard will prevent most of the problems. And when a problem does appear, show spanning-tree will tell you where to look.

Frequently Asked Questions

What is spanning tree protocol in simple terms?

STP is a protocol that stops network loops by blocking extra paths between switches, while keeping those paths ready as backups if a link fails.

What is a root bridge in STP?

The root bridge is the central switch that all other switches measure their distance from. It is elected by the lowest Bridge ID, but you should set it by hand so your main switch wins.

Why does STP take 30 seconds to connect?

In classic STP, a port moves through listening and learning states that each last 15 seconds before forwarding. PortFast skips this delay for end devices, and Rapid STP converges in seconds.

What is a broadcast storm?

It is a flood of broadcast frames looping forever around a network, using up all the bandwidth and switch CPU until the network stops working. STP prevents it by blocking looped paths.

What does BPDU guard do?

BPDU guard shuts down a port if it receives a BPDU, which should never happen on a port meant for a computer. It stops someone accidentally creating a loop by plugging in a switch.

Conclusion

Spanning Tree Protocol prevents Layer 2 loops by electing a root bridge and blocking redundant paths, keeping them as backups. Most STP problems come from a wrong root bridge, slow convergence, or a missing guard feature. Set the root properly, use Rapid STP, and enable PortFast, BPDU guard, and root guard.

If your office network has STP trouble or unexplained outages, contact us for a free quote. We will check your switches, fix the configuration, and make sure it stays fixed.

Related articles:

How to Configure a Cisco Router: A Beginner's Guide

The Cisco command line basics you need for STP commands.

Network Troubleshooting Commands: The Complete Guide for IT Professionals

The diagnostic approach that finds STP problems fast.

What Is Network Monitoring and Why Your Business Needs It

Monitoring catches STP topology changes before users notice them.

Want help with your network or IT?

Tell us what you need and we will send a free quote with no hidden charges.

Get a Free Quote