TechKnowSurge
Cisco CCNA 2.5 Cisco CCNA 1.13
VideoNetworkFree

Spanning Tree Protocol

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.

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

About this video

Redundancy is a core principle of reliable network design, encompassing duplicate devices, dual power supplies, and multiple physical links between switches. However, at Layer 2, redundant switch links introduce a critical problem: switches forward broadcast frames out all ports except the one on which the frame arrived, causing frames to circulate indefinitely through looped paths. This broadcast storm rapidly multiplies traffic across the network, degrading performance to the point of failure and halting communication entirely. Spanning Tree Protocol (STP) addresses this problem by logically blocking select switch ports to create a loop-free active topology while preserving the physical redundant links for failover. The protocol relies on two core mechanisms: Bridge Protocol Data Units (BPDUs), which are frames exchanged between switches to share topology and bridge identification data, and the Spanning Tree Algorithm, which provides a consistent set of decision rules each switch follows independently to ensure all devices reach the same conclusion about which ports to keep active and which to block. The Spanning Tree Algorithm proceeds through a defined sequence of steps. First, switches exchange BPDUs to elect a root bridge, the switch with the lowest Bridge ID, which serves as the logical center of the topology. Each switch then calculates the least-cost path to the root bridge, factoring in link speed, and designates a root port representing that best path. Designated ports are elected on each network segment to handle active forwarding, while remaining ports are placed in a blocked state, eliminating loops. If an active link fails, STP detects the change, recalculates the topology, and transitions a blocked port to an active forwarding state to restore connectivity. STP exists in several variants, including Per-VLAN Spanning Tree (PVST), Rapid Spanning Tree Protocol (RSTP), Rapid PVST, and Multiple Spanning Tree Protocol (MST), each offering improvements in convergence speed or support for VLAN-based topologies. Understanding the foundational operation of STP — root bridge election, path cost calculation, and port role assignment — is essential before working with any of these more advanced implementations.

What you'll learn

What's covered

Spanning Tree Protocol

Aligned to

Cisco CCNA
2.5 Interpret basic operations of Rapid PVST+ Spanning Tree Protocol
1.13 Describe switching concepts

Key terms

Spanning Tree Protocol
STP
A network protocol that prevents loops in Ethernet networks by creating a loop-free logical topology.
Redundancy
The duplication of critical components or systems to increase reliability and availability.
Bridge
A network device that connects two or more network segments and filters traffic based on MAC addresses.
Switch
A network device that connects devices within a LAN and forwards traffic based on MAC addresses.
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.
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.
Root Bridge
The switch elected as the reference point for the Spanning Tree Protocol topology, determined by the switch with the lowest Bridge ID (priority + MAC address). All other switches calculate their best path to the root bridge and block redundant links to create a loop-free tree.
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.
Layer 2
The Data Link layer of the OSI model, responsible for MAC addressing and frame delivery on a local network.

Topics

Spanning Tree Protocol Layer 2 Switching Network Redundancy Loop Prevention Bpdus Root Bridge Election Networking

Transcript

Redundancy and the Problem It Creates

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.

What a Bridge Is

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.

Adding Redundancy to the Network

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.

How Redundancy Creates a Loop

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

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.

Spanning Tree Protocol Concepts

There are a few concepts you should understand when it comes to spanning tree protocol.

  • The algorithm. This is just the set of instructions that each switch is using to base its decisions off of.
  • The bridge protocol data unit. That's the frame that's being sent back and forth between these bridges or switches, carrying the information that tells these devices information about the different links and about the different switches that are on within this network.
  • The bridge ID. Each of these switches, each of these bridges, will come up with a bridge ID, an identifier that is unique to each one of these bridges.

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.

The Spanning Tree Algorithm

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.

Versions of Spanning Tree Protocol

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.

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 →