The Spanning Tree Algorithm is the logic behind Spanning Tree Protocol, guiding switches through a structured election process to eliminate network loops. This overview covers how switches exchange Bridge Protocol Data Units, elect a root bridge, calculate path costs, and assign port roles to maintain a loop-free topology.
Spanning Tree Algorithm
The spanning tree algorithm is that set of instructions that spanning tree protocol uses to eliminate loops.
This is going to be more of an overview, and then we'll go over the specific steps: electing a root bridge, then calculating root path costs and how it applies to electing root ports, and then finally we'll sum it up with electing designated and non-designated ports.
When you turn on spanning tree protocol on your switch — and a lot of switches already have spanning tree protocol enabled on them — what's going to happen is every time you plug something into one of those ports and those ports go live, it's going to send out what's called bridge protocol data units. It's just a frame that it sends out the port with certain pieces of information.
So if switch 2 on here would turn on, it would send out bridge protocol data units down each one of the links, and then it would send that out and those other switches would get that.
Some of the information that it sends out is things like information about STP, like the timers and that type of stuff. It will also send out its own bridge ID, so it sends out its ID to these other devices. It also sends out information about what the lowest bridge ID that it's found on the network is.
What essentially happens is at some point in time all these switches get that same information, and then they determine who has the lowest bridge ID, and it will elect a root bridge. So we elect one of these devices as being the root bridge.
The next thing it does is calculate: okay, what is my fastest route, what is my least cost route to get to that root bridge? So for each one of these links on switch 2, it's going to determine that there are four ways to get to the root bridge, and then it's going to calculate the cost that it takes to get to that root bridge on each one of those links.
Once it's done that, what it will do is elect a root port out of those four links. It will choose one of them to say, that is the link that I'm going to use to get to the root bridge, so I'll send it out in that direction. So, elect a root port.
Then it will elect designated ports. We will talk about what specifies a designated port, but on this network there are going to be a lot of different designated ports that are on this network.
And then it will shut off all other ports, so it will elect alternate or blocked ports. So for switch 2 it would shut down all other ports going towards that root bridge.
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 →