Course contents

Chapter 6: Spanning Tree ProtocolLesson 1 of 25

Why is Spanning Tree needed?

Why can adding a backup cable make a switched network stop working? Let's follow one frame around three switches and see why a spare path needs loop protection.

Beginner · 6 min read

A third cable for a three-switch office

An office has three switches, connected in a line: SW2 – SW1 – SW3. If one cable breaks, part of the office is cut off. So the designer adds a third cable, SW2 – SW3. Now the switches form a triangle. Any one cable can break, and every switch can still reach every other switch.

This is called redundancy: a spare path that takes over when the main one fails. For example, each access switch has two uplinks, and there are two core switches. But redundancy causes a big problem for Ethernet.

Learn more: LAN Switching with Redundant Links

What the switches normally learn

PC A connects to SW2 and PC B connects to SW3. For this lesson both PCs are in VLAN 10, one logical Layer 2 network carried across the switch links. PC A is 192.168.10.10/24 and PC B is 192.168.10.20/24. They are in the same IP subnet, so the exchange does not need a router or a default gateway.

An Ethernet frame carries a source and destination MAC address, the link-layer addresses used by switches. When SW2 receives a frame from PC A, it learns PC A's source MAC on the receiving port in VLAN 10. This entry goes into the MAC address table. Learning uses the source address; the destination address determines where the frame goes next.

If the destination MAC is known, the switch can choose its learned port. An unknown unicast is addressed to one device whose port has not been learned. The switch floods it to the other eligible forwarding ports in the same VLAN. A broadcast is intended for all devices in that VLAN and is flooded too.

One ARP request, flooded round the triangle

PC A needs PC B's MAC address before sending its local IPv4 packet. ARP (Address Resolution Protocol) asks which MAC belongs to 192.168.10.20. The request is an Ethernet broadcast to ff:ff:ff:ff:ff:ff. The animation deliberately shows the faulty case: all three sides forward for VLAN 10, with no effective spanning-tree protection.

Diagram
A broadcast storm in a switching loop
A broadcast storm in a switching loop
SW1SW2SW3PC APC B

Device key: SW1, SW2, SW3 (switch) · PC A, PC B (computer)

Lines show the example’s network connections. The coloured path and envelope follow the current step; its text identifies the sender, receiver and traffic type.

  1. 1. One frame. PC A sends one broadcast.
  2. 2. Flooded. SW2 copies the broadcast to its other forwarding ports in VLAN 10: one copy to SW1 and one to SW3.
  3. 3. Flooded again. SW1 sends its copy on to SW3. SW3 sends its copy on to SW1 (and to PC B).
  4. 4. Back where it started. Copies return to SW2 on different links and are flooded again. Ethernet has no hop counter to end this loop.
PC A sends one ARP broadcast. Copies circulate through the fully forwarding triangle; arrows show Ethernet frame copies, not three new ARP requests generated by the PC.

No TTL in an Ethernet frame

An IP packet has a TTL (time to live) number. Every router lowers it by one. When it reaches zero, the packet is thrown away. So a packet stuck in a routing loop dies after a while. An Ethernet frame has no TTL. Switches pass it on without reducing the IP TTL inside it. A looping copy may eventually be lost because of congestion or an error, but Ethernet supplies no hop limit to make the loop safe.

Storms, MAC flapping and duplicate frames

Diagram
Storms, MAC flapping and duplicate frames
Storms, MAC flapping and duplicate frames
ProblemWhat you seeWhy
Broadcast stormHigh link use, discarded frames, slow services and possibly loss of management accessEvery switch copies every broadcast again and again. New broadcasts keep adding more.
MAC table instabilityThe same MAC address keeps jumping between ports ("MAC flapping"), and the switch logs itCopies of PC A's frame arrive on different ports, so the switch keeps changing its mind about where PC A is
Duplicate framesHosts receive the same unicast frame several timesA frame for an unknown MAC address is flooded around the loop and arrives more than once
Read each row across: the left box names the item, the others describe it.

Warning: a broadcast storm can stop a whole network within seconds. It can happen very easily: for example, someone plugs both ends of one cable into the same switch, or connects two wall sockets together.

In practice, MAC flapping messages in the switch log (%SW_MATM-4-MACFLAP_NOTIF on many Cisco switches) are often the first clue that a loop exists.

The switch relearns a source MAC whenever a frame with that source arrives on a different port in the VLAN. If returning copies arrive through both uplinks, the source appears to move even though PC A is still at its desk. MAC flapping describes that repeated movement. It is evidence to investigate, not proof by itself: legitimate mobility and some multihoming faults can also move an address.

Keeping the spare links without the loops

You want the spare links, so the network survives a broken cable. You also want no loops, so the network stays stable. Spanning Tree Protocol (STP) gives you both. All the cables stay connected, but STP prevents selected ports from forwarding user frames for the relevant tree. It does not administratively shut those interfaces. The next lesson follows the protected triangle.

Short lab: observe protection without creating a storm

Use an isolated three-switch Cisco IOS/IOS XE lab with spanning tree enabled and VLAN 10 already carried on all three links. Keep its protection enabled throughout. Verify the mode rather than assuming a factory default; PVST+, Rapid PVST+ and MST are different supported designs.

The root bridge is the reference switch elected for this tree. A root port leads towards it. An RSTP alternate port offers another path towards it but does not currently forward user frames. The next two lessons show how those choices are made.

show spanning-tree summary show spanning-tree vlan 10 show mac address-table dynamic vlan 10

Privileged EXEC on each lab switch. Check the active mode, VLAN 10's forwarding/non-forwarding ports and the learned source MAC addresses.

Illustrative Rapid PVST+ excerpt · selected uplink rows, not a lab capture
SW3#show spanning-tree vlan 10
Interface        Role Sts Cost      Prio.Nbr Type
Gi1/0/1          Root FWD 4         128.1    P2p
Gi1/0/2          Altn BLK 4         128.2    P2p
Root/FWD is the active path towards the root switch. Altn/BLK is a non-forwarding alternate path; some Cisco RSTP output uses BLK even though the RSTP state is called discarding. These costs assume the short path-cost method and gigabit links.

Send a few pings from PC A to PC B. Inspect the MAC table again and identify PC A on the expected port. If you cannot identify a protected, non-forwarding side of the triangle for VLAN 10, stop the traffic and verify the lab configuration before adding more traffic. Do not disable STP or BPDU processing to reproduce the animation.

Test yourself on switching loops

Predict · scenario 1

Why does a packet caught in a routing loop eventually die, while a frame in a switching loop doesn't?

Predict · scenario 2

PC A's ARP broadcast arrives on SW2 in VLAN 10. Where is it normally flooded?

Predict · scenario 3

A switch logs that PC A's MAC address keeps moving between Gi1/0/1 and Gi1/0/2. What's the most likely cause?

Sources: Cisco spanning-tree behaviour and verification; IEEE MAC bridging background. The deliberately unprotected animation is an explanation, not an instruction to disable loop protection.