Spanning Tree Protocol exists to stop loops in a switched network with redundant links. To do that, it first picks a single reference point — the root bridge — and then every other switch works out its shortest path back to it. So the election isn't a formality: the root decides the entire tree.
What's actually being compared: the Bridge ID
Each switch has a Bridge ID, and the lowest one wins. The BID is two parts stuck together:
Bridge ID = Bridge Priority + MAC address
(2 bytes) (6 bytes)
Priority default ......... 32768
Priority steps ........... 4096 (0, 4096, 8192, 12288 ...)
Tiebreaker ............... lowest MAC address
Modern switches split that 2-byte priority into a 4-bit priority and a 12-bit extended system ID (the VLAN number). That's why you can only set priority in multiples of 4096 — the lower 12 bits are spoken for.
How the election plays out
When the network comes up, every switch assumes it's the root and says so in the BPDUs (Bridge Protocol Data Units) it sends every 2 seconds. As a switch receives BPDUs, it compares the advertised root BID to the best one it has seen. The moment it hears a lower BID, it stops claiming to be root and instead relays that better BID onward. Very quickly, the whole network agrees on the single lowest BID — that switch is the root bridge.
The tiebreaker: lowest MAC address
If two switches share the same priority (and out of the box, they all sit at 32768), the lowest MAC address wins. MACs tend to be lower on older hardware — so left to default, your oldest switch can quietly become the root of your network, which is rarely where you want all traffic converging.
Forcing the root bridge (do this)
Pick the switch you actually want as root — usually a core/distribution switch — and lower its priority:
SW1(config)# spanning-tree vlan 1 priority 4096 ! or let IOS choose a low value automatically: SW1(config)# spanning-tree vlan 1 root primary
Verify with show spanning-tree — the root switch reports "This bridge is the root."