Spanning Tree Protocol (STP) is a Layer 2 network protocol that prevents switching loops caused by redundant links while preserving failover capability. It operates on managed switches by selectively blocking ports to eliminate loops and automatically restoring blocked paths when an active link fails.
Spanning Tree Protocol
Within our networks we want redundancy. For example, we want multiple pieces of equipment doing the same thing, so if one of those pieces of equipment fails the other one can take its place. Within that equipment we also want redundancy — we want multiple power supplies, we want multiple components within it, so that if any component fails within that device, the device is still up and running. And between our devices we also want multiple lines, so that if any one of those lines goes down we still have redundancy and the network still operates.
The problem is that when you talk about layer 2 devices like switches and you create two lines between those switches, it creates a loop. Things like broadcast will your network, it will bring it down to a crawl, or it will just stop communicating altogether because of all of those loops that it creates and all the frames that are getting sent back and forth. What we need is something like spanning tree protocol to help mitigate against that, to protect our network but allow us still to have redundancy within our network. Spanning tree protocol is pretty common amongst all of our networks of any decent size, and it comes on your switches by standard.
Just a refresher about what a bridge is, because we're going to be talking quite a bit about a bridge and what a bridge does. A switch is a multi-port bridge, so switch and bridge quite often can be interchangeable — really they are interchangeable. As an example, this switch right here will analyze the frames that are coming into it, take a look at the source MAC address, and record the source MAC address with the port that it comes in on, so that way it knows how to forward future frames onto that device. A bridge allows this device to start learning. A bridge is a device that learns about MAC addresses and where the destination of those MAC addresses are, and a switch is a multi-port bridge. Just remember that those are going to be interchangeable as we work through.
We're going to work with the network diagram we've been working on, and I want to show you how I would incorporate some redundancy with this. What I would do is start creating multiple links between these switches. Between switch 2 and switch 1 I'm going to create a second line there, and that way either of those links could fail and I'm still up and running. I would of course do the same thing for switch 2 to switch 1, or switch 3 to switch 1. So now I've got multiple lines between these devices.
But another thing: let's say these are in different locations, maybe they are different buildings. I would also want to guard against that. Quite often what will happen is a backhoe will dig up a line, or some line will get severed, and so I still need to have redundancy — it would go take a different route. What I could do is also create links between these two switches right here, and now communication can happen the other way as well. That would be quite a few redundancies, and that's what I'm looking for within these networks.
The problem that happens here is that when you have redundancy, a broadcast is sent out all ports except for the port that it comes in on. So as an example, between switch 2 and switch 1: if a broadcast comes in on this link right here and comes into switch one, switch one is going to then send it out all other — the one that goes back to this switch right here, and the one that goes back to switch two. So switch two is going to be receiving that broadcast again, and then it's going to resend it out all other links, to include the one that it just sent it out on. Now you see the loop. This loop is created right here, and not only is it created right there, but it's going to have the same effect all across the network — we're going to get the same loops within the network. You can see how just one broadcast frame that's sent out is going to be sent over and over again, and it's just going to multiply within this network, and it will just continue to loop until it brings down your network.
I've had this happen over and over again. I've had janitors during the summertime at a school unplug all the equipment, and when they plug it in they just plug in things kind of crazy like, and they'll create loops. Sometimes you intentionally want to create redundancy within your networks, and then that creates a loop. All your smarter switches have spanning tree protocol.
Spanning tree protocol is the answer to fixing this issue. What spanning tree protocol will do is shut down some of the redundancy within your network so that you don't get these loops, and then if one of your links happens to go down accidentally, it will make this other link, this backup link, go live, and now you have connectivity again.
It does this in a few different ways. First of all, there is something called a bridge protocol data unit. A bridge protocol data unit is a frame that gets sent back and forth between the switches with some information to it that allows these switches to communicate and to establish which links are going to actually go down.
Then we've got something called the spanning tree algorithm. The spanning tree algorithm is the actual steps and instructions it takes to shut down the links. You need an algorithm so that each switch can make a logical decision on what links go down without causing problems, because if they're working off of a different set of instructions, they could potentially turn off the wrong link between them. They won't all be on the same page and they'll create issues. Between the bridge protocol data units and the spanning tree algorithm, and a few other things that we'll discuss, it really helps mitigate these loop issues.
There are a few concepts you should understand when it comes to spanning tree protocol.
Based off of that unique ID there are a lot of things that are determined. For instance, one of the things that's determined is what is going to be the root bridge, or the main bridge. In this network right here, what I would like is that this main switch — I want everything to be going through it, because it goes out to the rest of the world and then is routed into other networks. So I want this to be the main bridge or the root bridge, and we'll talk about how to make that happen, how to make that the root bridge.
Then there's this concept called path cost. There's going to be a calculation that's going to happen that's going to determine what the path is to that root bridge. For instance, this switch will calculate the path cost that's going to the root bridge going via this direction, and then also via this direction. Provided that all these links are the same speed, we're going to see that this is probably going to be the winner of those two, but we'll talk about what determines all of that.
Then there's also link failure and recalculation. The one thing that has to happen with spanning tree is that if one of these links goes down, then the other link can take over — the one that was shut off now becomes live. Those are some concepts when it comes to spanning tree protocol.
So what does the spanning tree algorithm look like? Here are the steps right here. I've already talked about a couple of these steps.
The first thing that happens is it elects a root bridge. The root bridge, the essential winner I guess of this, is going to be the one with the lowest bridge ID. That's where the bridge protocol data units come in. Those bridge protocol data units are sent back and forth between these devices and they carry information like what their bridge ID is and what the lowest bridge ID that they have found is. By sending this back and forth, all of the switches then get the information at some point about all of the bridge IDs that are on this network, or at least what is the lowest bridge ID. They determine the lowest bridge ID in my network, and that bridge right there is then elected as the root bridge.
From there, the second step is to calculate what is the least cost to get to that bridge. What it will do is add up the links to find out what the cost is to get to that root bridge. From switch 2 to get to switch 1 it's going to come up with a certain cost, and then if it goes this direction right here and then heads this direction through switch 3, what is the cost going to be there? When we look at this, it looks like this is going to be the shortest path to get to switch one, the least amount of cost. But that's not necessarily the case. What if these are gigabit connections right here and this is just a 100 megabit connection right there? Well then this is actually going to be faster. So part of the calculation factors in the speed of those links. That is calculating the root path cost — the cost of the path in each of the directions here to get to the root bridge.
Then it's root ports. The root ports are going to be the ports that it's going to want to use to get to that root bridge, so it elects root ports to get to that root bridge.
Then finally what it will do is elect designated ports. Those are going to be the ports that are going to essentially be receiving. We're not going to get real in depth into this, but it's going to elect quite a few designated ports on here and then use those. Once it elects those designated ports, those are the ports that are going to be up and running and receiving information — essentially sending and receiving some too.
Then it's going to elect alternate or blocked ports. This goes by many different names, but essentially these are going to be the ports that it shuts down. The designated ports are going to be the ports it's going to keep live, it's going to keep the root ports live, and then it's going to shut down some of these other ports. By shutting down those ports it shuts down those links, so there's not communication between these devices on those links. It's not forwarding frames at all on those links, and then we reduce or eliminate that redundancy that's within this network.
There are different versions of this. There's spanning tree protocol, STP. There's PVST, which is per-VLAN spanning tree protocol. There's RSTP, rapid PVST, and multiple spanning tree protocol, MST. There are a lot of different versions that are around. Just know that at this point in time.
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 →