Spanning Tree Algorithm – Path Cost
When a loop occurs in the switched network, the STP uses path cost to resolve the ports state. Path cost is obtained from the speed of the port. If all of the connected ports have the same path cost values, then the spanning tree puts the lowest numbered port into the forwarding state. The path information is determined using the sum of the individual port costs along the path from the destination to the root bridge. Each “destination” is a switch port. The default port costs are defined from the speed of the port operates. The table below illustrates the default port cost of the Cisco switches.
Link Speed | Default Cost (According to old specification) | Default Cost (Revised ) |
10 Gbps | 1 | 2 |
1 Gbps | 1 | 4 |
100 Mbps | 10 | 19 |
10 Mbps | 100 | 100 |
As shown in the table, 10 Gb/s Ethernet ports have a port cost of 2, 1 Gb/s Ethernet ports have a port cost of 4, 100 Mb/s Fast Ethernet ports have a port cost of 19, and 10 Mb/s Ethernet ports have a port cost of 100. So if the speed is slow then the cost is greater for the spanning-tree algorithm.
The IEEE revised the values of cost to accommodate the 10 Gigabits Ethernet standards. As newer and faster Ethernet technologies enter the marketplace, the path cost values may again be revised to accommodate new standards. The default cost of the port is associated with the port but we can manually configure the cost value for any port to control the spanning-tree paths to the root bridge. We can configure the port cast in interface configuration mode. The cost value must be between 1 and 200, 000, 000. To restore the default port cost value, enter the “no spanning-tree cost” in interface configuration mode.
Path Cost Calculation
Paths with the lowest cost become the preferred path. Remaining paths to the root bridge are blocked. Now lookit the below image, and analyze the all paths from all switches to the root bridge:-
Switch-2
Switch-2 has three ways to towards Root Bridge.
- Fa0/3 (Fast Ethernet) of switch-3 is directly connected to Fa0/1 (Fast Ethernet) of Root Bridge. Link is working on 100 Mbps, so the link cost is 19.
- The second root towards the root bridge is via switch-3. The cost of the link between switch-2 and switch-3 is 19 and the cast of the link between switch 3 and Root bridge is 100, So the total cost of the root is 19+100 = 119.
- The third root towards the root bridge is via switch-4, switch-5 and switch-3. The path cost of this root is 19+19+100+100=238
So, the lowest cost path towards the root bridge is 19, which is a link from the Fa0/3. So the port Fa0/3 becomes a root port and remaining ports become Designated Ports or Block ports.
Switch-3
Similarly, switch-3 has also three ways towards the root bridge:
- The first root is directly connected with the root cost of 100.
- The second root is via switch-2. The root cost for this root is 19+19=38.
- The third root is via switch-5, switch-4 and switch-3. The root cost for this root is 100+19+19+19=157
So, the lowest cost path towards the root bridge is 38, which is a link from the Fa0/1 switch-3 to switch-2. So the port Fa0/1 of this switch becomes a root port and remaining ports become Designated Ports or block ports.
Switch-4
This switch is also four ways towards the root bridge.
- The first way is via switch-2 to Root Bridge. The path cost is 19+19=38
- The second path is via switch-2 to switch-3 and then Root Bridge. The path cost is 19+19+100=138.
- The third path is from switch-4 to switch-5, switch-3 and then Root Bridge. The cost for this path is 19+100+100=219
- The fourth path is via switch-5 to switch-3 to switch-2 and then Root Bridge. The path cost for this root is 19+100+19+19 =157
So, the lowest cost path towards the root bridge is 38, which is a link from the switch-4 to switch-2. So the port Gig1/0/1 of this switch becomes a root port and remaining ports become Designated Ports or block ports.
Switch-5
Switch-5 is also four ways towards the root bridge.
- The first way is via switch-3 to Root Bridge. The path cost is 100+100=200
- The second path is via switch-3 to switch-2 and then Root Bridge. The path cost is 100+19+19=138.
- The third path is from switch-5 to switch-4, switch-2 and then Root Bridge. The cost for this path is 19+19+19=57
- The fourth path is via switch-4 to switch-2 to switch-3 and then Root Bridge. The path cost for this root is 19+19+19+100 =157
So, the lowest cost path towards the root bridge is 57, which is a link from the switch-5 to switch-4, switch-2 and then Root Bridge. So the port Fa0/1 of this switch becomes a root port and remaining ports become Designated Ports or block ports.
Notice:- The topology has two physical loops. The first loop is between the Root Bridge, Switch-2 and Switch-3. And the second loop is between the switch-2, switch-3, switch4 and switch-5. The spanning-tree algorithm block the port Eth2/1 of switch-3 and port fa0/4 of switch5 to avoid the loop.

Configure the Path Cost
To verify the path cost use the command “spanning-tree cost <cost_value>” command in interface configuration mode. To verify the port and path cost to the root bridge, enter the “show spanning-tree” command.