How spanning tree protocol works
Spanning Tree Protocol (STP) is a Layer 2 protocol that lets Ethernet switches be wired with redundant links without creating a loop. It was invented by Radia Perlman at Digital Equipment Corporation in 1985 and standardized by the IEEE as 802.1D. Each switch running STP exchanges small control frames called BPDUs, and together the switches agree on a single loop-free tree of active links. Every link that would close a loop is blocked, but stays cabled and ready.
A loop matters because Ethernet frames have no time-to-live field. A router drops an IP packet after a set number of hops, but a switch forwards a broadcast frame out of every port, and on a loop the copies come back and are forwarded again. Within seconds the copies multiply into a broadcast storm, switch MAC tables change constantly as the same address appears on different ports, and hosts receive duplicate frames. A single extra patch lead can stop a whole network.
STP solves this by turning a meshed physical network into a logical tree. If an active link or switch fails, the switches notice that BPDUs have stopped arriving, recalculate the tree and unblock a backup path, so the redundancy is still there when it is needed.
How STP builds a loop-free tree
Every switch runs the same algorithm, so they all reach the same answer without a central controller. It happens in four steps.
-
//
Elect a root bridge. Each switch has a bridge ID made of a priority value (32768 by default, set in steps of 4096) and its MAC address. The switch with the lowest bridge ID becomes the root, the reference point for the whole tree.
-
//
Choose a root port on every other switch. Each non-root switch picks the one port with the lowest total path cost back to the root. Path cost follows link speed: under the original 802.1D values a 100 Mb/s link costs 19, 1 Gb/s costs 4 and 10 Gb/s costs 2.
-
//
Choose a designated port on every segment. On each link, the switch with the cheaper path to the root forwards traffic for that segment through its designated port.
-
//
Block the rest. Any port that is neither a root port nor a designated port stops forwarding user traffic but keeps listening to BPDUs, so it can take over if the topology changes.
STP port states and timers
Classic STP moves a port through a sequence of states before it forwards traffic. The waiting is deliberate: it gives BPDUs time to spread across the network so no switch starts forwarding into a loop that has not yet been detected.
| Port state | Forwards user frames | Learns MAC addresses | Processes BPDUs | Typical time in state |
|---|---|---|---|---|
| Blocking | No | No | Yes, receives only | Up to 20 s (max age) |
| Listening | No | No | Yes | 15 s (forward delay) |
| Learning | No | Yes | Yes | 15 s (forward delay) |
| Forwarding | Yes | Yes | Yes | Until the topology changes |
| Disabled | No | No | No | Administratively shut down |
With the default timers, a 2 s hello time, a 20 s max age and a 15 s forward delay, a blocked port takes around 30 to 50 seconds to start forwarding after a failure. That was acceptable for office LANs in the 1990s. It is the main reason faster versions were developed, and why classic STP is rarely the right choice on a control network today.
Types of spanning tree protocol
“Spanning tree” now covers a family of protocols. Most managed switches support several, and they interoperate to a degree, but a network works best when one version is chosen deliberately.
-
//
STP (IEEE 802.1D). The original protocol, with one tree for the whole network and slow, timer-driven recovery.
-
//
RSTP (IEEE 802.1w). Rapid Spanning Tree replaced the timers with a handshake between neighboring switches, cutting recovery to around a second or less on point-to-point links. It superseded STP in 802.1D-2004 and is now specified in IEEE 802.1Q.
-
//
MSTP (IEEE 802.1s). Multiple Spanning Tree runs several trees, each serving a group of VLANs, so different VLANs can use different links. It is also part of IEEE 802.1Q.
-
//
PVST+ and Rapid PVST+. Cisco’s per-VLAN versions, which run one tree per VLAN. They are common in enterprise networks but proprietary.
-
//
Ring protocols. ITU-T G.8032 ERPS and IEC 62439-2 MRP are not spanning tree, but they solve the same loop problem on ring layouts and recover in tens of milliseconds.
How MSTP (IEEE 802.1s) works
Multiple Spanning Tree Protocol, first published as IEEE 802.1s and now part of IEEE 802.1Q, keeps the rapid convergence of RSTP but stops a blocked link from sitting idle for every VLAN. Instead of one tree for the whole network, it runs several spanning tree instances and maps each VLAN to one of them. Camera VLANs can then forward over one uplink while control VLANs use the other, and each link takes over the other’s traffic if it fails.
MSTP suits networks with redundant links and several VLANs, where an idle uplink is wasted capacity. On a simple ring, or a machine network with one VLAN, it adds configuration without much benefit, and RSTP or a ring protocol is easier to run. Plan the VLAN-to-instance map before deployment and apply it to every switch at once, because a switch with a different map leaves the region.
The protocol is built from four ideas:
-
//
MST regions. Switches with the same region name, revision number and VLAN-to-instance map form a region. A difference in any of the three, even one VLAN mapped differently, splits the region in two.
-
//
Instances. Inside a region, instance 0, the internal spanning tree (IST), carries the control traffic, and up to 64 further MST instances (MSTIs) each have their own root bridge, port roles and blocked links.
-
//
The common spanning tree. Between regions, and towards switches running STP or RSTP, a whole region behaves like one large bridge in the common and internal spanning tree (CIST), so MSTP works alongside older switches.
-
//
One BPDU for every instance. MSTP sends a single BPDU that carries the information for all its instances, so adding instances adds little control traffic, unlike per-VLAN protocols that send one BPDU per VLAN.
Spanning tree in industrial networks
Plant networks use redundancy for the same reason offices do, but the stakes are different. A PLC that loses contact with its remote I/O for longer than its watchdog time faults the process, so a recovery measured in tens of seconds is a stoppage. That is why industrial designs normally run RSTP or a ring protocol instead of classic STP, and keep spanning tree for meshed links and for connecting to IT networks.
Spanning tree only works on switches that run it. Most unmanaged switches do not take part, so a loop cabled through them can still cause a storm. Most of our managed industrial switches list STP, RSTP and MSTP alongside ITU-T G.8032 ERPS, which recovers a ring in under 50 ms. Our explainer on what a managed switch adds covers the other settings that come with them, and the white paper on managed vs unmanaged industrial Ethernet switches explains where each type fits on a plant network.
A few habits make spanning tree predictable on any site:
-
//
Choose the root bridge. Set a low priority on the core or distribution switch. Left at defaults, the oldest switch with the lowest MAC address can become the root.
-
//
Mark device ports as edge ports. Ports facing PLCs, HMIs and cameras should start forwarding immediately, often called PortFast. Add BPDU guard so a loop plugged into a device port shuts that port down.
-
//
Keep the tree small. Plan for no more than about seven switches between any two devices, and split large plants into VLANs or routed cells.
-
//
Use one protocol per domain. Mixing STP, RSTP, MSTP and a vendor ring without a plan is a common cause of slow recovery and blocked links in the wrong place.
Quick answers on spanning tree
Spanning tree protocol: common questions
What does STP stand for in networking?
Spanning Tree Protocol. In chemistry STP means standard temperature and pressure, but in networking it is the IEEE 802.1D loop-prevention protocol run by Ethernet switches.
Is spanning tree protocol still used?
Yes, mostly in its rapid form. Almost every managed switch runs RSTP or MSTP by default. Classic 802.1D STP survives mainly for compatibility with older switches.
What is a root bridge?
The reference switch for the tree. It has the lowest bridge ID, all of its ports forward, and every other switch measures its path cost back to it.
Do unmanaged switches use spanning tree?
Usually not. Most unmanaged switches simply forward BPDUs or ignore them, so they cannot block a loop. Redundant links need managed switches at both ends.
Is spanning tree protocol the same as a minimum spanning tree?
Related, but not the same. A minimum spanning tree is a graph-theory problem: connect every node at the lowest total cost. STP builds a shortest-path tree from one root bridge, which is not always the minimum spanning tree.
What is the difference between RSTP and MSTP?
The number of trees. RSTP builds one loop-free tree for all VLANs. MSTP uses the same rapid mechanism but runs several trees, each serving a group of VLANs, so different VLANs can use different links.
We supply managed industrial switches as part of the system, and as standard we set the root bridge, redundancy protocol and edge ports to match your network drawing before it ships.