Spanning Tree Cost Calculation

Non-root bridges need to find the shortest path to the root bridge. What will happen if we have a mix of different interface types like Ethernet, FastEthernet, and Gigabit? Let’s find out!

Here’s the topology I will use to explain the spanning-tree cost calculation:

spanning tree cost calculation example

In the picture above, we have a larger network with multiple switches. You can also see that there are different interface types. We have Ethernet (10 Mbit), FastEthernet (100Mbit), and Gigabit (1000Mbit). SW1 on top is the root bridge so all other switches are non-root and need to find the shortest path to the root bridge.

Bandwidth Cost
10 Mbit 100
100 Mbit 19
1000 Mbit 4

Spanning tree uses cost to determine the shortest path to the root bridge. The slower the interface, the higher the cost is. The path with the lowest cost will be used to reach the root bridge.

Here’s where you can find the cost value:

BPDU Header

In the BPDU, you can see a field called root path cost. This is where each switch will insert the cost of its shortest path to the root bridge. Once the switches find out which switch is declared as root bridge, they will look for the shortest path to get there. BPDUs will flow from the root bridge downwards to all switches.

If you studied CCNA or CCNP then this story about spanning tree cost might sound familiar. OSPF (Open Shortest Path First) also uses cost to calculate the shortest path to its destination. Both spanning tree and OSPF use cost to find the shortest path, but there is one big difference. OSPF builds a topology database (LSDB) so all routers know exactly what the network looks like. Spanning-tree is “dumb”…switches have no idea what the topology looks like. BPDUs flow from the root bridge downwards to all switches, switches will make a decision based on the BPDUs that they receive!

Here’s an example of the different spanning tree costs for our topology:

spanning tree cost root port

SW2 will use the direct link to SW1 as its root port since this is a 100 Mbit interface and has a cost of 19. It will forward BPDUs towards SW4; in the root path cost field of the BPDU, you will find a cost of 19. SW3 is also receiving BPDUs from SW1, so it’s possible that, at this moment, it selects its 10 Mbit interface as the root port. Let’s continue…

spanning tree cost root port 2

This picture needs some more explanation, so let me break it down:

  • SW3 receives BPDUs on its 10 Mbit interface (cost 100) and on its 1000 Mbit interface (cost 4). It will use its 1000 Mbit interface as its root port (the shortest path to the root bridge is 19+19+4=42).
  • SW3 will forward BPDUs to SW4. The root path cost field will be 100.
  • SW4 receives a BPDU from SW2 with a root path cost of 19.
  • SW4 receives a BPDU from SW3 with a root path cost of 100.
  • The path through SW2 is shorter, so this will become the root port for SW4.
  • SW4 will forward BPDUs towards SW3 and SW5. In the root path cost field of the BPDU, we will find a cost of 38 (its root path cost of 19 + its own interface cost of 19).
  • SW3 will forward BPDUs towards SW5 and insert a cost of 42 in the root path cost field (19 + 19 + 4).

The complete picture will look like this:

We're Sorry, Full Content Access is for Members Only...

If you like to keep on reading, Become a Member Now!

  • Learn any CCNA, CCNP and CCIE R&S Topic. Explained As Simple As Possible.
  • Try for Just $1. The Best Dollar You’ve Ever Spent on Your Cisco Career!
  • Full Access to our 802 Lessons. More Lessons Added Every Week!
  • Content created by Rene Molenaar (CCIE #41726)
521 Sign Ups in the last 30 days
satisfaction-guaranteed

  • 100% Satisfaction Guaranteed!
  • You may cancel your monthly membership at any time.
  • No Questions Asked!

Forum Replies

    1. Lowest sender port ID: when the switch has two interfaces connecting to the same switch, and the cost to reach the root bridge is the same it will use the interface connected to the lowest upstream switch port. Isnt it, Rene?

  1. Andy if I understand your question correctly then I think no. The lowest switch port number is a local decision therefore it is not considering the port numbers of the upstream switch.
    I also can be wrong… :slight_smile: Maybe someone will correct me.

    Marek

  2. In the calculation , the switch , receive a bdpu with root path cost value ( the link cost is given by costs Of the 2 port ,upstream and downstream)
    The switch add at this path cost value , cost Of the port whrere receive the bpdu… When sendig this bpdu out another port, the switch shoulds also add the cost Of the port which use to forward??

  3. Hi Francesco,

    The switch will add the cost of its root port when it forwards the BPDU. It never adds the cost of the interface that is used to send the BPDU.

    The total cost to get to the root will be the sum of all root ports.

    Rene

99 more replies! Ask a question or join the discussion by visiting our Community Forum