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.
STP Root Port Election
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.
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.
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.
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 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.
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.
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 →