Spanning Tree Algorithm – Path Cost Exclusive Details
When a loop occurs in the switched network, the STP uses path cost to resolve the port’s state. Path cost is obtained from the port’s speed. The spanning tree puts the lowest-numbered port into the forwarding state if all connected ports have the same path cost values.
The path information is determined using the sum of the individual port costs from the destination to the root bridge. Each “destination” is a switch port. The port’s speed defines the default port costs. 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, the price is more significant for the spanning-tree algorithm.
The IEEE revised cost values 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 on the root bridge. We can configure the port cast in interface configuration mode. The cost value must be between 1 and 200 000 000. Enter the “no spanning-tree cost” in interface configuration mode to restore the default port cost value.
Path Cost Calculation
Paths with the lowest cost become the preferred path. The remaining paths to the root bridge are blocked. Now look at the below image and analyze all the paths from all switches to the root bridge:-
Switch-2
Switch-2 has three ways to go towards Root Bridge.
- Fa0/3 (Fast Ethernet) of switch-3 is directly connected to Fa0/1 (Fast Ethernet) of Root Bridge. The link works at 100 Mbps, so the link cost is 19.
- The second root towards the root bridge is via switch-3. The link between switch-2 and switch-3 costs 19, and the cost between switch 3 and the 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
The lowest-cost path towards the root bridge is 19, a link from Fa0/3. Thus, port Fa0/3 becomes a root port, and the remaining ports become Designated Ports or Block ports.
Switch-3
Similarly, switch-3 also has three ways toward 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
The lowest-cost path towards the root bridge is 38, a link from the Fa0/1 switch-3 to switch-2. Thus, port Fa0/1 of this switch becomes a root port, and the remaining ports become Designated Ports or block ports.
Switch-4
This switch also goes four ways toward 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 switch-5 to switch-3 to switch-2, and then Root Bridge. The path cost for this root is 19+100+19+19 =157
The lowest-cost path towards the root bridge is 38, a link from switch-4 to switch-2. Thus, port Gig1/0/1 of this switch becomes a root port, and the remaining ports become Designated Ports or block ports.
Switch-5
Switch-5 also has four ways toward 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 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, a link from switch-5 to switch-4, switch-2, and then the Root Bridge. So port Fa0/1 of this switch becomes a root port, and the remaining ports become Designated Ports or block ports.
Notice: The topology has two physical loops. The first loop is between the Root Bridge and switches 2 and 3, and the second is between Switches 2, 3, 4, and 5. The spanning-tree algorithm blocks port Eth2/1 of switch-3 and port fa0/4 of switch5 to avoid the loop.
![Path Cost NetworkUstad](https://networkustad.com/wp-content/uploads/2019/10/Path-Cost-300x226.png)
Configure the Path Cost
In interface configuration mode, verify the path cost by using the “spanning-tree cost <cost_value>” command. To verify the port and path cost to the root bridge, enter the “show spanning-tree” command.