Sub topic 4
Electing the root bridge
This chapter assumes you know how switches learn MAC addresses and flood unknown frames. It also assumes you can read a switch command line and know what a VLAN is. You have already seen that BPDUs carry bridge IDs. This chapter shows how switches use those IDs to agree on one root bridge.
Why there must be one root
Spanning tree turns a looped topology into a loop-free tree, and a tree needs a single trunk to grow from. The root bridge is that starting point. Every other switch measures its distance to the root and keeps only its best path toward it. No switch is configured as the root by default. The switches elect one by comparing bridge IDs.
What gets compared
Each switch has a bridge ID made of two parts:
- A 16-bit priority field. The top 4 bits are the configurable priority. The low 12 bits are the extended system ID, which holds the VLAN number.
- The 48-bit MAC address of the switch.
The lowest bridge ID wins. The priority is compared first, and the MAC address is used only when priorities are equal.
The default priority is 32768. With the extended system ID added, the value you see for VLAN 10 is 32768 + 10 = 32778. Because only the top 4 bits are configurable, priorities move in steps of 4096: 0, 4096, 8192, and so on up to 61440.
| Switch | Configured priority | VLAN | Priority shown | MAC address |
|---|---|---|---|---|
| SW1 | 32768 | 10 | 32778 | 0011.2233.4401 |
| SW2 | 32768 | 10 | 32778 | 0011.2233.4402 |
| SW3 | 4096 | 10 | 4106 | 00aa.bbcc.ddee |
SW3 wins because 4106 is the lowest priority value. If SW3 did not exist, SW1 would win. SW1 and SW2 tie on priority, and SW1 has the lower MAC address.
How the election runs
There is no voting round and no central coordinator. Each switch follows one rule:
- At startup, every switch assumes it is the root. It sends BPDUs with its own bridge ID in both the root ID field and the sender ID field.
- When a switch receives a BPDU whose root ID is lower than the root ID it currently believes in, it adopts the lower one.
- After adopting a better root, the switch stops originating BPDUs. It relays the root's BPDUs out its designated ports, updating the cost and sender fields.
- A switch that receives an inferior BPDU (a higher root ID) ignores it and keeps advertising its own better information.
Better information flows outward from the winner. Within a few hello intervals, every switch has heard the lowest ID and agrees.
Reading the result
On a Cisco switch, the root ID block shows who the switch believes is root. The bridge ID block shows the switch's own ID. When the two match, the switch is the root.
SW3# show spanning-tree vlan 10
VLAN0010
Spanning tree enabled protocol rstp
Root ID Priority 4106
Address 00aa.bbcc.ddee
This bridge is the root
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 4106 (priority 4096 sys-id-ext 10)
Address 00aa.bbcc.ddee
Hello Time 2 sec Max Age 20 sec Forward Delay 15 secOn SW1, the same command would show the root ID block with priority 4106 and the address of SW3. It would also show a "Root port" line naming the interface that leads toward SW3. The bridge ID block would show 32778 and SW1's own MAC address.
Choosing the root on purpose
Left at defaults, the switch with the lowest MAC address wins. That is often the oldest switch, because older hardware tends to have lower MAC addresses. An old access switch can end up as the root, and then traffic between distribution switches may take a path through it. Set the root deliberately.
You have two ways to do it:
! Cisco IOS: use Rapid PVST+ and make this switch the root for VLAN 10
configure terminal
spanning-tree mode rapid-pvst
spanning-tree vlan 10 root primary
end
! Or set the priority explicitly (must be a multiple of 4096)
configure terminal
spanning-tree vlan 10 priority 4096
endThe root primary macro looks at the current root's priority when you run it. If that priority is above 24576, it sets this switch to 24576. If the current root is already at or below 24576, it sets this switch 4096 lower than the current root. The macro runs once and writes a fixed priority into the configuration. It does not keep adjusting if someone else later lowers their priority.
A common design is:
- Primary root: priority 4096 or
root primary. - Backup root: priority 8192, or
root secondary, which sets 28672. - Everything else: leave at the default 32768.
Pick a primary and a backup that are both in the core or distribution layer, directly connected to each other. If the primary fails, the backup is then already the best next choice.
On a Linux bridge, the equivalent setting is the bridge priority:
sudo ip link set dev br0 type bridge priority 4096Linux uses a 16-bit priority value without the VLAN extension, so the number you set is the number that is compared.
Edge cases and gotchas
- A new switch can take over the root. The election never stops. If you plug in a switch with a lower bridge ID, such as a lab switch at default priority with a low MAC address, the whole network re-elects it. Root Guard and BPDU Guard, covered later, defend against this. A cheap precaution is to set the priority on core switches explicitly rather than leaving it at the default.
- Priority 0 is not special. It is the lowest value, so it wins every election. That removes the room to place a switch above it later. Use 4096 for the primary and keep 0 in reserve.
- Each VLAN has its own election in PVST+ and Rapid PVST+. The extended system ID makes the bridge IDs differ per VLAN, and you can choose different roots for different VLANs. The
spanning-tree vlan 10command only affects VLAN 10. - Mismatched modes. Switches running different STP variants still interoperate, but the result is often slower convergence and confusing output. Set the same mode everywhere.
- Root failure. If the root stops sending BPDUs, other switches wait for the max age timer (20 seconds by default) before they discard the stored root information. Then they run a new election. Rapid STP shortens this wait considerably.
Summary of the key rules
- Lowest bridge ID wins. Priority is compared before MAC address.
- The priority field includes the VLAN number, so VLAN 10 at the default shows 32778.
- Every switch starts by claiming to be root. Better BPDUs replace that claim.
- Set a primary and backup root explicitly, in multiples of 4096.
Exercise
In VLAN 20, SW1 has priority 32768 and MAC aaaa.0000.0001. SW2 has priority 28672 and MAC cccc.0000.0002. SW3 has priority 28672 and MAC bbbb.0000.0003. Which switch is the root, and what priority value does it show in show spanning-tree vlan 20?
Show answer
SW3 is the root. SW2 and SW3 both have priority 28672, which is lower than SW1's 32768, so SW1 is out. Their displayed priority is the same, 28672 + 20 = 28692, so the MAC address decides. bbbb.0000.0003 is lower than cccc.0000.0002, so SW3 wins. It shows priority 28692.
Exercise
You run spanning-tree vlan 10 root primary on a switch, and the current root has priority 4096. What priority does your switch get, and will it become the root?
Show answer
The macro cannot set a value below the current root's priority by 4096 here, because 4096 minus 4096 is 0, which is the lowest possible value. The result depends on the platform. Do not rely on the macro in this case. Set an explicit priority of 0 only if you really intend to override the current root, and understand that it leaves no room for further changes.