STP Port and Path Costs Explained

STP (Spanning Tree Protocol) is a layer two protocol. It dynamically finds and removes loops from the network. It creates a virtual topology of the entire network. It selects a single switch as the root bridge and uses it to create the virtual topology. Apart from the root bridge, all remaining switches become non-root bridge switches. All non-root bridge switches use the root bridge switch as the reference to select only one link for every destination.

STP uses BPDU messages to share information. An STP running switch broadcasts a BPDU message from all ports every two seconds. A BPDU message contains all the information STP running switches need to build the virtual topology and remove loops.

Administrators create multiple links between switches for backup and redundancy. Redundancy prevents the network from going down when primary links fail. However, it also creates loops in the network. A network never works with a loop.

If you use a single link between switches, no loop will form in the network. However, if the link fails, the entire network will be down. If you use multiple links between switches, the network will remain up even if primary links fail. But there is a twist. You can not use this network.

Network devices use broadcast messages for many purposes. Switches forward broadcast messages from all ports except the incoming port. If the network contains a loop, switches will forward and receive broadcast frames in an endless cycle.

network with loop

STP solves this issue. It dynamically removes loops and maintains connectivity. It classifies links into two types: primary and backup. If the primary link is up, it disables the ports connected to the backup link. If the primary link goes down, it enables the backup link. To classify links, it uses their path costs.

STP Path cost

Path cost is an accumulated value of all incoming ports' costs between the root bridge and the switch. A switch can have different types of ports. For example, it can have Ethernet, Fast Ethernet, and Gigabit Ethernet. STP assigns a unique value to each type. This value is called the port cost.

There are two sets of port costs. The following table lists both.

Bandwidth Old Cost Value New Cost Value
10 Gbps 1 2
1 Gbps 1 4
100 Mbps 10 19
10 Mbps 100 100

Some old series switches, like the Catalyst 1900, use the old cost value. Cisco has already discontinued these old series switches. New series switches, like the 2960, use the new cost value.

Path calculation process

The path calculation process starts from the root bridge. A BPDU contains the accumulated path cost. When the root bridge advertises BPDUs, it sets the accumulated value to 0.

When a non-root bridge switch receives a BPDU message on a port, it adds the port's cost on which the BPDU arrives to the path cost and forwards it from all other ports.

For example, a BPDU contains the accumulated path cost 0. The switch receives it on a Gigabit port. The port cost of a Gigabit port is 4. It adds this cost to the path cost and updates the accumulated path cost to 4 in the BPDU before forwarding it from other ports. The next switch repeats the same process. By following this process, all non-root bridge switches learn and broadcast the accumulated path cost from the root bridge.

After learning the accumulated path cost, a non-root bridge switch categorizes its ports into three types: root, designated, and blocked. It uses the root port to reach the root bridge. It selects only one root port. It uses the designated ports to reach end devices and other switches. It selects only one designated port for every destination. It uses blocked ports to remove loops. It does not accept user frames on blocked ports. 

STP Path calculation Packet Tracer example

Create a packet tracer practice lab, as shown in the following image.

Download the packet tracer practice lab

practice lab

STP is part of the default implementation on Cisco switches. It does not need any configuration. By default, it is enabled on all switches. Unless you manually disable it or change its configuration, it handles everything automatically. It first selects a root bridge. Then, it calculates the accumulated path on all non-bridge switches. Based on the accumulated path cost, it classifies all ports on all non-root bridge switches. This process takes about a minute.

We use the show spanning-tree command in privileged-exec mode to view all STP-related information. The output of this command formats information into three sections. The first section provides information about the root bridge. The second section shows information about the local switch. The third section lists all ports' states.

The following image shows the output of this command on S3.

root bridge

As the above output shows, STP elected it as the root bridge. A root bridge works in the center of the STP topology. All ports on the root bridge are designated ports. It does not have any root or blocked port. It starts the path calculation process. It sets the accumulated path cost's value to zero and advertises it from all ports.

The following image shows the output of this command on S2.

path cost on a non-root bridge

S2 receives the BPDU from S3 on a Gigabit port. The BPDU contains the accumulated path cost zero. The port cost of a Gigabit port is 4. It adds both values to calculate the root port's cost.

The following image shows the output of this command S4.

path cost on a non-root bridge

The following image shows the output of this command S1.

path cost calculation on a non-root bridge

The following image shows the output of this command S0.

path calculation on s0

STP disables S0's Gigabit 0/1 port to remove the loop. This port has a higher path cost than the FastEthernet 0/24 port.

0 (Advertised cost from root bridge) + 4 ( Gig0/1 incoming port on S2) + 19 (Fa0/24 incoming port on S1) + 4 (Gig0/1 incoming port on S0) = 27 (Path cost on Gig0/1)

0 (Advertised cost from root bridge) + 4 ( Gig0/2 incoming port on S3) + 19 (Fa0/24 incoming port on S0) = 23 (Path cost on Fa0/24)


A non-root bridge switch uses the path cost to compare all available paths to the root bridge. It selects the lowest-cost path to reach the root bridge. It selects only one path to reach the root bridge.

ComputerNetworkingNotes CCNA Study Guide STP Port and Path Costs Explained