The idea: a loop-free tree that heals fast

Switches are often wired in a ring or a mesh, so that one broken cable does not cut anybody off. But Ethernet frames have no hop limit, and a loop makes broadcasts circle forever. The Spanning Tree Protocol keeps every cable plugged in and turns some ports off, so that exactly one path joins any two switches. Why loops are so bad, and STP on two switches, is on How Ethernet Switches Forward Frames. This page is about what happens after a failure: how fast the tree grows back.

Rapid Spanning Tree (RSTP, IEEE 802.1w, now part of 802.1D-2004) builds the same tree as classic STP (802.1D-1998), but it repairs it in milliseconds instead of 30 to 50 seconds. It does this in two ways: every switch keeps a spare path ready (the alternate port), and two neighbours agree with a quick proposal/agreement handshake instead of waiting on timers.

SW3 has two BPDUs that lead to root SW1. On p2, from SW4: root SW1, cost 40000, plus the port cost 20000 gives 60000. On p1, from SW1 directly: cost 0 plus 200000 for the 100 Mb/s link gives 200000. Both have the same root ID, so the cost decides: p2 wins and becomes the root port; p1 becomes the alternate port.
A switch compares priority vectors field by field: root ID first, then the cost to reach it.

The page has four switches in a square and a shared hub on SW4 with PC B behind it. PC A is on SW3. Every switch has the default priority 32768. A BPDU hop takes 10 ms on the page, and a cut cable is noticed by both ends at once.

Electing the root bridge

Every switch has a bridge ID: a 2-byte priority (default 32768, set in steps of 4096) followed by its MAC address. The lowest bridge ID wins and becomes the root bridge. At power-on each switch believes it is the root and says so in its BPDUs: "root = me, cost 0". As soon as a switch hears a better root, it stops claiming and passes the better one on. Here all priorities are equal, so the lowest MAC decides: SW1 (32768.aa00.0000.0001) wins. (Demo 1: RSTP power-on)

Leaving the choice to the MACs is bad practice: the oldest switch often has the lowest MAC. Network engineers set the priority of the switch they want as root. Set SW4 to 4096 and it wins, whatever its MAC. (Demo 2: SW4 priority 4096)

Port roles from path cost

Each port has a path cost that depends on its speed. 802.1D-2004 uses 20000 for 1 Gb/s, 200000 for 100 Mb/s and 2000000 for 10 Mb/s. A BPDU carries a priority vector: root ID, root path cost, sender bridge ID, sender port ID. Smaller is better, field by field. Each switch gives every port one role:

RoleMeaningOn the page
Root portthe port with the cheapest path to the root; one per switch (the root has none)SW2 p1, SW4 p1, SW3 p2
Designatedon each link, the end that is closer to the root; it forwards onto that linkboth SW1 ports, SW2 p2, SW4 p2 and p3
Alternatea second path to the root through another switch; it discardsSW3 p1
Backupa second port of the same switch on the same shared segment; it discardsSW4 p4 on the hub
Edgea port to an end host, which sends no BPDUsSW3 p3 to PC A

SW3 shows why cost beats hop count. Its direct link to SW1 is an old 100 Mb/s link, cost 200000. The way round, SW3 → SW4 → SW2 → SW1, is three 1 Gb/s hops: 20000 + 20000 + 20000 = 60000. So the long way is SW3's root path, and its direct link becomes the alternate port. On SW4, p3 and p4 both go to the hub. p3 has the lower port ID, so p3 is designated and p4 is backup. Classic STP has only root, designated and blocked; the alternate and backup names are new in RSTP.

Port states and edge ports

RSTP has three states. Discarding: drop data frames (BPDUs still go through). Learning: still drop them, but fill the MAC table. Forwarding: pass frames. Classic STP has five: disabled, blocking, listening, learning, forwarding. RSTP merges disabled, blocking and listening into discarding. Root and designated ports end up forwarding; alternate and backup ports stay discarding. An edge port has only a PC behind it, so it forwards at once: there is no loop to fear (Cisco's name for it is PortFast).

A link fails: the alternate port takes over

When the cable between SW3 and SW4 is cut, SW3 loses its root port. But it has kept the BPDU that SW1 sends on the direct link every hello time (2 s), so it already knows another way to the root. The alternate port p1 becomes the root port and starts forwarding in the same instant. No message is needed and no timer runs. PC A's path changes from A → SW3 → SW4 → B to A → SW3 → SW1 → SW2 → SW4 → B, and the page counts an outage of 0.000 s. (Demo 3: link SW3–SW4 fails) A real switch takes a few milliseconds to notice the loss of signal.

Proposal and agreement

When the cable comes back, the two new ports know nothing. Each one thinks it is designated, stays discarding and sends a BPDU with the proposal flag: "I want to forward on this link". SW4's BPDU is better (root SW1, cost 40000), so SW3 makes p2 its root port again (40000 + 20000 = 60000 beats 200000) and p1 goes back to alternate. Before it agrees, SW3 syncs: it puts every other non-edge designated port into discarding, so that no loop can form below it. Then it answers with an agreement, and SW4's p2 forwards as soon as it arrives. (Demo 4: the link comes back)

Time runs down. At 0 ms the link comes up and SW3 p2 and SW4 p2 both send a proposal. At 10 ms SW3 sees SW4's better BPDU, makes p2 its root port and forwarding, moves p1 to alternate discarding, syncs and sends an agreement. At 20 ms SW4 p2 receives the agreement and forwards. PC A to PC B is cut only between 10 and 20 ms.
Two BPDU hops replace 30 seconds of timers; PC A loses only 10 ms.

The sync moves down the tree: a switch that blocked its designated ports proposes on them in turn, and the next switch syncs and agrees. Each hop costs one round trip, so a whole network settles in well under a second. The handshake needs a point-to-point link: on a shared segment (the hub) many switches could answer, so the designated port there falls back to the old timers, 15 s learning and 15 s forwarding. You can see it in Demo 1: every other port forwards within tens of milliseconds, but SW4 p3, and so PC B, waits 30 s.

Classic STP: timers only

Classic STP has no alternate port and no handshake. A port that may forward has to wait: 15 s listening (forward delay), then 15 s learning, then forwarding. The timers are there so that the news of the change can reach every switch before any new path opens. The same cut costs PC A 30 s. (Demo 5) Even the repair hurts: when the cable comes back, SW3's old root port blocks at once, and the new one needs 30 s again. (Demo 6)

Outage bars on a 0 to 50 s axis. RSTP, link fails: 0 s. RSTP, link comes back: 0.01 s. Classic STP, direct failure: 15 s listening plus 15 s learning, 30 s. Classic STP, failure further away: 20 s max age plus 15 s plus 15 s, 50 s.
RSTP's outage is too short to draw; classic STP's is 30 or 50 seconds.
EventClassic STP (802.1D-1998)RSTP (802.1w)
Own root port link fails, a spare path existslistening + learning: 30 salternate port forwards at once
A link further away failswait for max age (20 s), then 30 s: 50 snew information is sent at once; old information ages out after 3 missed hellos (6 s) at worst
A link comes back30 sproposal/agreement: one round trip per hop
A PC plugs in30 s (unless PortFast)edge port: at once
Who sends BPDUsthe root; others relayevery switch, every hello (2 s)

The 50 s case: when the failure is not on a switch's own link, a blocked port may still hold the old, better information. Classic STP keeps it until it is max age (20 s) old, and only then starts listening and learning. RSTP switches send their own BPDUs every hello, react to news at once, and drop information after three missed hellos.

Topology change

After the tree changes, the MAC tables are wrong: SW1 and SW2 never saw PC A before, and SW4 learned PC A on the dead link. A switch whose non-edge port starts forwarding sends BPDUs with the TC (topology change) flag, and every switch that gets one flushes the MAC entries it learned on its other ports. The frames that follow are flooded once and learned again. The page does not draw this step. How MAC learning works is on the Ethernet switch page; a hub, which just repeats every bit, is compared with a switch on Hub vs Switch vs Router.

See also VLANs for several networks on the same switches (with one spanning tree per VLAN group in MSTP), and VRRP and HSRP for the same "keep a spare ready and switch over fast" idea for the default gateway. STP builds a shortest-path tree towards the root, not a minimum spanning tree; for the difference see Prim vs Kruskal.

See also 802.1X and RADIUS: a Port That Opens Only After Login for the other reason an access port may refuse to forward: it waits for a RADIUS server to authorize the device.

See also Link Aggregation with LACP, which bundles parallel links into one port-channel so spanning tree sees a single port and blocks none of them.

What the page leaves out

Hello BPDUs every 2 s (the page sends a round of them only when two neighbours disagree), the TC flush, the extended system ID in the priority (VLAN number added to it), MSTP and per-VLAN spanning tree, the port priority (the page breaks ties on the port number only), the details of the 802.1D-2004 state machines (the page uses message age only to drop stale information after 20 switches), BPDU guard, root guard and loop guard, and mixing RSTP with old STP switches (the port falls back to STP). Checking who may use a port at all is 802.1X, on 802.1X and RADIUS.

On the mind map

Open the Networking mind mapNetworkingLayers & links: frames on one local networkLayers & linksIP & routing: packets hop between networksIP & routingCore services: address, name and timeCore servicesTCP, UDP & sockets: end to end between two portsTCP, UDP & socketsHTTP & TLS: what a browser does per requestHTTP & TLSAPIs & push: how apps talk to serversAPIs & pushProxies & edge: boxes in the middle of the pathProxies & edgeContainers: virtual networks from Linux partsContainersReal-time media: voice and video over UDPReal-time mediaSecurity at the edge: filter traffic at the borderSecurity at the edgeProtocol layersProtocol layerseach layer wraps the one above in a headerHub vs switch vs routerHub vs switch vs routerL1 repeats, L2 learns MACs, L3 routes IPIGMP multicastIGMP multicastsnooping sends a group only to membersRapid Spanning TreeAlternate port takes over at onceLACP Link AggregationLACP Link AggregationOne flow rides one link, never moreVLANsVLANs802.1Q tag splits one switch into LANs802.1X and RADIUS802.1X and RADIUSPort stays closed until Access-AcceptARPARPbroadcast who-has IP, reply with the MACCRCCRCXOR division remainder catches bit errorsInternet ChecksumInternet ChecksumSum + NOT sum = 0xFFFF; blind to swapsWi-Fi CSMA/CAWi-Fi CSMA/CAlisten, random backoff, wait for the ACKBluetooth LE and GATTBluetooth LE and GATTWrite CCCD 0x0001, then values get pushedALOHA and CSMA/CDALOHA and CSMA/CDFrame must last 2τ to hear a collisionLoRaWAN class ALoRaWAN class ASend any time, listen only at RX1/RX2Cellular Reuse and HandoverCellular Reuse and HandoverMargin + timer: no ping-pong, no dropDigital modulation (QAM)Digital modulation (QAM)More bits per symbol needs more SNROpen the Networking mind mapNetworkingframes on one local networkLayers & linksProtocol layersProtocol layerseach layer wraps the one above in a headerHub vs switch vs routerHub vs switch vs routerL1 repeats, L2 learns MACs, L3 routes IPIGMP multicastIGMP multicastsnooping sends a group only to membersRapid Spanning TreeAlternate port takes over at onceLACP Link AggregationLACP Link AggregationOne flow rides one link, never moreVLANsVLANs802.1Q tag splits one switch into LANs802.1X and RADIUS802.1X and RADIUSPort stays closed until Access-AcceptARPARPbroadcast who-has IP, reply with the MACCRCCRCXOR division remainder catches bit errorsInternet ChecksumInternet ChecksumSum + NOT sum = 0xFFFF; blind to swapsWi-Fi CSMA/CAWi-Fi CSMA/CAlisten, random backoff, wait for the ACKBluetooth LE and GATTBluetooth LE and GATTWrite CCCD 0x0001, then values get pushedALOHA and CSMA/CDALOHA and CSMA/CDFrame must last 2τ to hear a collisionLoRaWAN class ALoRaWAN class ASend any time, listen only at RX1/RX2Cellular Reuse and HandoverCellular Reuse and HandoverMargin + timer: no ping-pong, no dropDigital modulation (QAM)Digital modulation (QAM)More bits per symbol needs more SNR
This page on the Networking mind map · 83 pages in 10 branches · open it to see the whole map and test yourself in recall mode.