Preventing Loops with Spanning Tree

Ch. 5 of 616 mins3 Tasks

Understand the dangers of physical switching loops, the Bridge Protocol Data Unit (BPDU) election process, and how STP dynamically blocks redundant links to prevent broadcast storms.

Track Series

Chapters in this Track (Ch. 5 of 6)

5Preventing Loops with Spanning Tree
16m

In modern office networks, internet downtime means people cannot work. If a critical network switch fails or someone trips over a fiber cable in the server room, an entire department goes dark. To protect against hardware failure, network engineers connect switches with Backup Cables in a triangle or ring layout.

If the main cable breaks, the backup cable keeps everyone online. But at Layer 2, backup cables create a deadly trap: Loops.

Why Switches Cannot Handle Loops on Their Own

Unlike Layer 3 IP packets—which carry a Time-to-Live (TTL) counter that counts down to zero and disappears—an Ethernet frame header has no hop counter at all. Once an Ethernet frame is created, it will live forever unless a switch port drops it.

If you connect three switches in a triangle without special protection, a single broadcast message (like a normal ARP request) starts spinning around the circle. Every switch copies the frame and forwards it back to the other switches. Within three seconds, that single broadcast multiplies into thousands of copies, creating a full Broadcast Storm. Link activity lights turn solid green, switch processors freeze at 100%, and the entire office loses connection.

Radia Perlman and the Spanning Tree Solution

In 1985, an engineer named Radia Perlman solved this problem with a brilliant algorithm called the Spanning Tree Protocol (STP). Later standardized as IEEE 802.1D, STP allows you to keep physical backup cables plugged in, but logically turns off one of the ports so traffic cannot loop in circles.

Switches work together in four steps:

  1. Sharing Heartbeats (BPDUs): Every two seconds, switches send tiny announcement messages called Bridge Protocol Data Units (BPDUs) out of their ports to discover their neighbors.
  2. Picking the Leader (Root Bridge): Switches compare their ID numbers. The switch with the lowest number is elected as the reference point for the whole network: the Root Bridge.
  3. Finding the Best Path (Root Ports): Every other switch picks the port with the fastest, shortest path back to the Root Bridge. That port becomes the Root Port and stays wide open for traffic.
  4. Blocking the Redundant Path: On the link between remaining switches, STP looks at the ports. One port is chosen to carry traffic, while the port at the other end is placed into the Blocking State.
Port State Port Light Color Does It Forward User Data? What It Is Doing
Forwarding Solid Green Yes: normal files, pings, and web pages flow through. Active working link.
Blocking Solid Amber No: user traffic is completely blocked to stop loops. Silently listening for link failure.

What Happens During a Real Cable Failure?

While an amber port sits in the Blocking state, it is not broken. It is a guard waiting on standby. It continuously listens for BPDU heartbeats from the other switch.

If a technician unplugs the primary green cable, the amber port stops hearing heartbeats. It immediately knows the main highway is dead. Within seconds, it changes from amber to green, restoring full connectivity across the backup cable without any human having to run to the server room.

In the original 802.1D standard, this failover took between 30 and 50 seconds because the port waited through listening and learning states. Modern enterprise switches run Rapid Spanning Tree Protocol (RSTP), cutting this failover time down to under two seconds so video calls and file downloads do not disconnect.

The Next Challenge: Securing Physical Wall Ports

Spanning Tree protects our network backbone from loops between switches. But what about the other end of the wire—the physical network jacks in office cubicles and conference rooms? If a visitor unplugs an office PC and plugs in their own device, how do we stop them?

While STP keeps the switches themselves from crashing into broadcast storms, it does not inspect who is plugged into the ports. An untrusted laptop can still flood the switch CAM table or eavesdrop on unencrypted packets. In our next chapter, we will complete our enterprise campus toolkit by locking down switch access ports with Port Security.

Hands-On Practice Checklist

Progress:0 / 3

Perform actions on the practice lab canvas on the right. Tasks automatically check off as you connect cables and run commands.

Task 1: Inspect Triangular Redundant Topology

Observe the three interconnected switches (Root Switch, Switch-Left, and Switch-Right). Confirm that redundant physical links form a closed triangle loop.

Task 2: Identify the STP Root Bridge

Click Root Switch and inspect its STP configuration to confirm it was elected as the Root Bridge for the campus spanning-tree topology.

Task 3: Verify Loop-Free Communication with Ping

Open PC-1 Terminal and run "ping 192.168.1.20" to ping PC-2. Confirm that echo packets traverse the active forwarding tree with 0% packet loss.