TechKnowSurge
Cisco CCNA 2.5
VideoNetworkFree

STA - Elect Root Ports

Spanning Tree Protocol root port election determines the optimal path to the root bridge by calculating path costs based on link speeds and applying tiebreakers. Understanding this process is essential for designing and troubleshooting Layer 2 switched networks.

Complete this video to capture a CTF flag worth 1 point.

About this video

Spanning Tree Protocol assigns a numerical cost to each network link based on its bandwidth, with faster connections receiving lower cost values. A 10 Gbps link carries a cost of 2,000, a 1 Gbps link costs 4, a 100 Mbps link costs 19, and a 10 Mbps link costs 100 under the revised IEEE standard. When a switch evaluates its paths to the root bridge, it accumulates these link costs across every hop, allowing the protocol to prefer a multi-hop path over high-bandwidth links rather than a direct connection over a slower one. This calculation happens independently on each non-root switch and applies to every port that could potentially reach the root bridge. Once path costs are calculated, each switch elects a root port using a three-step tiebreaker process. The first criterion is lowest root path cost — whichever port offers the cheapest cumulative path to the root bridge wins. If two ports have equal path costs, the switch compares the bridge ID of the neighboring switch sending the Bridge Protocol Data Units, favoring the lower value. If both ports receive BPDUs from the same upstream switch and the bridge IDs remain tied, the final tiebreaker is the sender's port ID, which combines a configurable priority value with the interface number. The port receiving BPDUs from the lowest sender port ID is elected as the root port. The port ID structure consists of two bytes: four bits of configurable priority, which defaults to 128, and twelve bits representing the interface number. When all priorities are left at default, the interface number alone determines the outcome, and lower interface numbers are preferred. Administrators can override this behavior by manually adjusting port priority on upstream switches to influence which port a downstream switch selects as its root port. Consistent cost and priority configuration across all switches in the network is critical, as mismatched standards between devices will produce unpredictable spanning tree behavior.

What you'll learn

What's covered

STP Root Port Election

Aligned to

Cisco CCNA
2.5 Interpret basic operations of Rapid PVST+ Spanning Tree Protocol

Key terms

Spanning Tree Protocol
STP
A network protocol that prevents loops in Ethernet networks by creating a loop-free logical topology.
Root Port
The port on a non-root switch that provides the least-cost path to the root bridge.
Root Path Cost
The cumulative cost calculated by a switch to reach the root bridge, based on the speed of each link along the path.
Bridge ID
BID
A unique identifier used in the Spanning Tree Protocol consisting of a configured priority value and the bridge's MAC address. The BID is used in STP elections to determine which switch becomes the root bridge.
Port ID
A two-byte STP identifier assigned to each switch port, consisting of a priority value and an interface number, used as a tiebreaker when selecting a root port.
Bridge Protocol Data Unit
BPDU
A data message exchanged between switches running Spanning Tree Protocol to detect network loops and elect a root bridge. BPDUs contain the sending switch's BID and path cost information used to build the loop-free spanning tree.

Topics

Spanning Tree Protocol Root Port Election Layer 2 Switching Path Cost Calculation Networking Bridge Id

Transcript

The Root Port

Spanning tree algorithm uses a root port and elects a root port. The root port is important because it identifies the fastest path that's going to lead to the root bridge. Once it's identified a root bridge, then it can connect what is going to be the root port that will lead to that root bridge, and then it can later on decide what it's going to do with the other ports that lead to the root bridge.

In order to know what is the fastest path to the root bridge, what it's going to have to do is calculate the cost, and it calculates the cost for every path that leads to the root bridge. That happens on a persuade, so every switch.

Calculating the Root Path Cost

The next step is to calculate the root path cost, and that's the cost of the path to that root bridge. When the bridge protocol data units are sent out, switch 1 will be sending out bridge protocol data units to switch 2, and it will also send them out to switch 3, which will in turn send things out to switch 2. This switch will then see that there are actually four paths that can get to that root bridge - two right here, and two in this direction. What it will do for each one of those paths is figure out what is the cost to get to switch 1, to get to this root bridge.

So it'll calculate all of that, and at first glance we say, oh well, it looks like it would choose this route right here because it's directly connected versus this route right here. But that's not necessarily the case. What if this is a hundred Meg connection and these are gig connections here? Well, then it would actually prefer to go this way.

So how does it calculate that? How does it figure out what is the least cost to get to the root bridge? There are a lot of different standards when it comes to this, and you can even specify your own standard. Ultimately it doesn't really matter what standard you use as long as it's consistent across your network. You can set these standards on your different switches, but if they're different across your network, that's going to cause problems.

Essentially what they do is assign a certain cost to each one of those links, and it's based off of the link as it comes into the switch. So if your switch has a 10 gigabit per second port on there, then in the old standard it would be set to the newer standard 2000 - and like I say, there are some other standards out there as well. If it's a one gigabit per second, then it's set to 4. If it's a hundred megabits per second, then it's set to 19. If it's 10 megabits per second, it's a hundred.

Essentially what it's going to do is favor the faster links. It's also going to add things up, so if it has to go across two 10 gigabits per second links, then it's going to be added up to 4, and it might prefer that one gigabit per second link. So it's going to calculate the cost to the root bridge based off of these numbers, based off of these settings.

Working Through an Example

Here I've got my network, and we're going to take it once again from the perspective of switch 2. Let's say this first link right here is a 10 megabit per second connection, so the cost of it to get to the bridge here is going to be 20 million - quite high right there.

Next, let's say this next link right here is going to be a gigabit per second, so it's going to be 20,000. Then this link right here - let's say that this one's going to be a 20 big gigabit per second connection as well, so let's say that's 20,000. And then maybe this connection is a hundred megabit per second, so this is 200,000. For the interest of simplicity, let's say that both of these over here are gigabit connections, so let's say 20,000 for each one of these.

So now what's going to happen is the cost to make it out this direction right here is going to be the link cost here plus the link cost that's going to be from this switch to the root bridge, which is 20,000 as well. So in total this cost right here will be 40,000. And this cost right here will be 220,000, which is the link cost here plus the link cost that it takes for this switch to get to this bridge right here.

So now, out of switch 2's options, the costs of each one of these links are 20 million, 20,000, 40,000 and 220,000. So obviously it's going to prefer this 20,000 link over the other links in this network. It wants to figure out what the shortest path is.

Electing the Root Port

Next, each switch is going to elect a root port. That is the port that it's going to use to forward traffic towards the root bridge. What's going to happen here is that each one of these switches is going to use this criteria, and it's going to first of all try to select the lowest cost to the root bridge. So here's switch 2 right here, and this is what we said is going to be the root bridge. In our last example we said our lowest cost was this link right here, so it's pretty self-explanatory - it wants to use that, and then it would elect that port right there to be the root port, the port that's going to send traffic towards the root bridge.

But that's not always going to be the case, where that's going to be the least cost. Let's say these links are the same cost to the root bridge. In fact, let's just say that these are the same as well, the same cost - all four links are the same cost to the root bridge. This is very likely, because it's going to the same switch, and this can actually happen as well where it's the same cost.

Well, next what it's going to do is choose the lowest sender bridge ID. It's going to take a look at whoever's sending these bridge protocol data units out, and it says, okay, well who's the lowest bridge ID? In this case right here it's obviously going to be the root bridge, and so it's going to be one of these links that it's going to choose, and not these links right here.

Now in this case we still have two that have the same sender bridge ID. The bridge protocol data units that are being sent out are being sent from the same switch, so they have the same sender bridge ID. So in this case right here it then looks at the lowest sender port ID. So if this is port, let's say on this side it's 045 and this is 046, it's actually going to choose the link that has the lowest sender port ID, and then this one becomes the root port right there. That is now elected to be the root port, and not this other one next to it.

So that's how that works. It's got three criteria:

  • The lowest cost to the root bridge
  • The lowest sender bridge ID
  • The lowest sender port ID

The Port ID

The port ID has a similar type of format to the bridge ID. The port ID is two bytes long. 12 bits are the interface number, so if it's fa101, or fa 048, or whatever that number is that's associated with that - and that's going to look different depending on the different switches that you have, but essentially the interface number. Once again, it's going to prefer the lower interface number over a higher interface number.

And then the priority. Maybe we don't want to have it adjust based off of that interface number, and we want to make sure we specify which port is going to be selected - then we set the priority on it. But if it's just set to the default, which is 128, then all it will do is refer to the interface number and be set by whatever interface that it is. So this is the port ID, and once again it's the sender port, whatever is sending out the bridge protocol data units, that it's going to be determined off of.

Check Your Knowledge

Here is the question: what is the root ports? These should be pretty fun - these are like little logic problems that you get to solve, and it can be a fun experience.

First of all, though, you have to know that this is all at, let's say, a hundred megabits per second - all the lines - in order to figure out the cost of all these lines. You've got to know that. We'll call this switch 1, 2, 3 and 4. So try to figure out what the root port is on each of these switches. There are going to be root ports on only three of the four switches.

In order to figure out which ones the root ports are, we first of all have to figure out what the root bridge is. We take a look at this and we see that all of these are set to the default bridge priority, except for this switch 1 right here, which is set to 4096. So this is the winner for the root bridge. This will be the root bridge there, and all the other devices want to send traffic, or forward the traffic, towards the root bridge.

So what we'll do is go switch by switch to figure out what is going to be the lowest cost, or what is going to be the root ports. Let's take switch 2 next. What is the lowest cost? Well, it's not going to be these lines, because they are going to add up to more by the time it goes all the way around this direction to switch 1. So it's going to be either 045 or 046 that's going to be elected.

Next, what we're going to do is take a look at the lowest sender bridge ID. The sender bridge ID for this one is this right there, and it's going to come across both lines, so that is the one that we have. So that is the same - that's not a tie breaker, it doesn't work. And then we take a look at the lowest sender port ID. We see a 045 and a 046, and as long as the priorities are the same, we're going to choose 045. So this port on this side is going to be the port it's going to use; that is going to be the root port. So now we've got the root port for that switch.

We can go through the same process for switch 3. It's not going to use the ports going this way, so it's got to be either 47 or 48 that's going to be sending this way. And we see that first of all it checks the lowest cost - well, we just did that. The next step is the lowest sender bridge ID, which is the same because it's coming from the same switch. And then the lowest sender port, which is 047, so therefore it's going to choose this port right here as the root port.

Now let's take a look at switch 4. Switch 4 is going to see that there are four ports heading towards this root bridge. What is the lowest cost? It's going to say that they're all equal. So these are all equal. Then next, what it's going to do is, well, what is the sender bridge ID? So it sees that the priority for these senders are both the same, 32,768, so then it looks at the MAC addresses and determines switch 2, so it will eliminate these two as being options right there. And now we still have two options here we need to narrow down. Now it's going to take the lowest sender port ID, which is 043, so this is the one it's going to select: 047 is going to be the root port, and that's the one that's going to be elected in that case.

About TechKnowSurge

TechKnowSurge builds IT and cybersecurity professionals through hands-on, concept-first training built around real understanding — not memorization. Free interactive tools, structured programs, and 25+ years of real-world experience, all in one place.

Explore free tools and programs →