Intermediate · Spanning Tree and EtherChannel · topic 27 of 57 · 35 min
Root bridge election, root ports and designated ports
Explanation
The bridge ID
STP uses the old word "bridge" for a switch. Each switch has an 8-byte bridge ID (BID): a 2-byte priority part followed by the 6-byte MAC address of the switch. When two BIDs are compared, the priority is compared first, and the MAC address only breaks a tie. Lower is better.
With Cisco's per-VLAN STP, the 2-byte priority part is split in two: a 4-bit priority and a 12-bit extended system ID, which is simply the VLAN number. So the priority you see is the configured priority plus the VLAN number. With the default priority 32768, a switch shows 32769 in VLAN 1 and 32778 in VLAN 10. Because only 4 bits are left for the real priority, you can set it only in steps of 4096: 0, 4096, 8192 ... 61440.
Step 1: elect the root bridge
At first, every switch claims to be the root and sends BPDUs saying so. When a switch hears a BPDU with a lower (better) root BID than its own, it stops claiming and passes on the better one. Soon all switches agree: the switch with the lowest BID is the root bridge. If nobody changed the priority, every switch has 32768 and the switch with the lowest MAC address wins, which is often the oldest, slowest switch in the building. That is why you choose the root yourself (next topic).
All ports of the root bridge are designated ports and forward.
Step 2: every other switch picks one root port
The root port is the port with the best path to the root bridge. "Best" means the lowest root path cost: the sum of the port costs of every link on the way to the root. Cost depends on link speed.
| Link speed | STP cost (short, 802.1D) |
|---|---|
| 10 Mbps | 100 |
| 100 Mbps | 19 |
| 1 Gbps | 4 |
| 10 Gbps | 2 |
If two ports have the same root path cost, the tie-breakers are, in order: the lowest neighbour (sender) bridge ID, then the lowest neighbour port priority (default 128), then the lowest neighbour port number. Note that these compare the values sent by the neighbour in its BPDU, not your own port numbers.
Step 3: one designated port per link
On every link (segment), exactly one port is the designated port: the one on the switch with the lowest root path cost for that link. It forwards traffic onto that link. If both switches have the same cost, the switch with the lower bridge ID wins.
Step 4: block the rest
Any port that is neither a root port nor a designated port is blocked (in RSTP it is called an alternate port). This is what breaks the loop.
Worked example: three switches in a triangle
SW1, SW2 and SW3 all have priority 32769 (VLAN 1). Their MACs are SW1 0011.1111.1111, SW2 0022.2222.2222, SW3 0033.3333.3333. All links are 1 Gbps (cost 4). Cabling: SW1 Gi0/1 to SW2 Gi0/1, SW1 Gi0/2 to SW3 Gi0/1, SW2 Gi0/2 to SW3 Gi0/2.
- Root bridge: all priorities are equal, so the lowest MAC wins: SW1.
- SW1 Gi0/1 and Gi0/2 are designated, because every port of the root bridge is designated.
- SW2 root port: direct via Gi0/1 costs 4; via SW3 (Gi0/2) costs 4 + 4 = 8. Root port is Gi0/1.
- SW3 root port: direct via Gi0/1 costs 4. Root port is Gi0/1.
- Link SW2 to SW3: both switches have root cost 4, a tie. The lower bridge ID is SW2, so SW2 Gi0/2 is designated.
- SW3 Gi0/2 is neither root nor designated: it is blocked. The loop is broken.
Now change one thing: the SW1 to SW2 link is only 100 Mbps (cost 19). SW2 compares 19 (direct) with 4 + 4 = 8 (through SW3), so its root port becomes Gi0/2. On the SW2 to SW3 link, SW3 now has the lower root cost (4 against 8), so SW3 Gi0/2 is designated. The SW1 to SW2 link has SW1 Gi0/1 as designated, and SW2 Gi0/1 is blocked. The slow link is the one that ends up unused, which is exactly what you want.
Common mistakes and how to fix them
- Thinking the highest priority wins. In STP, lower is always better: lower BID, lower cost.
- Adding the costs of the wrong ports. Root path cost adds the cost of each link on the way to the root, as seen by the receiving ports.
- Using your own port number as a tie-breaker. The tie-breaker is the neighbour's (sender's) port priority and number.
- Setting a priority like 10000. Only multiples of 4096 are accepted.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Root bridge election, root ports and designated ports · 1/7
In this lesson you will learn how spanning tree chooses the root bridge and which ports forward or block.
Prefer a video by a teacher? Find free videos on “spanning tree root bridge election root port designated port explained” on YouTube ↗
In real life: Why the oldest switch in a Pune office became the root
A logistics company in Pune grew from one switch to twelve over ten years and never touched STP settings. All switches kept priority 32768, so the root bridge was the switch with the lowest MAC address: a 2012-era 100 Mbps switch in a store room. All traffic between floors was crossing that old switch, and some fast 1 Gbps links were blocked. After one show spanning-tree on each switch, the engineer set the two new core switches as root primary and secondary. Traffic now flows through the core and the old switch was retired.
Practice (0/4 done)
Write stp_cost(speed_mbps) that returns the short (802.1D) STP port cost for a link speed: 10 gives 100, 100 gives 19, 1000 gives 4, 10000 gives 2. For any other speed return None.
Write elect_root(switches) where switches is a list of (name, priority, mac) tuples, with MACs written like "0019.e86a.6f80". Return the name of the root bridge: lowest priority first; if priorities tie, lowest MAC address.
Write root_port(options) for a non-root switch. Each option is (port, costs, sender_priority, sender_mac): costs is the list of link costs on that path to the root, and sender is the neighbour switch on that port. Return the port with the lowest total cost; if costs tie, the one whose sender has the lowest (priority, MAC).
Packet Tracer lab: connect three 2960 switches in a triangle with Gigabit links (SW1 Gi0/1 to SW2 Gi0/1, SW1 Gi0/2 to SW3 Gi0/1, SW2 Gi0/2 to SW3 Gi0/2). Before looking at the switches, write down the MAC of each switch (show version or show spanning-tree) and predict the root bridge, the root ports, the designated ports and the blocked port. Then check with show spanning-tree. Finally make SW3 the root with a priority command and predict again.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- STP port states, RSTP and Rapid PVST+Spanning Tree and EtherChannel · same module
- Protecting spanning tree: PortFast, BPDU Guard, Root Guard and Loop GuardSpanning Tree and EtherChannel · same module
- Trunks and 802.1Q taggingSwitching and VLANs
- OSPF concepts: link state, areas and neighboursRouting: static routes and OSPF
- Inter-VLAN routingSwitching and VLANs
- Layer 2 security: port security, DHCP snooping, DAINetwork security
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
Which switch becomes the root bridge?
Answer: The one with the lowest bridge ID
The lowest bridge ID (priority first, then MAC) wins.
A switch has the default priority. What priority does it show in VLAN 20?
Answer: 32788
Default 32768 plus the extended system ID (the VLAN number 20) gives 32788.
What is the short STP cost of a 100 Mbps link?
Answer: 19
With short costs, 100 Mbps is 19, 1 Gbps is 4 and 10 Gbps is 2.
Which priority value can you configure?
Answer: 8192
Priorities must be multiples of 4096; 8192 is 2 × 4096.
Two ports on a switch have the same root path cost. What is compared next?
Answer: The neighbour (sender) bridge ID
Next comes the lowest sender bridge ID, then the sender port priority, then the sender port number.
A switch log keeps saying a host is "flapping between port Gi0/1 and port Gi0/2". What does this suggest?Related
Answer: A layer 2 loop
MAC flapping means the same source MAC keeps arriving on different ports, a typical sign of a loop.
What priority does spanning-tree vlan 10 root secondary set?Related
Answer: 28672
root secondary sets 28672, just below the default 32768 and above the root primary value.
A frame to ffff.ffff.ffff arrives on port 5 of a 24-port switch (all in one VLAN). Where does it go?Related
Answer: All ports except port 5
Broadcasts are flooded out of every port except the incoming one.
show vlan brief does not list port Gi0/1 at all. What is the most likely reason?Related
Answer: Gi0/1 is a trunk port
show vlan brief lists access ports only. Trunk ports appear in show interfaces trunk.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 3 more topics in “Spanning Tree and EtherChannel” before its exam: STP port states, RSTP and Rapid PVST+, Protecting spanning tree: PortFast, BPDU Guard, Root Guard and Loop Guard, EtherChannel: bundling links.
- Module 6 exam: Spanning Tree and EtherChannel · 13 questions · 20 min, without help. 5 topics of this module still to finish first.
- Then the next module, Routing: static routes and OSPF. 57 topics left in the course before the final exam.