Spanning Tree Protocol (STP)

Introduction
In the complex realm of computer networks, stability and efficiency are paramount. Imagine a scenario where multiple paths connect switches and bridges, forming a web of interconnected devices. While such redundancy promises increased reliability, it can also lead to unforeseen issues, like loops and broadcast storms, causing network outages and performance degradation. Therefore comes the Spanning Tree Protocol (STP), a fundamental mechanism designed to mitigate these problems and ensure seamless communication within networks.
One of the protocols that a network engineer must grasp is spanning-tree, and if you decide to take the Cisco CCNA exam, you will undoubtedly come across it.
In this article, you will learn the basics of spanning tree protocol, including how it works, its various types and states. So, let’s get started and understand what is Spanning Tree Protocol or STP.
What is Spanning Tree Protocol (STP)?
Spanning Tree Protocol (STP) is a Layer 2 network protocol; it is used to stop loops from forming inside a network topology. It was developed to prevent the issues that occur when computers exchange data over redundant channels in a Local Area Network (LAN). Data can become trapped in a loop that circles network segments if traffic flow is not carefully monitored and controlled. This can affect performance and bring traffic to a virtual standstill.
If you have worked with network switches, you must have noticed that when we connect switches, there is some orange colour indication on the links, and then after 15-30 seconds, they turn to green colour.
Any idea why this happens and what’s the reason behind this?
The reason behind this mechanism is known as spanning tree protocol which avoids loops when you have multiple links between the switches.
Let’s understand this by an example, we have three switches, and we’ll connect all these 3 switches. Then we will see the colour states change from orange to green because the ports go through some listening and learning stages, and all the switches do an election process.


As you can see, the port states as well that they are going through listening and learning stages changes in colour as we have seen, but why is this all happening?
Let’s deep dive into spanning tree protocol now!
Before taking this deep dive, you should know that STP is an integral part of CCNA training.
Whenever we have multiple links for redundancy or multiple switches which are connected together, STP occurs automatically on the network switches because it takes care of avoiding loops in the network, or we can say that if all the ports are in up or forwarding states, then there will lot of broadcast request generated inside your network. To avoid these kinds of scenarios in the network, Spanning tree protocol is there.
- STP is an open standard protocol (IEEE 802.1D)
- STP avoids broadcast storms, database instability, loops, and multiple frame copies.
How many loops are there in the network?
When switches are linearly connected to each other, we have no chance of loops, but when multiple switches are connected, the loop can be there.
- Loop Scenario:

- Loop Scenario:

Now, let’s see how the spanning tree protocol works.
How Spanning Tree Protocol (STP) Works?
The working of STP is a 3-step process, which is –
- Selection of Root Bridge
- Selecting the Root Port
- Selecting the designated and non-designated port.
Spanning Tree Protocol works by selecting one of the switches as a head switch, considered as “Root Bridge.” So, what will happen as a result that now all of the frames in the network will only pass through the “Root Bridge?”
And all redundant/backup paths will be put in a blocking state. So, there will be only one path reach from source to destination. – Hence, there will be no loop.
- Selection of Root Bridge:
Before understanding the working, let’s understand what exactly this term “Root Bridge” is.
The root bridge is like the head in the L-2 topology and the most important switch, which has all ports in the forwarding state, which is selected by some election process.
So, let’s try to understand the selection of root bridges. For the first time, when we connect multiple switches together, we see that in 30 seconds, the port states change from orange to green. In that case, there is an election process between all the switches. All the switches are exchanging BPDUs (Bridge Protocol Data Unit).
In these BPDUs, all the connected switches exchange information like MAC Address, Priority number, port number, and all the necessary information to select the root bridge. When all the switches have exchanged their BPDUs with each other, the switch with the best (lowest) bridge-id is considered the root bridge.
Bridge-id = Priority + MAC Address
Note – Default priority value is 32768 on all switches
Out of all the switches in the network, one is elected as a root bridge, and it becomes the focal point in the network; the rest all the remaining switches are known as non-root bridges.
Let’s see with an example –
We have connected three switches, and we’ll verify the Spanning Tree Protocol of all switches.

As you can see from this image that when all three switches were exchanging the BPDUs with each other. All these are looking for the lowest bridge-id, a combination of “Priority + MAC.”
But in our scenario, we have the same priority value on all the devices, so there is a tie-in priority. So, now MAC will be the second option per the bridge-id concept, so the least MAC Address we have is 0030.A3E3.B975 is now considered our root bridge.
To verify – #show spanning-tree
- Selecting the root port:
The nearest port to the root bridge is known as the root port. Every non-root bridge will have one root port. (Shortest path to reach on root bridge) because every non-root bridge will for the best path to reach the root bridge.
We have some default STP port costs –
STP Port Cost | Link Type |
---|---|
100 | Ethernet (10 Mbps) |
19 | Fast Ethernet (100 Mbps) |
4 | Gig Ethernet (1000 Mbps) |
2 | Gig Link (10 Gbps) |
- Selecting the designated and non-designated ports:
Root Port – It’s always in the forwarding state and the best & shortest path to reach the root bridge.
Designated Port – These ports are also in upstate; they always forward the data.
Non-Designated Port – Ports that are in a blocking state.
These are three processes explaining how Spanning Tree Protocol works.
Now, let’s discuss the types of STP.
Types of Spanning Tree Protocol (STP)
There are 5 different types of STP listed below –
- STP (802.1D) – The original STP
- PVST – Per VLAN STP
- PVST+ – Per VLAN STP Plus
- RSTP (802.1W) – Rapid STP
- MSTP (802.1S) – Multiple STP
Moving on, let’s see various STP Ports.
Spanning Tree Protocol Ports
There are five ports used in STP –
- Root Port: The shortest path from a non-root switch to the root bridge.
- Designated port: Provides the best path from a switch to the root bridge, responsible for forwarding network traffic.
- Blocking port: Put into a “blocking” state to prevent loops, does not forward network traffic but remains in a listening and learning mode.
- Backup Port: Redundant path to the root bridge, ready to take over forwarding if the designated port fails.
- Alternate port: Backup path on switches not part of the active topology, transitions to forwarding if a designated port fails.
These are the five ports in STP. Let’s understand Spanning tree port states now.
Spanning Tree Port States
There are five stages through which a switch has to pass in STP.
- Disabled – This port does not forward any data, simply the blocked one.
- Blocking – This port will not forward frames or learn MAC addresses. It can only receive BPDUs from other switches.
- Listening – In this stage, the port will change its state from blocking to listening, where it’ll listen only; no forwarding or sending of BPDUs occurs here.
- Learning – The port will listen to the MAC addresses, and it can send and receives the BPDUs.
- Forwarding – From the learning stage, it’ll redirect to the forwarding stage.
These are the 5 Spanning Tree Port States.
Other terminologies associated with Spanning Tree Protocol
Port-Timer in STP

Hello Timer
It determines how often switches send BPDUs. By default, BPDUs are sent every 2 seconds.
Forward-Delay Timer
It shows how long a port must spend in both a learning and listening state.
(Listening to learning = 15 seconds)
(Learning to forwarding = 15 seconds)
Max Age Timer
It shows how long a switch will retain BPDU information from a neighbour switch before discarding it.
You can also watch PyNet Labs’ YouTube video and learn how to configure Spanning Tree Protocol. Click this link – https://www.youtube.com/watch?v=l-MlnTno65s
Frequently Asked Questions
Q1 – What is STP and its types?
STP, or Spanning Tree Protocol, is a network protocol that prevents loops in Ethernet networks. It designates a root bridge and calculates the shortest path to reach other switches, creating a loop-free topology. The main types of STP include Rapid Spanning Tree Protocol (RSTP), Multiple Spanning Tree Protocol (MSTP), Per VLAN spanning tree, Per VLAN spanning tree Plus, and STP (802.1D).
Q2 – What is vlan and STP?
VLAN (Virtual Local Area Network) is a logical segmentation of a network, while STP (Spanning Tree Protocol) is a network protocol that prevents loops in Ethernet networks. VLANs divide a network into separate broadcast domains, providing flexibility in managing network traffic, while STP ensures a loop-free topology by designating a root bridge and blocking redundant paths. Both technologies work together to enhance network performance and maintain stability.
Q3 – What does BPDU stand for?
BPDU stands for Bridge Protocol Data Unit, which is a data message exchanged between network switches in Spanning Tree Protocol (STP) to communicate information about network topology and to prevent loops.
Q4 – What is the purpose of STP?
The purpose of Spanning Tree Protocol (STP) is to prevent loops in Ethernet networks by creating a loop-free logical topology. It achieves this by designating a single switch as the root bridge and calculating the shortest path to reach other switches, while blocking redundant paths. STP ensures network stability, prevents broadcast storms, and enables efficient and reliable communication within the network.
Conclusion
In this blog, we have discussed what is spanning tree protocol, how it works, what are its different types, etc. If you are still with us, you have already learned most things about STP. If you want advanced STP knowledge, you should join PyNet Labs’ CCNP ENCOR training. We hope you liked this article; please share your valuable feedback in the comment box below. Check out the “All Courses” Section to learn more about what PyNet Labs offers. You can also check out what our students say about us by clicking the “Student Review” section.
Blogs you may like:
What is DHCP?
What is VTP?