All lessons are free · No login · No trackingStart learning

Network Stories 7 · Intermediate

Octo's Broadcast Storm: Spanning Tree Protocol

Adding an extra cable should make the network more reliable. So why did the whole LAN grind to a halt?

Starring: Octo, Pip, Professor Arpa, MacAbout 10 min read

Recommended first: Story 1: “Switch Basics”

1. The Story

Press "Next" to go through it step by step. In each step, one character comes on stage and explains what they are doing.

Prologue: a quick recap

Step 1 of 15

Octo's delivery rules

Remember me? I'm a Switch. I deliver by reading the MAC Address on each Frame, the little envelope data travels in. If I know the recipient, I send it only to that Port. If I don't, or if it's a Broadcast for everyone, I copy it to every other Port.

Animation text version (all steps)
  1. Prologue: a quick recap
  2. Octo's delivery rules · Octo: Remember me? I'm a Switch. I deliver by reading the MAC Address on each Frame, the little envelope data travels in. If I know the recipient, I send it only to that Port. If I don't, or if it's a Broadcast for everyone, I copy it to every other Port.
    • Full details: Network Story 1, "Octo's First Day: How a Switch Delivers"
  3. Act 1: The trouble with an extra cable
  4. The LAN grows up · Octo: There are more and more devices at home, so two more Switches join in: S1 in the middle, and S3 connected to the phone. Now, getting from Mac to the phone means going S2 → S1 → S3.
  5. The danger of a single path · Mac: Oh no! The cable between S1 and S3 has been yanked out. That was the only path between me and the phone, so now we've lost contact completely.
    • Only one path, so one break cuts everything: a Single Point of Failure
  6. Adding a spare cable · Octo: After fixing the cable, we add a spare cable between S2 and S3. This is called Redundancy: if one path breaks, there's still another one to use.
  7. Huh, is Pip going in circles? · Pip: Mac sends out a Broadcast. S2 copies me and sends me to S1 and S3, and they copy and forward me again... The three cables form a circle, and my copies keep spinning around it!
    • Three Switches connected in a circle: a Switching Loop
  8. A Frame has no "lifespan" · Pip: An IP Packet forwarded by Routers has a TTL (Time to Live). It drops by 1 at every Router, and when it reaches 0 the Packet is thrown away. But Frames passed between Switches have no such "lifespan", so they keep going round and never stop.
  9. Broadcast Storm! · Octo: Every time the copies reach a Switch, they get copied again. Soon the cables are jammed, all three of us are rushed off our feet, and Mac can't even open a web page. This is a Broadcast Storm.
    • Another side effect: the same MAC Address shows up on one Port, then another, so the MAC Address Table becomes a mess
  10. Act 2: Enter Spanning Tree
  11. Professor Arpa's bright idea · Professor Arpa: A long, long time ago... well, in 1985, engineer Radia Perlman came up with a plan: keep every cable, but temporarily close off one Port so the network becomes a loop-free "tree". This is Spanning Tree Protocol, or STP for short.
  12. Step 1: Elect the Root Bridge · Octo: We swap little letters called BPDUs (Bridge Protocol Data Units), each with our own Bridge ID written on it. The Switch with the smallest Bridge ID is elected Root Bridge and becomes the root of the tree.
    • The Switch's ancestor was called a Bridge, so STP's terms all use "Bridge"
    • Bridge ID = priority + MAC Address
    • S1: 32768 + …:A1 ← smallest, elected!
    • S2: 32768 + …:A2
    • S3: 32768 + …:A3
    • If the priorities are equal, compare the MAC Addresses
  13. Step 2: Find the Root Ports · Octo: Each of the other Switches finds the Port "closest to the root", called its Root Port. S2 and S3 are both connected straight to S1, and that path has the lowest Path Cost, so both pick the Port leading to S1.
    • Path Cost of each 1 Gbps cable: 4
    • S2 → S1: 4 (lowest)
    • S2 → S3 → S1: 4 + 4 = 8
  14. Step 3: One Designated Port per cable · Octo: On each cable, only one Port is in charge of forwarding Frames. It's called the Designated Port. All of the Root Bridge's Ports are Designated Ports. On the cable between S2 and S3, both ends have the same cost to the root, so the Bridge IDs are compared: S2's is smaller, so S2's end wins.
    • S2 → root: 4, S3 → root: 4 (a tie)
    • Compare Bridge IDs: …:A2 is smaller than …:A3 → S2 wins
  15. Step 4: Pause the remaining Port · Octo: Any Port that is neither a Root Port nor a Designated Port gets Blocked: it doesn't forward Frames, but it still listens for BPDUs. That's how the Port on S3 leading to S2 gets paused.
    • DP = Designated Port: in charge of forwarding
    • RP = Root Port: leads to the root
    • BP = Blocked Port: forwarding paused, only listens for BPDUs
  16. No more loop! · Pip: Mac sends another Broadcast. This time my copy stops when it reaches the Blocked Port. Every device gets just one copy, and nothing goes round in circles any more.
  17. The spare cable steps in · Octo: If the cable between S1 and S3 breaks again, S3 notices that its path to the root is gone. It reopens the Port that was Blocked and reaches the root through the spare cable via S2 instead.
    • Before opening, the Port goes through the Listening and Learning stages to make sure no loop appears again
    • Traditional STP: about 30 to 50 seconds to recover
    • The newer RSTP (Rapid Spanning Tree Protocol): usually recovers within a few seconds
  18. Summary · Octo: With STP, every cable can stay. Normally we deliver along a loop-free tree, and if one cable breaks, the spare one steps in. An extra cable makes things more reliable without causing a storm.
    • A Switch delivers inside a LAN using Learning, Flooding and Forwarding
    • When there's a loop, a Broadcast turns into a Broadcast Storm
    • STP: elect the Root Bridge → find Root Ports → choose Designated Ports → Block the rest

2. Where Is the Problem

There are three Switches at home: S2, S1 and S3. A Switch is the device that delivers data between the devices inside one network. The phone connects to S3 through the Access Point upstairs. There is only one path from Mac to the phone: S2 → S1 → S3. If the cable between S1 and S3 breaks, the two sides lose contact completely. This "one break and everything breaks" weakness is called a Single Point of Failure.

So everyone adds a spare cable between S2 and S3. This is called Redundancy. But now the three cables form a perfect circle, which creates a Switching Loop:

  1. Mac sends out a Broadcast, a message meant for every device in the network.
  2. The Switch rule is to copy a Broadcast and send it out of every other Port.
  3. The copies keep circling the loop in both directions. At every Switch they are copied again to every device. New Broadcasts keep joining in, so more and more Frames pile up in the loop.
  4. A Frame has no TTL (Time to Live), so it never disappears on its own.

Within a few seconds, the cables are completely jammed. This is a Broadcast Storm. On top of that, the same MAC Address keeps appearing on one Port one moment and another Port the next, so the MAC Address Table becomes a total mess. The whole LAN (Local Area Network) is paralysed.

3. How the Network Solves It

Imagine a park with lots of little paths that wind around and join up into several loops. Visitors easily walk in circles and get lost. So the park keeper puts "Path closed for now" signs at a few junctions. Every path stays in place, but walking around no longer leads you in circles. If one path gets damaged, the keeper simply moves a sign away.

Spanning Tree Protocol, or STP for short, is the "park keeper" between Switches. The Switches swap BPDU (Bridge Protocol Data Unit) messages and automatically pick a loop-free "tree". Any extra Ports are temporarily Blocked and become Blocked Ports. When a link fails, a paused Port opens up again.

4. A Closer Look

A bit of history

In 1985, engineer Radia Perlman designed the STP algorithm. She even wrote a little poem about it, praising "a tree with no loops that still connects every LAN". The IEEE (Institute of Electrical and Electronics Engineers) later turned it into the 802.1D standard.

The Switch's ancestor was called a Bridge, so STP's terms all use the word "Bridge", for example Root Bridge.

Step 1: Elect the Root Bridge

Every Switch has a Bridge ID:

Bridge ID = Bridge Priority + MAC Address

S1: 32768 + 00:00:5E:00:53:A1   ← smallest, elected Root Bridge
S2: 32768 + 00:00:5E:00:53:A2
S3: 32768 + 00:00:5E:00:53:A3

The priority is compared first, and the smaller one wins. If the priorities are the same, the MAC Addresses are compared. The default priority is 32768, and it can be adjusted in multiples of 4096. Network administrators usually lower the priority of the most central, most powerful Switch to make sure it wins, instead of leaving it to a MAC Address "lucky draw".

Step 2: Find the Root Port

Every Switch that is not the root has to find the one Port that is "closest to home". Distance is measured in Path Cost. The faster the cable, the lower the cost:

Cable speed Path Cost (traditional 802.1D values)
10 Mbps 100
100 Mbps 19
1 Gbps 4
10 Gbps 2

Take S2 as an example. Going straight to S1 costs 4. Going via S3 and then to S1 costs 4 + 4 = 8. So the Port on S2 that leads to S1 is its Root Port. The same goes for S3.

Step 3: Choose one Designated Port for each cable

On each cable, only one Port is in charge of forwarding Frames:

  • All of Root Bridge S1's Ports are Designated Ports.
  • On the cable between S2 and S3, both ends have a cost of 4 to reach the root. It's a tie! So the Bridge IDs are compared: …:A2 is smaller than …:A3, so S2's end wins.

Step 4: Block the remaining Ports

The Port on S3 that leads to S2 is neither a Root Port nor a Designated Port, so it gets Blocked. It does not forward normal Frames and does not learn MAC Addresses, but it keeps listening for BPDUs. The final result:

Cable This end Other end
S1 — S2 S1: DP S2: RP
S1 — S3 S1: DP S3: RP
S2 — S3 S2: DP S3: BP (Blocked)

How does the spare cable step in?

By default, the Root Bridge sends a BPDU every 2 seconds. When the cable between S1 and S3 breaks, S3 notices that its path to the root is gone. It then turns the Port that was Blocked into its new Root Port.

But traditional STP is very careful. A Port has to pass through several states, one after another, before it can start forwarding:

Blocking → Listening 15 seconds → Learning 15 seconds → Forwarding

In the Listening stage, the Switch first makes sure no new loop will form. In the Learning stage, it learns MAC Addresses first, to reduce Flooding (sending a Frame out of every Port). If the Switch has to wait for old information to expire before it spots the problem (Max Age, 20 seconds by default), the whole thing takes about 50 seconds. Even when it detects the broken cable directly, it still takes about 30 seconds.

The new generation: RSTP

30 to 50 seconds is far too slow for today's networks. So in 2001 the IEEE introduced 802.1w, known as RSTP, short for Rapid Spanning Tree Protocol. It prepares backup Ports in advance, and Switches confirm things directly with each other, so recovery usually takes a few seconds or even less than one second. Today, most Switches use RSTP or an extended version of it by default.

5. Try It Yourself

Task: Pick your Root Bridge

There are four Switches. Their Bridge IDs are:

Switch Priority MAC Address
A 32768 00:00:5E:00:53:B2
B 32768 00:00:5E:00:53:B1
C 28672 00:00:5E:00:53:B9
D 32768 00:00:5E:00:53:B0
  1. Which one becomes the Root Bridge? (Answer: C. Its priority is the smallest, so there is no need to compare MAC Addresses at all.)
  2. If C is switched off, which one takes over? (Answer: D. The other three have the same priority, so the MAC Addresses are compared, and …:B0 is the smallest.)
  3. Think about it: why would an administrator deliberately lower the priority of the core Switch?

Mini game

STP in the right order

Three Switches have just been switched on. Put the four STP steps in the right order.

  1. Choose one Designated Port for each cable
  2. Swap BPDUs and elect the Switch with the smallest Bridge ID as Root Bridge
  3. Set the remaining Ports to Blocked, so they only listen for BPDUs
  4. Each non-root Switch picks the Root Port with the lowest cost to the root

6. Where the Analogy Breaks

  • A Blocked Port is not an "unplugged cable". The cable stays connected, and the light may still be on. The Port simply does not forward normal Frames, and it keeps listening for BPDUs.
  • Pip doesn't really "get tired of going round in circles". A Frame in a loop never gets older or slower, because it has no TTL. Every Broadcast circles forever, and new Broadcasts keep joining in, so the traffic keeps piling up until the cables and Switches are completely full.
  • The root is not necessarily "in the middle". The Root Bridge is chosen only by Bridge ID. If the administrator doesn't adjust the priority, an old Switch in some corner might be chosen, and traffic takes a long detour.
  • STP doesn't make the network faster. It simply lets the spare cable rest most of the time. To make two cables work together, you need the method in the next story.
  • The recovery time in the animation is shortened. Traditional STP really does wait 30 to 50 seconds, and during that time any data using that path is cut off.

7. Quiz

Question 1 of 3Three Switches are connected in a loop and STP is not running. What problem is most likely?
Question 2 of 3How does STP elect the Root Bridge?
Question 3 of 3What does a Blocked Port do?

8. Key Notes

  • Adding a spare cable gives you Redundancy, but if Switches are connected in a circle, they form a Switching Loop.
  • A Frame has no TTL, so every Broadcast circles the loop forever while new ones keep joining in. The traffic piles up into a Broadcast Storm, which paralyses the whole LAN.
  • STP (Spanning Tree Protocol) has four steps: elect the Root Bridge → find the Root Ports → choose a Designated Port for each cable → Block the remaining Ports.
  • A Blocked Port doesn't forward Frames but keeps listening for BPDUs. If a link breaks, it opens up again so the spare cable can step in.
  • Traditional STP takes about 30 to 50 seconds to recover; the newer RSTP (Rapid Spanning Tree Protocol) usually finishes within a few seconds.

Further reading

STP lets us add spare cables without worrying about storms. But most of the time the spare cable just "sits on the bench", which is a bit of a waste. Is there a way to let two cables work together without creating a loop? In the next story, Octo bundles two cables into one: "Two Cables Pulling Together: Link Aggregation".