LAN NetworksNetwork design

Spanning Tree: Why One Extra Cable Can Bring Down the Whole Network

Layer 2 loops and the missing TTL, broadcast storms, STP and BPDUs, root bridge election, port roles and cost, classic STP, RSTP and MSTP, good practices and troubleshooting.

  • Category: LAN Networks · Network design · Diagnostics
  • Published:
  • Editorial team: Alba Technology Academy
  • Reading time: about 8 minutes

Connecting two switches with a second cable looks like an easy way to make a network more reliable. Yet, without protection, that very extra cable can stop everything within seconds. The culprit is the layer 2 loop, and the cure is called Spanning Tree. Let us see why a loop is so dangerous, how the Spanning Tree Protocol chooses which ports to use and which to block, what changes with RSTP and MSTP, and which good practices to follow.

Why a layer 2 loop is dangerous

When the destination of a frame is unknown, or when it is the broadcast address FF:FF:FF:FF:FF:FF, a switch sends it out of every port in the same VLAN except the one it came in on. This flooding works perfectly as long as there is only one path between any two points of the network.

If the links form a loop instead, for example three switches in a triangle or two switches joined by two cables, the frame returns to the switch it started from, which forwards it again, and so on. At layer 3 the problem dies out by itself: every IP packet has a TTL field (the hop limit in IPv6) that each router decrements, and at zero the packet is discarded. The Ethernet header has no such field: a frame that enters a layer 2 loop keeps circling until someone breaks the circle.

Broadcast storm, unstable MAC table and duplicate frames

The effects of a loop appear together and reinforce one another.

  • Broadcast storm. Every broadcast that enters the loop keeps circling in both directions. Devices send them all the time (ARP, DHCP, service announcements), so the copies pile up and, when there is more than one loop, they multiply at every pass. Within seconds the links are saturated and the switch CPUs hit their limit.
  • Unstable MAC table. The same frame arrives now on one port, now on another: the sender's entry keeps jumping between ports (MAC flapping) and even unicast traffic heads in the wrong direction.
  • Duplicate frames. Computers receive several copies of the same frame and, with thousands of copies per second, applications freeze.
A layer 2 loop and a broadcast storm Three switches, SW1, SW2 and SW3, are connected in a triangle. PC A, connected to SW2, sends a broadcast: the copies circle the loop clockwise and anticlockwise and never expire, because Ethernet frames have no TTL field. On the right, SW1's MAC table sees A's address first on port 2, then on port 4. An IP packet, by contrast, is discarded when its TTL reaches zero. A broadcast enters the loop and never leaves SW1SW2SW3 PC A broadcast to FF:FF:FF:FF:FF:FF copies circleboth ways Ethernet frame: no TTL The frame never expires:it circles until the loop is opened. SW1 MAC table (A's MAC) port 2 → port 4 → port 2 … the entry keeps changing IP packet, for comparison TTL 64 → 63 → … → 0: discarded
Figure 1 — Simplified diagram. In a triangle of switches a single broadcast produces two copies that circle forever, while SW1's MAC table keeps changing port.

A loop is often created by accident: a cable between two wall sockets in the same room, or a patch cord with both ends plugged into the same desktop switch. An automatic mechanism is therefore needed to neutralise it.

The Spanning Tree Protocol: BPDUs and the root bridge

The Spanning Tree Protocol (STP), originally defined in IEEE 802.1D and based on an algorithm devised by Radia Perlman in the mid-1980s, turns a physical topology with loops into a logical tree: only one path stays active between any two points, and redundant links are kept in reserve.

Switches (the bridges of the standard) exchange messages called BPDUs (Bridge Protocol Data Units), sent to the reserved multicast address 01:80:C2:00:00:00. Each switch has an 8-byte bridge ID, made of a 2-byte priority and its own MAC address. The default priority is 32768; on recent equipment it is set in multiples of 4096, because part of that field identifies the instance or the VLAN.

The first step is the election of the root bridge, the root of the tree. At first every switch claims to be the root; when it receives a BPDU with a bridge ID lower than its own, it accepts the other as a better candidate. The lowest bridge ID wins: priority counts first and, on a tie, the MAC address. If nobody has changed the priority, the switch with the lowest MAC becomes root, often the oldest model on the network. The root bridge then sends a BPDU every hello time, 2 seconds by default, and the other switches relay it down the tree.

Port roles and path cost

Once the root is elected, each switch calculates its path cost to the root bridge by adding up the cost of the links along the way. The cost depends on speed: with the values of the 1998 standard a 100 Mbit/s link costs 19, a 1 Gbit/s link 4 and a 10 Gbit/s link 2; with the "long" values introduced by IEEE 802.1t and adopted by 802.1D-2004, the same links cost 200,000, 20,000 and 2,000. All switches in the network must use the same scale.

Based on cost, every port is given a role:

  • Root port: on every switch other than the root, the port with the lowest cost to the root bridge. On equal cost, the port receiving BPDUs from the lowest bridge ID wins, and then the one with the lowest port identifier.
  • Designated port: on every link, the port of the switch closest to the root, the one that forwards traffic onto that segment. All active ports of the root bridge are designated.
  • Blocked port: any port that is neither root nor designated does not forward traffic. RSTP calls it alternate when it offers a backup path to the root, and backup when it duplicates another port of the same switch on the same segment.
Topology with the root bridge and a blocked port SW1, with the lowest bridge ID, is the root bridge and both its ports are designated. SW2 and SW3 reach the root with cost 4 through their direct root port; the alternative path would cost 8. On the link between SW2 and SW3, SW2's port is designated because SW2 has the lower bridge ID, while SW3's port is alternate and stays blocked: the loop is open. The logical tree: only one active path between two points SW1 · root bridge priority 32768 · MAC …:01 SW2 SW3 32768 · MAC …:0232768 · MAC …:03 D D R R D A cost 4cost 4cost 4 blocked R root port D designated port A alternate (blocked, no forwarding) Indicative costs for 1 Gbit/s links; example MACs (RFC 7042)
Figure 2 — SW2 and SW3 reach the root directly with cost 4; going through the other switch would cost 8. On the link between SW2 and SW3, SW3's port stays blocked.

The blocked port keeps receiving BPDUs, but it neither forwards nor learns traffic. If the active link fails, Spanning Tree recalculates the topology and that port goes into service.

States and timers: from classic STP to RSTP

In classic STP a port does not start forwarding straight away, to avoid temporary loops. It goes through the blocking, listening (takes part in the election, does not learn addresses) and learning (learns MAC addresses, does not forward) states before reaching forwarding. Each of the two intermediate phases lasts one forward delay, 15 seconds by default. If the failure is not detected directly, the switch also waits for the max age, 20 seconds, before treating the received information as expired. That is why classic STP needs roughly 30 to 50 seconds to reconverge: an eternity for phone calls and applications.

The Rapid Spanning Tree Protocol (RSTP), published as IEEE 802.1w in 2001, later merged into 802.1D-2004 and today part of IEEE 802.1Q, keeps the same logic but cuts the times drastically. There are three states (discarding, learning, forwarding); alternate ports are calculated in advance and, if the root port fails, one of them becomes root port at once; on point-to-point links between switches a proposal/agreement handshake moves ports to forwarding without waiting for the timers. Edge ports, facing computers, start forwarding immediately. Reconvergence usually takes a few seconds, often less than one. RSTP is compatible with classic STP, but falls back to the slow timers towards legacy switches.

MSTP in brief

With VLANs, a single tree can leave many links unused. The Multiple Spanning Tree Protocol (MSTP), born as IEEE 802.1s and now part of 802.1Q, allows several Spanning Tree instances, each associated with a group of VLANs. Each instance can have a different root bridge, so a link blocked for some VLANs stays active for others. Switches with the same configuration (name, revision and VLAN-to-instance mapping) form an MST region.

ProtocolStandardPort statesTypical reconvergenceTrees
Classic STPIEEE 802.1D (up to the 1998 edition)Blocking, listening, learning, forwardingAbout 30–50 sOne for the whole network
RSTPIEEE 802.1w, then 802.1D-2004 and 802.1QDiscarding, learning, forwardingA few seconds, often less than oneOne for the whole network
MSTPIEEE 802.1s, now 802.1QAs RSTPAs RSTPSeveral instances, each for a group of VLANs

There are also proprietary variants with one tree per VLAN: with switches from different vendors it is safer to use RSTP or MSTP, which are standard.

Good practices

  • Choose the root bridge. Do not leave the election to chance: give the lowest priority, for example 4096, to the central switch (the core) and a slightly higher one, for example 8192, to the switch that must take over.
  • Edge ports towards computers. Configure the ports facing PCs, printers and phones as edge (on some equipment PortFast): they start forwarding at once and do not trigger topology changes.
  • BPDU guard. On the same ports, shut the port down if it receives a BPDU: if someone plugs in a switch or closes a loop on the socket, the port goes down immediately. Root guard, instead, prevents an edge switch from becoming root.
  • Never disable STP. Even in a network without loops, Spanning Tree is the insurance against human error.
  • Two cables together? Link aggregation. To use two links between the same switches at the same time, aggregate them with LACP (IEEE 802.1AX, originally 802.3ad): the cables form a single logical link, which Spanning Tree sees as one port, and remain redundant.
  • Limit the damage. Storm control limits the broadcast traffic accepted on a port: it does not replace Spanning Tree, but it contains the damage.

Troubleshooting

A storm has recognisable symptoms: the LEDs of all ports flash together, the network stops all of a sudden, switch management responds with difficulty and the logs report the same MAC on different ports. The first action is physical: unplug the suspect cable, or the ports one at a time, until traffic returns to normal.

On managed switches, check the root bridge, the role and state of each port and the topology change counter: if it keeps growing, a port is unstable. On many devices the command is similar to show spanning-tree; an indicative example:

Root bridge     priority 4096   MAC 00:00:5E:00:53:01
This switch     priority 32768  MAC 00:00:5E:00:53:03
Port   Role         State        Cost
1      root         forwarding   20000
5      alternate    discarding   20000
7      designated   forwarding   20000  (edge)

If the root bridge is not the expected one, or a port facing a PC is not edge, the configuration needs reviewing. Many unmanaged switches do not support Spanning Tree: they must never be connected to each other with more than one cable.

Conclusions

A layer 2 loop is enough to bring a network down, because Ethernet frames have no TTL. Spanning Tree elects a root bridge, gives each port a role based on cost and blocks redundant paths, which stay ready to take over in case of failure. RSTP brings reconvergence down to a few seconds, MSTP adds trees for groups of VLANs. Choosing the root bridge, protecting the ports facing computers and using link aggregation make the network stable and predictable.

The video

Spanning Tree: Why One Extra Cable Can Bring Down the Whole Network — Animation without voice-over, with on-screen text in English and sound effects.

Technical sources

  • IEEE Std 802.1D-2004 — MAC Bridges — Spanning Tree Protocol and Rapid Spanning Tree Protocol: BPDUs, bridge ID, port roles and states, path costs, hello time, max age and forward delay.
  • IEEE Std 802.1D-1998 — Classic Spanning Tree: blocking, listening, learning and forwarding states and "short" path costs (for example 4 for 1 Gbit/s).
  • IEEE Std 802.1w-2001 — Rapid Spanning Tree Protocol (RSTP): alternate and backup ports, edge ports, the proposal/agreement mechanism; later incorporated into IEEE 802.1D-2004.
  • IEEE Std 802.1t-2001 — "Long" path costs (for example 20,000 for 1 Gbit/s) and the system ID extension in the bridge ID (priority in multiples of 4096).
  • IEEE Std 802.1Q — Bridges and Bridged Networks — Current standard including RSTP and MSTP (originally IEEE 802.1s): multiple Spanning Tree instances mapped to groups of VLANs, and MST regions.
  • IEEE Std 802.1AX — Link Aggregation — Link aggregation and the LACP protocol (originally IEEE 802.3ad).
  • Radia Perlman, «An Algorithm for Distributed Computation of a Spanning Tree in an Extended LAN», ACM SIGCOMM Computer Communication Review, 1985 — The original Spanning Tree algorithm.
  • RFC 791 e RFC 8200 — The IPv4 TTL field and the IPv6 hop limit, cited for comparison with Ethernet frames, which have no equivalent field.
  • RFC 7042 — MAC addresses reserved for documentation (00-00-5E-00-53-00 … 00-00-5E-00-53-FF), used in the examples.

Standards and official documentation available from the respective organisations.