What Does Spanning Tree Do?

Follow the protocol from topology discovery to automatic recovery—and watch a redundant physical network become a logical loop-free topology.

Spanning Tree ProtocolLayer 2SwitchingCCNA
What Does Spanning Tree Do? cheat sheet: use this quick map before reading the detailed sections.

What Spanning Tree does

In our previous lesson, we saw why redundant LAN topologies require Spanning Tree to work. Now we are going to answer the question: What does STP do?

The short answer: Spanning Tree prevents loops by breaking the redundant physical topology into a logical loop-free one. Now let us look at this in more detail.
Spanning Tree Protocol lesson diagram showing switches, BPDU messages and loop-free forwarding paths
Spanning Tree keeps redundant physical links while selecting a loop-free forwarding topology.

Creating a logical topology

High availability is paramount in networking, so we want redundancy at every appropriate layer. Let us begin with the simplest LAN topology: two interconnected Ethernet switches.

If clients are connected to SW1 and other clients are connected to SW2, we want a redundant connection between the switches. Otherwise, if their only link fails, the clients on SW1 lose connectivity to the clients on SW2.

Looped topology with two Ethernet switches
Ethernet linkMoving frame
Figure 1. Looped topology with two Ethernet switches.

What happens when we introduce a second link between SW1 and SW2? We create a Layer 2 loop. Ethernet does not work safely in a looped topology: frames can circulate endlessly, causing a broadcast storm, duplicate Ethernet frames, MAC address flapping, CAM table instability, network congestion, and eventually Layer 2 network failure.

Forwarding and blocking states

When Spanning Tree is enabled on a switch—it is enabled by default on Cisco switches—it controls the state of every participating switch port. For this lesson, the two essential behaviors are forwarding and blocking.

Forwarding state

  • Sends and receives Ethernet frames
  • Learns source MAC addresses
  • Acts as a normal active switch interface
  • Shown in green in the figures

Blocking state

  • Does not forward ordinary data frames
  • Does not learn source MAC addresses
  • Still processes Spanning Tree BPDU messages
  • Shown in orange in the figures

This frame-forwarding control is the basis of STP loop prevention. Spanning Tree blocks a redundant port logically; it does not unplug or disable the physical cable. The redundant link remains available as an alternate network path.

Redundant LAN with Spanning Tree

Using this logic, Spanning Tree breaks the looped physical topology into a loop-free logical topology. In Figure 2, three interconnected switches form a triangle. STP detects the redundant network paths through BPDU exchange across the links.

After comparing BPDU information, STP creates one active tree. The green ports forward frames, while the orange port blocks ordinary traffic. The logical view on the right has no switching loop even though all physical links remain connected.

Physical redundancy → logical tree
ForwardingBlockingBPDU
Figure 2. Redundant LAN with Spanning Tree.

STP in larger redundant topologies

The same logic applies to larger switched Ethernet networks with many redundant links. Figure 3 contains several possible Layer 2 loops. The STP protocol must block multiple redundant ports to produce the loop-free network shown on the right.

Multiple loops, one active topology
ForwardingBlocked portBPDU
Figure 3. Redundant LAN with Spanning Tree—example 2.

Figure 4 increases the number of switches and links again. Notice how many ports must enter a blocking state before only one active path remains between any two points in the Layer 2 network.

Scaling the same loop-prevention logic
ForwardingBlocked portBPDU
Figure 4. Redundant LAN with Spanning Tree—example 3.
Important: Spanning Tree controls the topology by placing individual ports into a blocking state—not by physically removing entire links.

What does Spanning Tree Protocol do behind the scenes?

At a high level, the spanning tree algorithm follows this chain. The detailed election rules belong in the next lesson.

Exchange BPDUs→Elect a root bridge→Calculate path cost→Select root and designated ports→Block redundant ports→Create a loop-free topology

The root bridge election, STP path cost, root port selection, designated port selection, and blocked port decision determine the active Layer 2 tree. This is how STP prevents broadcast storms, duplicate frames, endless frame circulation, and MAC flapping while preserving network redundancy.

Traditional IEEE 802.1D STP transitions ports through blocking, listening, learning, and forwarding behavior. Rapid Spanning Tree Protocol (RSTP), MSTP, PVST+, and Rapid PVST+ use related terminology and faster or more scalable mechanisms, but they share the same fundamental purpose: Ethernet loop prevention with resilient redundant paths.

Summary

Spanning Tree prevents loops by breaking the redundant physical topology into a logical loop-free one. At the same time, it tracks the status of all inter-switch links.

If an active link fails, STP detects the topology change, recalculates the tree, updates or relearns affected MAC address table entries, and activates a suitable backup path. This topology reconvergence provides automatic Layer 2 failover while maintaining loop prevention.

Prevent Layer 2 loops

Stop broadcast storms, duplicate frames, and MAC table instability.

Preserve redundancy

Keep redundant switch links available as backup paths.

Recover automatically

Reconverge and activate an alternate path after failure.

Continue with the next lesson: Spanning Tree Port States explains blocking, listening, learning and forwarding behavior, including classic STP timers and Cisco verification commands.

What Does Spanning Tree Do? Frequently Asked Questions

What does Spanning Tree do in networking?

Spanning Tree Protocol creates a loop-free Layer 2 topology by blocking selected redundant forwarding paths while keeping them available for failover.

How does STP prevent loops?

Switches exchange BPDUs, elect a root bridge, calculate the best paths, assign port roles, and place redundant ports in a blocking state so frames cannot circulate around a loop.

Why does STP block ports?

STP blocks ports to ensure there is only one active logical path through each part of the switched network. This prevents broadcast storms, duplicate frames, and MAC address flapping.

Does STP disable redundant links?

No. STP logically blocks a port from forwarding ordinary frames. The physical redundant link remains connected and can become active after a topology change.

What happens when an STP link fails?

STP detects the link failure, performs topology recalculation and reconvergence, and can activate a previously blocked backup network path.

Continue the STP learning chain