PacketLab
Switching · Spanning Tree

Path cost

Calculate each candidate root path before using port-ID tie breakers.

Independent lab examples; selected output and frame summaries are illustrative. Port naming and command support vary by switch and software release.

Network and objective

Classic PVST+ is used to expose original STP behavior; rapid-PVST+ and MST are separate lessons.

Use three fresh isolated switches with Gigabit trunks: SW1 Gi1/0/23 ↔ SW2 Gi1/0/23; SW1 Gi1/0/24 ↔ SW3 Gi1/0/24; SW2 Gi1/0/24 ↔ SW3 Gi1/0/23. Both VLANs10/20 exist on every switch. Baseline SW1/SW2/SW3 priorities are4096/8192/12288, with short costs and no extra links. Start independently from the included baseline for each lesson; subsequent repair snippets apply to the named device.

Ethernet switchingIllustrative topology
Physical links are solid; device roles and relevant links are labeled.
Physical links are solid; device roles and relevant links are labeled.

How it works

A receiver adds its incoming port cost to the root cost advertised in a BPDU. With short Gigabit cost4, SW3’s direct path to SW1 is4 and its path through SW2 is8. Raising the direct port’s cost to20 makes the path through SW2 preferable.

Compare root identity, total path cost, sender bridge ID and sender port ID in order; local receiving port ID resolves a remaining tie. Port priority does not override a lower path cost. Short and long cost scales use different values; choose and verify a consistent method rather than mixing a memorized table with actual output.

Configure or inspect

SW1

vlan 10
vlan 20
spanning-tree mode pvst
spanning-tree pathcost method short
spanning-tree vlan 10 priority 4096
spanning-tree vlan 20 priority 4096
interface range GigabitEthernet1/0/23 - 24
 switchport mode trunk
 switchport trunk allowed vlan 10,20
 switchport nonegotiate
 no shutdown
exit

SW2

vlan 10
vlan 20
spanning-tree mode pvst
spanning-tree pathcost method short
spanning-tree vlan 10 priority 8192
spanning-tree vlan 20 priority 8192
interface range GigabitEthernet1/0/23 - 24
 switchport mode trunk
 switchport trunk allowed vlan 10,20
 switchport nonegotiate
 no shutdown
exit

SW3

vlan 10
vlan 20
spanning-tree mode pvst
spanning-tree pathcost method short
spanning-tree vlan 10 priority 12288
spanning-tree vlan 20 priority 12288
interface range GigabitEthernet1/0/23 - 24
 switchport mode trunk
 switchport trunk allowed vlan 10,20
 switchport nonegotiate
 no shutdown
exit
interface GigabitEthernet1/0/24
 spanning-tree vlan 10 cost 20

Verify the result

Illustrative output · selected lines
SW3#show spanning-tree vlan 10
Interface           Role Sts Cost
Gi1/0/23            Root FWD 4
Gi1/0/24            Altn BLK 20
  Root path cost: 8

The winning root path is advertised4 plus local4 =8. The direct port still exists but its configured cost20 loses. This change affects VLAN10 only.

Failure and recovery

If the expected direct port does not win, inspect its explicit cost and the root advertised by its neighbor. Do not change port priority first when total costs differ.

SW3

interface GigabitEthernet1/0/24
 no spanning-tree vlan 10 cost

Further reading

Key Takeaways

  • Add local ingress cost to advertised root cost.
  • Short Gigabit cost4 is not the long-scale value.
  • The lab compares4,8 and20 explicitly.
  • Cost precedes sender/port tie breakers.
  • A VLAN-specific cost affects only that instance.

Path cost Quiz

Six questions · four options each · select one answer per question. Submit all answers to see your score and explanations.

1. What is the path through SW2?
2. What wins after direct cost becomes20?
3. Does port priority beat lower path cost?
4. Which scale is used here?
5. What does no spanning-tree vlan10 cost do?
6. What should be compared first?