What Is STP (Spanning Tree Protocol)?

Also called: Spanning tree

Related problems: Someone plugged a cable into the wrong port and the whole office network went down; The network freezes for a while whenever a switch link fails; Want redundant switch links without causing network loops

Spanning Tree Protocol (STP) is a protocol that Ethernet switches use to prevent loops in a local area network that has redundant links. Redundant paths between switches are useful for resilience, but at Layer 2 they can cause traffic to circle endlessly. STP has the switches agree on a single loop-free set of active paths and puts the extra links into a blocking state, ready to take over if an active link fails. Originally standardized by the IEEE, it now usually runs in its faster successors, Rapid Spanning Tree (RSTP) and Multiple Spanning Tree (MSTP).

Not to be confused with shielded twisted pair (STP), a type of network cabling.

At a glance

  • STP stops Layer 2 loops on networks of interconnected switches by blocking redundant links.
  • If an active link fails, a blocked link can take over, so redundancy is kept without loops.
  • The original version could take 30 seconds or more to recover; RSTP usually recovers in a few seconds or less.
  • Misconfigured spanning tree is a common cause of office-wide outages, so its settings matter.
  • It works within a LAN; routing protocols such as OSPF handle paths between networks.

What problem it solves

Ethernet switches forward broadcast traffic out of every other port in the same VLAN, and Ethernet frames have no built-in limit on how many times they can be forwarded. If two switches are connected by two cables, or if switches are cabled in a ring, a broadcast can loop around indefinitely, copying itself each time. Within seconds the loop can consume all available bandwidth and switch processing, and the whole network segment stops working. This is a broadcast storm, and it is a classic cause of sudden, total office outages.

Network designers still want redundant links between switches so that one failed cable or switch does not cut off a floor. STP lets them have both: redundant cabling, and only one active path at a time. It also protects against accidental loops, such as a user plugging both ends of a cable into wall ports or connecting a small unmanaged switch in a way that creates a loop.

How it works

Electing a root. The switches exchange messages and elect one as the root bridge, based on a configurable priority and their hardware addresses. Choosing the root deliberately, usually a core switch, matters because it shapes every path.

Choosing paths. Each switch works out its lowest-cost path to the root, based on link speeds. Ports on those paths forward traffic; ports that would create a loop are put into a blocking state and drop ordinary traffic.

Reacting to change. If an active link or switch fails, the switches recalculate and unblock a backup port. The original STP waited through listening and learning stages, often 30 to 50 seconds. RSTP negotiates directly between neighbors and typically recovers much faster.

VLANs. With many VLANs, some vendors run a separate spanning tree per VLAN, and MSTP maps groups of VLANs to a few trees. Both allow different VLANs to use different links.

Protective features. Switches add features such as edge-port settings for user ports, guards that shut a port if it unexpectedly receives spanning tree messages, and root guards that stop an unauthorized switch from taking over as root.

For LAN design and refresh, see our Wired and Wireless LAN Infrastructure solution page.

When it matters for buyers

  • Switch refreshes. Mixing vendors or versions can lead to spanning tree interoperability issues; plan and test the design.
  • After an unexplained outage. A loop or a spanning tree change is a common cause of brief, office-wide network failures.
  • Building in redundancy. Second uplinks between closets and the core add redundancy only if spanning tree, link aggregation or a similar method manages them.
  • Managed LAN services. Ask who owns spanning tree design and monitoring, since the setting is easy to overlook.

Questions to ask vendors

  • Which spanning tree version will run on our switches, and how is the root bridge chosen?
  • How are user-facing ports protected against loops and rogue switches?
  • How quickly does the design recover from a failed uplink, and has that been tested?
  • Will you use link aggregation or switch stacking to reduce how much the network depends on spanning tree?
  • How will spanning tree changes and events be monitored and alerted on?
  • How will this interoperate with our existing switches during a phased refresh?

How it differs from OSPF

STP and Open Shortest Path First (OSPF) both manage redundant paths, but at different layers. STP works at Layer 2, among switches within one LAN, and handles loops by blocking redundant links so that only one path is active. OSPF is a Layer 3 routing protocol that runs between routers and calculates the best paths between networks, and it can use several equal paths at once. Many networks use both: spanning tree inside each LAN segment, and a routing protocol between segments and sites.

Frequently Asked Questions

What is a network loop?
A loop happens when there are two or more Layer 2 paths between the same switches, for example two cables between them, without anything to stop traffic circling. Broadcast traffic then multiplies until it can overwhelm the switches, a failure often called a broadcast storm.
What are RSTP and MSTP?
They are newer versions of spanning tree. Rapid Spanning Tree Protocol (RSTP) recovers from link failures much faster than the original. Multiple Spanning Tree Protocol (MSTP) lets different groups of VLANs use different paths. Many modern networks run one of these rather than the original STP.
Should spanning tree ever be turned off?
Generally not on switch ports where a loop could occur, which in practice includes ports users can plug things into. Some designs use other loop-prevention methods, such as switch stacking or link aggregation across two switches, but spanning tree is commonly left on as a safety net.
Why does a port take a while to start working when I plug a device in?
On a port running the original STP, the switch listens and learns before forwarding, which can take around 30 seconds. Configuring user ports as edge ports, often called PortFast, lets them forward straight away.

You Don’t Need Another Sales Call. You Need an Answer.

30 minutes. No pitch. Just an honest conversation about where you are, what you need, and whether working together makes sense.

We use your details to set up and prepare for the call, and send the newsletter only if you ask for it. Privacy policy.