Spanning Tree Port Election: A Worked 7-Switch Example
Root bridge, root ports, designated ports and blocked ports: worked out link by link, the way the exam asks
Spanning Tree Protocol (STP, IEEE 802.1D) stops Layer 2 loops by putting some switch ports into a blocking state. Every exam question about it, from "which port is the root port on SW3?" to "consider the switched network shown below", is solved with the same four elections in the same order. This guide states the rules exactly, then applies them to one 7-switch network, link by link, including the tie-breakers that catch most candidates out.
The four rules, in order
Run these in order; each step depends on the one before. (1) Elect one root bridge: the lowest bridge ID wins. (2) On every non-root switch, elect one root port: the port with the lowest total cost to the root. (3) On every link (segment), elect one designated port: the port on the switch with the lowest cost to the root. Every port on the root bridge is designated. (4) Every port that is neither a root port nor a designated port blocks.
Bridge ID = priority + MAC address
default priority 32768, plus the VLAN ID
(extended system ID), e.g. 32769 for VLAN 1
lowest priority wins; on a tie, lowest MAC wins
Root port ties 1. lowest root path cost
2. lowest NEIGHBOUR bridge ID
3. lowest NEIGHBOUR port priority (default 128)
4. lowest NEIGHBOUR port number
Designated ties 1. lowest root path cost of the switch on the link
2. lowest bridge ID
3. lowest port ID (priority, then number)Root port tie-breakers 2 to 4 compare values received from the neighbour (sender), not the local switch's own port numbers. Picking the local port with the lower number is the single most common STP exam mistake.
Port costs
Root path cost is the sum of the costs of the ports a BPDU enters on the way from the root, so it is counted on the receiving side of each link. Cisco switches use the short (802.1D-1998) costs by default; "spanning-tree pathcost method long" switches to the 802.1t values.
Link speed Short cost (default) Long cost
10 Mbps 100 2,000,000
100 Mbps 19 200,000
1 Gbps 4 20,000
10 Gbps 2 2,000Exam questions almost always use the short costs. If a question shows costs like 19 and 4, it is the short method; mixed speeds are where the cheapest path stops being the one with the fewest hops.
The example network
Seven switches, ten links, VLAN 1. SW3 has been configured with priority 4096 (bridge priority 4097 with VLAN 1); every other switch keeps the default 32769. MAC addresses increase from SW1 to SW7, so among the default-priority switches SW1 has the lowest bridge ID and SW7 the highest. Every link is 1 Gbps (cost 4) except the SW4 to SW5 link, which is 100 Mbps (cost 19). SW1 and SW3 are joined by two parallel links.
Gi0/1 ┌─────┐ Gi0/2
┌──────────────┤ SW3 ├──────────────┐
│ Gi0/4 │root │ │
│ ┌───────────┤ BID │ │
│ │ │4097 │ │
│ │ └─────┘ │
Gi0/1 Gi0/4 Gi0/1
┌─────┐ Gi0/2 Gi0/2 ┌─────┐
│ SW1 ├─────────────────────────────┤ SW2 │
└──┬──┘ └──┬──┘
Gi0/3 Gi0/3
│ │
Gi0/1 Gi0/1
┌─────┐ Gi0/2 100 Mbps Gi0/2 ┌─────┐
│ SW4 ├─────────────────────────────┤ SW5 │
└──┬──┘ └──┬──┘
Gi0/3 Gi0/3
│ │
Gi0/1 Gi0/1
┌─────┐ Gi0/2 Gi0/2 ┌─────┐
│ SW6 ├─────────────────────────────┤ SW7 │
└─────┘ └─────┘
Switch Priority MAC Bridge ID
SW1 32769 0000.0000.0011 32769.0000.0000.0011
SW2 32769 0000.0000.0022 32769.0000.0000.0022
SW3 4097 0000.0000.0033 4097.0000.0000.0033
SW4 32769 0000.0000.0044 32769.0000.0000.0044
SW5 32769 0000.0000.0055 32769.0000.0000.0055
SW6 32769 0000.0000.0066 32769.0000.0000.0066
SW7 32769 0000.0000.0077 32769.0000.0000.0077Step 1: elect the root bridge
Compare bridge IDs. Priority is compared first, so SW3 (4097) beats every switch at 32769, even though SW1 has a lower MAC address. SW3 is the root bridge. If nobody had changed a priority, SW1 would win on the lowest MAC, which is why real networks set the root priority deliberately instead of leaving it to the oldest switch.
SW3(config)# spanning-tree vlan 1 priority 4096
! or let IOS pick a value below the current root:
SW3(config)# spanning-tree vlan 1 root primaryPriority must be a multiple of 4096 (0, 4096, 8192 ... 61440); the VLAN ID is added on top automatically. That is why you see odd numbers like 4097 or 32769 in show output.
Step 2: elect a root port on every other switch
For each non-root switch, add up the cost of every path to SW3 and keep the cheapest. SW1 is the interesting one: both of its links to SW3 cost 4, through the same neighbour, so the costs and the neighbour bridge ID tie. The neighbour's port priorities tie too (128), so the decision falls to the neighbour's port number: SW3 Gi0/1 is lower than SW3 Gi0/4, so the SW1 port that receives from SW3 Gi0/1 becomes the root port. That is SW1 Gi0/1. Note SW4: the path through SW5 would be 8 + 19 = 27, far worse than 8 through SW1, which is what the slow link is there to show.
Switch Paths to the root (cost) Root port
SW1 Gi0/1 = 4, Gi0/4 = 4 -> tie on cost and Gi0/1
neighbour BID; neighbour port Gi0/1 < Gi0/4
SW2 Gi0/1 = 4, via SW1 Gi0/2 = 4 + 4 = 8 Gi0/1
SW4 via SW1 Gi0/1 = 4 + 4 = 8, via SW5 = 8 + 19 Gi0/1
SW5 via SW2 Gi0/1 = 4 + 4 = 8, via SW4 = 8 + 19 Gi0/1
SW6 via SW4 Gi0/1 = 8 + 4 = 12, via SW7 = 16 Gi0/1
SW7 via SW5 Gi0/1 = 8 + 4 = 12, via SW6 = 16 Gi0/1
Root path cost: SW1 4, SW2 4, SW4 8, SW5 8, SW6 12, SW7 12The root bridge has no root port. If an answer option gives SW3 a root port, it is wrong.
Step 3: elect a designated port on every link
Take each link in turn and ask which of its two switches is closer to the root. That switch's port on the link is designated. Every port on SW3 is designated, because the root has a cost of 0. Three links tie on cost: SW1 to SW2 (both 4), SW4 to SW5 (both 8) and SW6 to SW7 (both 12). Each tie goes to the lower bridge ID, so SW1, SW4 and SW6 win them.
Link Costs to root Designated port Other end
SW3–SW1 (Gi0/1) 0 vs 4 SW3 Gi0/1 SW1 Gi0/1 (root port)
SW3–SW1 (Gi0/4) 0 vs 4 SW3 Gi0/4 SW1 Gi0/4
SW3–SW2 0 vs 4 SW3 Gi0/2 SW2 Gi0/1 (root port)
SW1–SW2 4 vs 4 tie -> BID SW1 Gi0/2 SW2 Gi0/2
SW1–SW4 4 vs 8 SW1 Gi0/3 SW4 Gi0/1 (root port)
SW2–SW5 4 vs 8 SW2 Gi0/3 SW5 Gi0/1 (root port)
SW4–SW5 8 vs 8 tie -> BID SW4 Gi0/2 SW5 Gi0/2
SW4–SW6 8 vs 12 SW4 Gi0/3 SW6 Gi0/1 (root port)
SW5–SW7 8 vs 12 SW5 Gi0/3 SW7 Gi0/1 (root port)
SW6–SW7 12 vs 12 tie -> BID SW6 Gi0/2 SW7 Gi0/2A root port can never be the designated port on its own link: it faces the switch that is closer to the root. If you find yourself making one designated, recheck the costs.
Step 4: everything else blocks, then check your answer
Four ports are neither root nor designated: SW1 Gi0/4, SW2 Gi0/2, SW5 Gi0/2 and SW7 Gi0/2. They block (802.1D) and keep listening for BPDUs. Check: a loop-free tree over 7 switches uses exactly 6 links, and this network has 10, so exactly 4 links must have a blocked port. They do.
Switch Root port Designated Blocked
SW1 Gi0/1 Gi0/2, Gi0/3 Gi0/4
SW2 Gi0/1 Gi0/3 Gi0/2
SW3 (root) Gi0/1, Gi0/2, Gi0/4 none
SW4 Gi0/1 Gi0/2, Gi0/3 none
SW5 Gi0/1 Gi0/3 Gi0/2
SW6 Gi0/1 Gi0/2 none
SW7 Gi0/1 none Gi0/2
Blocked ports = links - (switches - 1) = 10 - 6 = 4Use the links-minus-(switches-minus-one) check on every port-election question. If your count of blocked links is different, you have made an election mistake somewhere.
Verify it on a switch
show spanning-tree lists every port with its role and state. Root ports show Root FWD, designated ports Desg FWD, and blocked ports show Altn BLK under Rapid PVST+ (BLK under classic 802.1D PVST+). The output below is what SW1 would show in this example.
SW1# show spanning-tree vlan 1
VLAN0001
Spanning tree enabled protocol rstp
Root ID Priority 4097
Address 0000.0000.0033
Cost 4
Port 1 (GigabitEthernet0/1)
Bridge ID Priority 32769 (priority 32768 sys-id-ext 1)
Address 0000.0000.0011
Interface Role Sts Cost Prio.Nbr Type
---------------- ---- --- --------- -------- ----
Gi0/1 Root FWD 4 128.1 P2p
Gi0/2 Desg FWD 4 128.2 P2p
Gi0/3 Desg FWD 4 128.3 P2p
Gi0/4 Altn BLK 4 128.4 P2pRSTP role names
Rapid STP (802.1w) runs the same elections but names the losing ports by what they offer. An alternate port receives a better BPDU from another switch, so it is a ready-made backup path to the root: all four blocked ports in this example are alternate ports. A backup port receives a better BPDU from its own switch, which only happens when two ports of one switch sit on the same shared segment (for example through a hub). Root and designated keep their names; the states collapse to discarding, learning and forwarding.
Key tips
Always elect in order: root bridge, root ports, designated ports, then everything else blocks.
Priority is compared before MAC address. A switch with a lower configured priority wins even with a higher MAC.
Root path cost is counted on the receiving port of each link; sum the costs along the path from the root.
Root port tie-breakers use the neighbour's bridge ID, port priority and port number, not the local switch's.
Every port on the root bridge is designated, and the root bridge has no root port.
Check your answer: blocked links = links - (switches - 1).
Frequently asked questions
How is the root bridge elected in STP?
Every switch starts by claiming to be root and advertising its bridge ID in BPDUs. The switch with the lowest bridge ID wins: priority is compared first (default 32768 plus the VLAN ID), and on a tie the lowest MAC address wins.
How do I find the root port on a switch?
Add up the port costs along each path from the switch to the root bridge and pick the port with the lowest total. If two ports tie, choose the one whose neighbour has the lowest bridge ID, then the lowest neighbour port priority, then the lowest neighbour port number.
What is the difference between a designated port and a root port?
A root port is the one port on a non-root switch that leads to the root bridge by the cheapest path. A designated port is the one port on each link that forwards traffic toward the rest of the network away from the root; it belongs to whichever switch on that link is closer to the root.
Why does the switch with the lower bridge ID win a designated port tie?
When both switches on a link have the same root path cost, STP needs a deterministic tie-breaker, and the lower bridge ID is the next value compared. Then port ID is used if the same switch has two ports on the link.
How many ports will be blocked in a switched network?
In a single VLAN with every link active, the number of links with a blocked port equals the number of links minus (the number of switches minus one). A 7-switch network with 10 links therefore has 4 blocked ports.
Related glossary terms
Dynamic route
A route that is automatically learned and updated by a router using a routing protocol, rather than being manually configured.
Bash script
A Bash script is a text file containing a sequence of commands for the Unix shell Bash, allowing users to automate repetitive tasks and streamline system administration on Linux and macOS.
File Transfer Protocol
File Transfer Protocol (FTP) is a standard network protocol used to transfer files between a client and a server over a TCP/IP network.
Public IP address
A globally unique IP address assigned to a device that allows it to communicate directly over the internet.
Persistent Disk
Persistent Disk is a durable, high-performance block storage service for Google Cloud virtual machines that retains data even after the VM is shut down or deleted.
Extensible Authentication Protocol
Extensible Authentication Protocol (EAP) is a flexible authentication framework used in network access control, particularly in wireless and point-to-point connections, that supports multiple authentication methods without requiring changes to the underlying protocol.
Practise with exam-style questions
Apply what you just learned with exam-style practice questions.