STP Root Port Election Worked Example: Cost, Neighbor BID, and Port ID

Calculate root ports on six switches using cost, neighbor BID, and sender port ID. Check real outputs, then change one cost to move SW4’s root port.

STP root port calculation worked example cover: cost, neighbor BID, and sender port ID, proved with show spanning-tree
Lab topology: six IOL-L2 switches SW1 to SW6 in VLAN 10; SW1 is root; SW4 elects root port by path cost, SW5 by neighbor bridge ID, SW6 by sender port ID; a cost change moves SW4 root port

SW4, SW5, and SW6 each have two upstream links. Each switch ends up with one root port, but a different comparison settles each choice: path cost, neighbor bridge ID, or the neighbor's port ID.

Work through the six-switch diagram before checking the outputs. You will calculate the VLAN 10 tree, mark every link endpoint, then predict how one cost change moves SW4's root port. The recorded switches run Rapid PVST+; their output identifies the protocol as RSTP.

!Six-switch VLAN 10 exercise: SW1 connects to SW2 and SW3; both connect to SW4 and SW5; SW3 has two separate links to SW6.

Draw SW1 at the top, SW2 and SW3 beneath it, and SW4 and SW5 at the bottom. Connect each bottom switch to both middle switches. Place SW6 beside SW3 and connect them with two separate links. Crossing lines are not junctions. There is no SW2–SW3 link and no SW4–SW5 link.

All eight links are access links in VLAN 10. The two SW3–SW6 links are separate STP segments, with no EtherChannel. There are no end hosts or routed links in this exercise.

Link Endpoint A Endpoint B
L1 SW1 Et0/1 SW2 Et0/1
L2 SW1 Et0/2 SW3 Et0/1
L3 SW2 Et0/2 SW4 Et0/1
L4 SW2 Et0/3 SW5 Et0/1
L5 SW3 Et0/2 SW4 Et0/2
L6 SW3 Et0/3 SW5 Et0/2
L7 SW3 Et1/0 SW6 Et0/1
L8 SW3 Et1/1 SW6 Et0/2

Et is the CLI abbreviation for Ethernet. On SW3, Et1/0 and Et1/1 are the two ports toward SW6.

Use the costs below and the bridge IDs in Step 1 to answer four questions:

  1. Which switch is the root bridge?
  2. What is the root port and total root path cost on every other switch?
  3. Which endpoint is designated on each segment, and which ports block?
  4. What changes if only SW4 Et0/1 moves from cost 40 to cost 5?

If you need a refresher on the role names, keep STP port roles explained beside the exercise.

Cost table: use the configured short-method values

The lab uses the short path-cost method with explicit per-interface costs. These are configured values, not a speed-to-default-cost table. Use the recorded costs rather than assigning costs from interface names or advertised capabilities.

Link Local cost at endpoint A Local cost at endpoint B
L1: SW1–SW2 10 10
L2: SW1–SW3 10 10
L3: SW2–SW4 10 40
L4: SW2–SW5 10 10
L5: SW3–SW4 10 10
L6: SW3–SW5 10 10
L7: SW3–SW6, first link 10 10
L8: SW3–SW6, second link 10 10

For a root-port candidate, add the sender's advertised root path cost + the receiving interface's local cost. Costs are local: L3 costs 10 at SW2 and 40 at SW4.

A port ID contains a port priority and port number. SW3's two ports toward SW6 deliberately have different priorities: Et1/0 is 192.5, while Et1/1 is 64.6. Compare the priority first, then the port number. The full port ID 64.6 is lower than 192.5.

Pause here if you want to solve the spanning tree port election as a class exercise. Record one reason beside each winning port before reading on.

Step 1 — elect the root bridge

The bridge ID (BID) compares priority first, then MAC address. With the VLAN system ID extension enabled, VLAN 10 adds 10 to each configured bridge priority. The following values come from the recorded bridge output; the full outputs appear in the proof section.

Switch Configured priority VLAN extension Effective priority Bridge MAC Complete BID: effective priority / MAC
SW1 4096 10 4106 aabb.cc00.0100 4106 / aabb.cc00.0100
SW2 8192 10 8202 aabb.cc00.0200 8202 / aabb.cc00.0200
SW3 12288 10 12298 aabb.cc00.0300 12298 / aabb.cc00.0300
SW4 16384 10 16394 aabb.cc00.0400 16394 / aabb.cc00.0400
SW5 20480 10 20490 aabb.cc00.0500 20490 / aabb.cc00.0500
SW6 24576 10 24586 aabb.cc00.0600 24586 / aabb.cc00.0600

SW1 is the root bridge: 4106 is the lowest effective priority. No MAC tie-break is needed because every configured priority is different. SW1's root path cost is 0, and it has no root port.

Do not confuse the root BID with the sender BID. SW2 and SW3 both advertise SW1 as root, but each identifies itself as the bridge sending the BPDU.

Step 2 — calculate every non-root switch's root port

All candidates used below identify the same root, SW1. Compare total path cost first, then sender BID, then sender port ID. Stop as soon as a comparison produces a winner. The later receiving-port-ID tie-breaker is not reached anywhere in this exercise.

SW1 advertises root path cost 0. Each middle switch adds 10 on its direct receiving interface:

Switch Receiving port Sender Calculation Root port / root path cost
SW2 Et0/1 SW1 Et0/1 0 + 10 = 10 Et0/1 / 10
SW3 Et0/1 SW1 Et0/2 0 + 10 = 10 Et0/1 / 10

Any independent route through a bottom switch would cost more. Once the tree has settled, those bottom switches have cost 20; adding another local cost of 10 would give 30. That arithmetic is a check on the drawing, not a claim that a middle switch receives a superior BPDU on a designated port. A route that returns through the switch doing the calculation is not an independent path to the root.

SW4: cost beats the lower neighbor BID

Receiving port Sender Sender root cost Local cost Total
Et0/1 SW2 Et0/2 10 40 50
Et0/2 SW3 Et0/2 10 10 20

SW4 selects Et0/2 toward SW3, with total root path cost 20. SW2 has a lower BID than SW3, but the costs are unequal. The BID comparison never gets a vote here. Et0/1 becomes alternate.

SW5: equal costs, lowest neighbor bridge ID

Receiving port Sender Calculation Sender BID
Et0/1 SW2 Et0/3 10 + 10 = 20 8202 / aabb.cc00.0200
Et0/2 SW3 Et0/3 10 + 10 = 20 12298 / aabb.cc00.0300

Both totals are 20. Compare the neighbors' BIDs: SW2's effective priority 8202 is lower than SW3's 12298. SW5 selects Et0/1 toward SW2. Et0/2 becomes alternate.

This is the lowest-neighbor-bridge-ID root-port election case. It does not require comparing MAC addresses: priority already settles the BID comparison.

SW6: equal costs and sender BID, lowest sender port ID

Receiving port on SW6 Sender port on SW3 Calculation Sender BID Sender port ID
Et0/1 Et1/0 10 + 10 = 20 12298 / aabb.cc00.0300 192.5
Et0/2 Et1/1 10 + 10 = 20 12298 / aabb.cc00.0300 64.6

The costs tie, and both BPDUs come from SW3. Compare SW3's sending port IDs: 64.6 beats 192.5, so SW6 selects Et0/2. Et0/1 becomes alternate.

SW6's own port IDs are 128.2 on Et0/1 and 128.3 on Et0/2. The higher local number wins because the sender's port ID is compared earlier. Choosing the lowest local interface number would give the wrong answer.

The relevant SW3 configuration is:

interface Ethernet1/0
 description to_SW6_Ethernet0/1
 switchport access vlan 10
 switchport mode access
 spanning-tree vlan 10 port-priority 192
 spanning-tree vlan 10 cost 10
!
interface Ethernet1/1
 description to_SW6_Ethernet0/2
 switchport access vlan 10
 switchport mode access
 spanning-tree vlan 10 port-priority 64
 spanning-tree vlan 10 cost 10
!

The three deliberate contests are SW4 by cost, SW5 by neighbor BID, and SW6 by sender port ID. SW2 and SW3 also win on cost through their direct links to SW1.

Step 3 — mark designated and alternate ports on every segment

For the designated-port election, compare each endpoint's own advertised root path cost on that segment. If costs tie, compare sender BID, then sender port ID. Do not add the other endpoint's receiving cost for this election.

Every designated election here is settled by advertised root cost: SW1 advertises 0, SW2 and SW3 advertise 10, and the bottom switches advertise 20.

Segment Endpoint A root cost Endpoint B root cost Endpoint A role / state Endpoint B role / state
L1: SW1 Et0/1 — SW2 Et0/1 0 10 Designated / FWD Root / FWD
L2: SW1 Et0/2 — SW3 Et0/1 0 10 Designated / FWD Root / FWD
L3: SW2 Et0/2 — SW4 Et0/1 10 20 Designated / FWD Alternate / BLK
L4: SW2 Et0/3 — SW5 Et0/1 10 20 Designated / FWD Root / FWD
L5: SW3 Et0/2 — SW4 Et0/2 10 20 Designated / FWD Root / FWD
L6: SW3 Et0/3 — SW5 Et0/2 10 20 Designated / FWD Alternate / BLK
L7: SW3 Et1/0 — SW6 Et0/1 10 20 Designated / FWD Alternate / BLK
L8: SW3 Et1/1 — SW6 Et0/2 10 20 Designated / FWD Root / FWD

A non-designated endpoint can still forward as a root port. The three losing root-port candidates on SW4, SW5, and SW6 are alternate ports and discard data traffic. This IOS output labels their state BLK. No backup role appears in this topology.

Notice that both SW3 ports toward SW6 are designated and forwarding. SW6 blocks one endpoint of one link; SW3 does not have to block its matching endpoint.

Check the count: eight segments give eight designated ports. Five non-root switches give five root ports. The remaining three endpoints are alternate: 8 + 5 + 3 = 16.

Prove it: match the calculation to all six switches

These are recorded device outputs from the settled baseline. The excerpts preserve the output lines, including spacing. A line containing only ... marks omitted lines. Commands shown with their output were run at the named switch's privileged EXEC prompt.

Read the Cost field under Root ID as the switch's cumulative root path cost. The Cost column beside each interface is only that interface's local cost. Prio.Nbr in the main table is the local port ID; the detail output's designated port ID identifies the upstream sender on the root and alternate ports below.

SW1: the root, with both ports designated

show spanning-tree

VLAN0010
  Spanning tree enabled protocol rstp
  Root ID    Priority    4106
             Address     aabb.cc00.0100
             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     aabb.cc00.0100
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  300 sec

Interface           Role Sts Cost      Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Et0/1               Desg FWD 10        128.2    P2p 
Et0/2               Desg FWD 10        128.3    P2p 


SW1#

SW2: Et0/1 is root, total cost 10

show spanning-tree

VLAN0010
  Spanning tree enabled protocol rstp
  Root ID    Priority    4106
             Address     aabb.cc00.0100
             Cost        10
             Port        2 (Ethernet0/1)
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    8202   (priority 8192 sys-id-ext 10)
             Address     aabb.cc00.0200
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  300 sec

Interface           Role Sts Cost      Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Et0/1               Root FWD 10        128.2    P2p 
Et0/2               Desg FWD 10        128.3    P2p 
Et0/3               Desg FWD 10        128.4    P2p 


SW2#
show spanning-tree

VLAN0010
  Spanning tree enabled protocol rstp
  Root ID    Priority    4106
             Address     aabb.cc00.0100
             Cost        10
             Port        2 (Ethernet0/1)
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    12298  (priority 12288 sys-id-ext 10)
             Address     aabb.cc00.0300
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  300 sec

Interface           Role Sts Cost      Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Et0/1               Root FWD 10        128.2    P2p 
Et0/2               Desg FWD 10        128.3    P2p 
Et0/3               Desg FWD 10        128.4    P2p 
Et1/0               Desg FWD 10        192.5    P2p 
Et1/1               Desg FWD 10         64.6    P2p 


SW3#

SW4: Et0/2 wins on cost

show spanning-tree

VLAN0010
  Spanning tree enabled protocol rstp
  Root ID    Priority    4106
             Address     aabb.cc00.0100
             Cost        20
             Port        3 (Ethernet0/2)
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    16394  (priority 16384 sys-id-ext 10)
             Address     aabb.cc00.0400
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  300 sec

Interface           Role Sts Cost      Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Et0/1               Altn BLK 40        128.2    P2p 
Et0/2               Root FWD 10        128.3    P2p 


SW4#

The detail output exposes the two received candidates: the local costs differ, while both designated path costs are 10.

show spanning-tree detail
...
 Port 2 (Ethernet0/1) of VLAN0010 is alternate blocking 
   Port path cost 40, Port priority 128, Port Identifier 128.2.
   Designated root has priority 4106, address aabb.cc00.0100
   Designated bridge has priority 8202, address aabb.cc00.0200
   Designated port id is 128.3, designated path cost 10
...
 Port 3 (Ethernet0/2) of VLAN0010 is root forwarding 
   Port path cost 10, Port priority 128, Port Identifier 128.3.
   Designated root has priority 4106, address aabb.cc00.0100
   Designated bridge has priority 12298, address aabb.cc00.0300
   Designated port id is 128.3, designated path cost 10
...

SW5: Et0/1 wins on neighbor BID

show spanning-tree

VLAN0010
  Spanning tree enabled protocol rstp
  Root ID    Priority    4106
             Address     aabb.cc00.0100
             Cost        20
             Port        2 (Ethernet0/1)
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    20490  (priority 20480 sys-id-ext 10)
             Address     aabb.cc00.0500
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  300 sec

Interface           Role Sts Cost      Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Et0/1               Root FWD 10        128.2    P2p 
Et0/2               Altn BLK 10        128.3    P2p 


SW5#

Here the local and designated path costs tie. The designated bridge fields identify SW2 and SW3, so their BIDs settle the choice.

show spanning-tree detail
...
 Port 2 (Ethernet0/1) of VLAN0010 is root forwarding 
   Port path cost 10, Port priority 128, Port Identifier 128.2.
   Designated root has priority 4106, address aabb.cc00.0100
   Designated bridge has priority 8202, address aabb.cc00.0200
   Designated port id is 128.4, designated path cost 10
...
 Port 3 (Ethernet0/2) of VLAN0010 is alternate blocking 
   Port path cost 10, Port priority 128, Port Identifier 128.3.
   Designated root has priority 4106, address aabb.cc00.0100
   Designated bridge has priority 12298, address aabb.cc00.0300
   Designated port id is 128.4, designated path cost 10
...

SW6: Et0/2 wins on sender port ID

show spanning-tree

VLAN0010
  Spanning tree enabled protocol rstp
  Root ID    Priority    4106
             Address     aabb.cc00.0100
             Cost        20
             Port        3 (Ethernet0/2)
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    24586  (priority 24576 sys-id-ext 10)
             Address     aabb.cc00.0600
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  300 sec

Interface           Role Sts Cost      Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Et0/1               Altn BLK 10        128.2    P2p 
Et0/2               Root FWD 10        128.3    P2p 


SW6#

Both designated bridge fields identify SW3. The designated port IDs, 192.5 and 64.6, settle the tie.

show spanning-tree detail
...
 Port 2 (Ethernet0/1) of VLAN0010 is alternate blocking 
   Port path cost 10, Port priority 128, Port Identifier 128.2.
   Designated root has priority 4106, address aabb.cc00.0100
   Designated bridge has priority 12298, address aabb.cc00.0300
   Designated port id is 192.5, designated path cost 10
...
 Port 3 (Ethernet0/2) of VLAN0010 is root forwarding 
   Port path cost 10, Port priority 128, Port Identifier 128.3.
   Designated root has priority 4106, address aabb.cc00.0100
   Designated bridge has priority 12298, address aabb.cc00.0300
   Designated port id is 64.6, designated path cost 10
...

Cost change exercise: move SW4's root port

Keep every other setting the same. Change only SW4 Et0/1 from cost 40 to cost 5. Before checking the capture, calculate both candidates again:

SW4 measurement Before After
Total via SW2 on Et0/1 10 + 40 = 50 10 + 5 = 15
Total via SW3 on Et0/2 10 + 10 = 20 10 + 10 = 20
Root port Et0/2 Et0/1
Alternate port Et0/1 Et0/2
Root path cost 20 15

The before-state capture on SW4 shows:

show spanning-tree vlan 10

VLAN0010
  Spanning tree enabled protocol rstp
  Root ID    Priority    4106
             Address     aabb.cc00.0100
             Cost        20
             Port        3 (Ethernet0/2)
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    16394  (priority 16384 sys-id-ext 10)
             Address     aabb.cc00.0400
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  300 sec

Interface           Role Sts Cost      Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Et0/1               Altn BLK 40        128.2    P2p 
Et0/2               Root FWD 10        128.3    P2p 


SW4#

At SW4's CLI, the recorded change and save were:

configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
SW4(config)#
interface Ethernet0/1
SW4(config-if)#
spanning-tree vlan 10 cost 5
SW4(config-if)#
end
SW4#
write memory
Building configuration...
[OK]
SW4#

The captured result after the change matches the prediction:

show spanning-tree vlan 10

VLAN0010
  Spanning tree enabled protocol rstp
  Root ID    Priority    4106
             Address     aabb.cc00.0100
             Cost        15
             Port        2 (Ethernet0/1)
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    16394  (priority 16384 sys-id-ext 10)
             Address     aabb.cc00.0400
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  300 sec

Interface           Role Sts Cost      Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Et0/1               Root FWD 5         128.2    P2p 
Et0/2               Altn BLK 10        128.3    P2p 


SW4#

SW4 now reaches SW1 through SW2 at cost 15. Its Et0/2 cost stays 10, but that candidate still totals 20. SW2's local cost on the opposite end of the changed link stays 10; an interface cost change is local to the receiving switch.

SW2 and SW3 remain designated toward SW4 because each advertises cost 10, lower than SW4's new cost 15. The remaining post-change captures show SW1 still root, SW2 and SW3 still at cost 10, and SW5 and SW6 still at cost 20, with their roles unchanged. Comparing the six before-and-after configurations shows only SW4's cost line changed.

The recorded exercise ends with cost 5 saved. The first six output blocks describe the baseline; the last block describes the changed tree.

Quick checklist for an STP calculation exam question

  • Identify the VLAN and elect the root from the complete BID. Include the VLAN system ID extension when reading the displayed priority.
  • Add the sender's advertised cost to the receiving port's local cost. Keep that total separate from the interface Cost column.
  • With the same root ID, compare total cost, sender BID, then sender port ID. Stop at the first difference.
  • Compare port priority before port number. In this exercise, sender 64.6 beats sender 192.5.
  • Keep sender and local port IDs separate. SW6 selects local 128.3 because it receives sender 64.6.
  • Elect one designated endpoint per segment. A root port is a forwarding, non-designated endpoint; an alternate port discards data traffic.
  • Count the results: one root bridge, five root ports, eight designated ports, and three alternates in this baseline.

For more practice, cover the answer tables and redraw the tree twice: once with SW4 Et0/1 at cost 40, then at cost 5. Keep SW5 and SW6's tie-breakers unchanged. The PingLabz spanning-tree guide links the wider STP series.

Read next