Sub topic 5
Path cost and root path cost
This chapter assumes you know how a root bridge is elected and what a BPDU carries. Once the root exists, every other switch must decide which of its links gives the best route back to it. Path cost is the number that makes that decision.
Port cost
Each switch port has a path cost, a number derived from the link speed. Faster links get lower costs, and spanning tree prefers the lowest total. IEEE 802.1D originally defined a short scale. The newer long scale (802.1t) exists because 10 Gbps links would otherwise all collapse to the same tiny number.
| Link speed | Short cost | Long cost |
|---|---|---|
| 10 Mbps | 100 | 2,000,000 |
| 100 Mbps | 19 | 200,000 |
| 1 Gbps | 4 | 20,000 |
| 10 Gbps | 2 | 2,000 |
Classic STP on Cisco IOS uses the short scale. Rapid PVST+ and MSTP use the long scale by default. A mismatch between switches that use different scales can produce odd path choices, so keep the method consistent across the domain.
Root path cost
The root path cost is the total cost from a switch to the root bridge. It is built up hop by hop:
- The root bridge sends BPDUs with a root path cost of 0.
- A switch receiving a BPDU adds the cost of the port it arrived on.
- The switch sends its own BPDUs out its other ports carrying that new total.
The cost is added on the receiving side of each link, not the sending side. A switch's own outgoing port cost is never part of the sum it advertises.
Worked example
Switch B has two paths to root R. One is a direct 100 Mbps link. The other goes through switch A over two Gigabit links.
- A receives R's BPDU (cost 0) on a Gigabit port and adds 4. A's root path cost is 4.
- B receives R's BPDU directly on a Fast Ethernet port: 0 + 19 = 19.
- B receives A's BPDU (cost 4) on a Gigabit port: 4 + 4 = 8.
B picks the lower total, 8, so its root port faces A. The direct link has fewer hops but a higher cost, so it is not chosen. Spanning tree counts cost, not hop count.
Viewing and changing cost
show spanning-tree vlan 10
show spanning-tree interface GigabitEthernet0/1
configure terminal
interface GigabitEthernet0/1
spanning-tree vlan 10 cost 8
endIn the output, the Root ID section shows the Cost to the root. The port table shows each port's own cost. Setting a manual cost changes only that port's contribution. This lets you steer traffic, for example making a backup link less attractive per VLAN.
When two paths have equal root path cost, spanning tree falls back to tie-breakers, which the chapter on port selection covers.
Exercise
A switch receives a BPDU on a 10 Gbps port (short cost 2) with root path cost 4. A second BPDU arrives on a 1 Gbps port (short cost 4) with root path cost 0. Which port becomes the root port, and what root path cost does the switch advertise?
Show answer
The first path totals 4 + 2 = 6. The second totals 0 + 4 = 4. The 1 Gbps port has the lower total, so it becomes the root port, and the switch advertises a root path cost of 4.