PyNet Labs- Network Automation Specialists

STP - Spanning Tree Protocol. How it Works and its Types!

Last Updated : August 22, 2022
spanning tree protocol

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 study the basics of spanning tree protocol, including how it works and its various types and states. So, let's get started and understand what is Spanning Tree Protocol or STP. 

What is Spanning Tree Protocol?

It is a Layer 2 network protocol also known as STP; it is used to stop loops from forming inside a network topology. STP 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. 

spanning tree protocol
spanning tree protocol

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. CCNA training is your entry into the networking domain, and your whole networking career depends on your CCNA knowledge. Therefore, it is very important to learn from the best. PyNet Labs has become the first choice of every aspiring network engineer for 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. 

  1. Loop Scenario: 
spanning tree protocol
  1. Loop Scenario: 
spanning tree protocol

Now, let's see how the spanning tree protocol works. 

How does Spanning Tree Protocol Works?

STP 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. 

The working of STP is a 3-step process, which is – 

  1. Selection of Root Bridge 
  1. Selecting the Root Port 
  1. Selecting the designated and non-designated port. 
  1. 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 STP of all switches.

spanning tree protocol

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 

  1. 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) 
Gig Ethernet (1000 Mbps) 
Gig Link (10 Gbps) 
  1. 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 STP:

  1. STP (802.1D) – The original STP, we are discussing now. 
  1. PVST – Per VLAN STP 
  1. PVST+ - Per VLAN STP Plus 
  1. RSTP (802.1W) – Rapid STP 
  1. MSTP (802.1S) – Multiple STP 

These are the five types of STP. 

Spanning Tree Port States

There are five stages through which a switch has to pass in STP. 

  1. Disabled – This port does not forward any data, simply the blocked one. 
  1. Blocking – This port will not forward frames or learn MAC addresses. It can only receive BPDUs from other switches. 
  1. 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. 
  1. Learning – The port will listen to the MAC addresses, and it can send and receives the BPDUs. 
  1. Forwarding – From the learning stage, it'll redirect to the forwarding stage. 

These are the 5 Spanning Tree Port States. 

Port-Timer in STP

spanning tree protocol

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. 

If you are still with us, you have already learned most things about Spanning Tree Protocol. If you want advanced STP knowledge, you should join PyNet Labs' CCNP ENCOR training.

You can also watch PyNet Labs' YouTube video and learn how to configure Spanning Tree Protocol. Click this link -

Blogs you may like:

What is DHCP?

What is VTP? 

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. 

Leave a Reply

Your email address will not be published. Required fields are marked *

linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram