Sub topic 3
The bridge ID and why priority comes first
This chapter assumes you know how switches learn MAC addresses, what a VLAN and a trunk are, and how to read a switch command line. It covers the bridge ID, the value every switch puts in its BPDUs to say who it is. The next chapter uses that value to elect the root bridge.
What the bridge ID is
Every switch running spanning tree identifies itself with a bridge ID (BID). The BID is 8 bytes long and has two parts:
- A 2-byte bridge priority field.
- A 6-byte MAC address, called the bridge address.
When two BIDs are compared, the lower value wins. The comparison reads the whole 8 bytes as one number, starting from the priority. The MAC address is examined only if the priorities are identical.
Why priority comes first
The priority sits in the most significant bytes, so it always outranks the MAC address. That ordering is deliberate. A MAC address is assigned at the factory. It tells you nothing about where a switch sits in your network. If the MAC address were compared first, the oldest switch, which often has the lowest MAC address, would tend to become root. That could be a slow access switch in a wiring closet.
Putting priority first gives the administrator control. You can lower the priority of the switch you want as root. The MAC address then works only as a tie-breaker, and it guarantees that two switches never produce identical BIDs.
The default priority is 32768. If you change nothing, every switch has the same priority, and the lowest MAC address decides the election. This is the most common source of an accidental root bridge.
The extended system ID
Per-VLAN spanning tree runs a separate tree for each VLAN, and each tree needs its own BID. The switch has only one MAC address to use. To make the BIDs differ per VLAN, the 2-byte priority field is split:
- The top 4 bits hold the configurable priority.
- The lower 12 bits hold the extended system ID, which is the VLAN number.
The bridge priority value in the field is therefore the configured priority plus the VLAN ID. Twelve bits can hold VLAN numbers up to 4095, which covers the full 802.1Q VLAN range.
Priority comes in steps of 4096
Only 4 bits are left for the configurable part, so only 16 values exist. Each step is 4096 (2^12), because the lowest 12 bits belong to the VLAN number.
| Step | Priority value |
|---|---|
| 0 | 0 |
| 1 | 4096 |
| 2 | 8192 |
| 3 | 12288 |
| 4 | 16384 |
| 5 | 20480 |
| 6 | 24576 |
| 7 | 28672 |
| 8 | 32768 (default) |
| 9 | 36864 |
| 10 | 40960 |
| 11 | 45056 |
| 12 | 49152 |
| 13 | 53248 |
| 14 | 57344 |
| 15 | 61440 |
Setting a value that is not a multiple of 4096 is rejected on a switch that uses the extended system ID.
A worked example
Take a switch with the default priority and a MAC address of 0011.2233.4455. In VLAN 10 its bridge priority is 32768 + 10 = 32778. In VLAN 20 it is 32788. The MAC address is the same in both.
Now compare it with a second switch whose MAC address is 0000.AAAA.0001 and whose priority is also the default:
- Both switches have a priority of 32768 plus the VLAN number, so the priority fields are equal in each VLAN.
- The comparison moves on to the MAC address.
0000.AAAA.0001is lower than0011.2233.4455, so the second switch has the better BID in both VLANs.
If you set the first switch to priority 4096 for VLAN 10, its bridge priority in that VLAN becomes 4106. That is lower than 32778, so the first switch now wins VLAN 10 whatever the MAC addresses are. VLAN 20 is unchanged, and the second switch still wins there.
Setting the priority
On Cisco IOS you can set the value directly, or use the macro that picks a value for you:
! Cisco IOS: set an explicit priority for VLAN 10 (multiple of 4096)
configure terminal
spanning-tree vlan 10 priority 4096
end
! Or let the switch choose a priority lower than the current root's
configure terminal
spanning-tree vlan 10 root primary
endThe root primary macro looks at the current root's priority and sets the local one lower. It normally sets 24576, or 4096 below the root's value if the root already uses 24576 or less. It runs once when you enter it. It does not keep adjusting if another switch later lowers its priority, so an explicit value is more predictable in a design you document.
On a Linux bridge the priority is a plain 16-bit number and the kernel does not split it for VLANs unless you configure per-VLAN spanning tree separately:
# Set the bridge priority on a Linux bridge (lower is better)
sudo ip link set dev br0 type bridge priority 4096
# Show the bridge ID as the kernel sees it
ip -d link show br0
bridge link showReading the bridge ID in output
The show spanning-tree vlan 10 command prints a Bridge ID block for the local switch, and a Root ID block for the current root. A trimmed example:
VLAN0010
Spanning tree enabled protocol rstp
Root ID Priority 4106
Address 0011.2233.4455
This bridge is the root
Bridge ID Priority 4106 (priority 4096 sys-id-ext 10)
Address 0011.2233.4455Read the priority line carefully. The first number, 4106, is the full value in the field. The text in brackets splits it into the configured priority (4096) and the extended system ID (10). If you expected to see 4096 and you see 4106, nothing is wrong.
Common mistakes
- Leaving the defaults. All switches have priority 32768, so the lowest MAC address wins. The root ends up wherever the oldest hardware is.
- Expecting a higher number to win. Lower is better, for both priority and MAC address.
- Entering a priority that is not a multiple of 4096. The switch rejects it.
- Comparing the printed priority across VLANs. The VLAN number is included, so 32778 in VLAN 10 and 32788 in VLAN 20 are not different configurations.
- Setting priority 0 everywhere. If every switch uses priority 0, the MAC address decides again. Give the intended root a lower value than its backup, for example 4096 and 8192.
Exercise
Switch A has priority 32768 and MAC address 0000.0C11.1111. Switch B has priority 32768 and MAC address 0000.0C22.2222. Both run VLAN 30 with the extended system ID. (a) What is each switch's bridge priority value in VLAN 30? (b) Which switch has the better BID? (c) You then set switch B to priority 8192 for VLAN 30. What is its new value, and which switch is better now?
Show answer
(a) Both have 32768 + 30 = 32798. (b) The priorities are equal, so the lower MAC address decides. Switch A, with 0000.0C11.1111, is better. (c) Switch B's value becomes 8192 + 30 = 8222. That is lower than 32798, so switch B is now better, regardless of MAC address.
Exercise
Why does the switch reject the command "spanning-tree vlan 10 priority 5000"?
Show answer
With the extended system ID, only the top 4 bits of the 16-bit priority field are configurable. The lower 12 bits carry the VLAN number. Valid priorities are therefore multiples of 4096 (0, 4096, 8192, and so on). 5000 is not a multiple of 4096.