What is Spanning Tree Protocol (STP) and How it works?

Spanning Tree Protocol Featured Image

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 or STP Protocol is a Layer 2 network protocol 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.

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!

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

History of STP Protocol

STP was developed by Dr. Radia Perlman in the 1980s. IEEE standardized it under 802.1D to address redundancy problems in Ethernet networks. Since then, updates like Rapid STP (RSTP) and Multiple STP (MSTP) have improved it.

Importance of Spanning Tree Protocol

Without STP, data loops can occur, causing data packets to circulate endlessly. This process consumes bandwidth, potentially bringing networks down. STP stops loops by blocking some paths, ensuring data moves efficiently.

How Spanning Tree Protocol Works?

STP uses Bridge Protocol Data Units (BPDUs) to exchange network information between switches. One switch becomes the root bridge, and all other switches determine the shortest route to it, creating a single, loop-free path for data.

The working of STP is a 3-step process, which is โ€“ 

  1. Selection of Root Bridge
  2. Selecting the Root Port
  3. 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.

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

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) 

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

Below, we have explained types of Spanning Tree Protocol.

ProtocolIEEE StandardKey DifferenceSwitch
STP (Spanning Tree Protocol)802.1DThe first version that started it all. Takes 30-50 seconds to recover from network changes. Works with one big tree for all VLANs.Old Cisco switches, basic managed switches
RSTP (Rapid Spanning Tree Protocol)802.1wMuch faster than STP – recovers in 1-3 seconds. Ports change states quickly. Backwards compatible with old STP.Most modern switches from all brands
PVST+ (Per VLAN Spanning Tree +)Cisco proprietaryMakes a separate tree for each VLAN. You can balance traffic across different paths. Uses more CPU and memory.Cisco switches only
RPVST+ (Rapid PVST+)Cisco proprietaryCombines fast recovery of RSTP with per-VLAN trees. Each VLAN gets its own fast tree. Best for Cisco networks.Cisco Catalyst switches
MSTP (Multiple Spanning Tree Protocol)802.1sGroups many VLANs into regions. Uses less CPU than PVST+. Good for big networks with lots of VLANs.Enterprise switches from all vendors 
PVRST (Per VLAN Rapid Spanning Tree)Based on 802.1wLike RPVST+ but works on non-Cisco gear. Each VLAN gets rapid recovery. Not as common.Some HP and Dell switches

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 Protocol Port States

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

Disabled

โ€ข The port is completely turned off – like unplugging the cable 

โ€ข No data goes in or out through this port at all 

โ€ข Network admins shut down ports on purpose, or the port might be broken 

Blocking

โ€ข The port stays awake but doesn’t send any data frames 

โ€ข It only listens for special STP messages called BPDUs from other switches 

โ€ข This state stops network loops by keeping some paths closed 

Listening

โ€ข The port wakes up from blocking and starts getting ready to work 

โ€ข It begins sending and receiving BPDUs to talk with other switches 

โ€ข Still no regular data passes through – the port checks if it’s safe to open 

Learning

โ€ข The port starts building a list of device addresses it hears on the network 

โ€ข It keeps exchanging BPDUs to stay updated about network changes 

โ€ข Regular data still waits – the port needs to know where devices are first 

Forwarding

โ€ข The port now sends and receives all network traffic normally 

โ€ข It keeps updating its address list as new devices join the network 

โ€ข This is the fully working state where actual data flows through the port 

Note: A port takes about 30 seconds to go from blocking to forwarding in old STP. Each stage (listening and learning) takes 15 seconds. Newer versions, such as RSTP, skip most of this wait time. 

What are STP Modes?

Before STP modes, we understand the beginning of STP (Spanning Tree Protocol), which Radia Perlman introduced in 1985. After the protocol evolved in many ways and new changes were introduced, the Institute of Electrical and Electronics Engineers (IEEE) organized it.

The following table shows an overview of the most frequently occurring Spanning Tree protocols, but these protocols do not support every bridge and switch. So, there are other spanning tree-inspired protocols that are not mentioned here.

ProtocolIEEE StandardSwitchDescription
Spanning Tree Protocol (STP)IEEE 802.1DstpThe Original STP Version
Rapid STP (RSTP)IEE 802.1wrstpAn evolution of STP 802.1D that addresses the STP Convergence time gap issue with enhanced BPDU exchange
Multiple STP (MSTP)IEEE 802.1smstpA format for mapping multiple VLANs into the same spanning tree to reduce processing on the switch
Per-VLAN Spanning Tree (PVST+)Cisco Protocol based on 802.1DpvstAn 802.1D enhancement that provides a separate STP instance for each VLAN configured in the network
Rapid PVST+Cisco Protocol based on 802.1wrapid-pvstAn 802.1w enhancement that provides a separate STP instance for each VLAN, enabling faster convergence times

The original protocol standards are indicated in the IEEE Standards column, and the IEEE commonly rearranges these standards, making it difficult to track which standard currently includes STP functionality. For example, in the 802.1D-2004 revision, 802.1D was updated to include 802.1w. The 802.1Q standard was launched in 2014 with more functionality than that specified in 801.1D.

The options used to specify the protocol mode when enabling STP on a bridge or switch are shown in the Switch column. To enable STP, a network manager connects to the device and then switches to global configuration mode and runs a command in the following format:

spanning-tree mode <protocol mode>

For example, Follow the below command to start Rapid STP (RSTP) on a switch

spanning-tree mode rstp

When STP is enabled, the manager must select a root bridge to act as the central STP reference point of the network, and the administrator also checks the root port and the specified port. (A root port is a bridge port that sends frames to the root bridge, whereas a specified port sends frames away from the root bridge).

Other terminologies associated with Spanning Tree Protocol

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.

STP Election Process

Transmission BPDU configurations, including their BIDs with a single switch, began to be considered root bridges. However, if a switch receives a BPDU with a high (low value) BID, then the switch configuration will hinder evolving BPDUs and will instead transfer these larger BPDUs to its neighbouring switches.

When the root bridge is declared, a second election process is initiated to regulate the “root port” selection process. The process will follow the following steps until the root port is elected:

  • A switch port receives more BPDUs from another switch and investigates that switch as the root bridge.
  • The port with the lesser root path is chosen as the root port.
  • If the path cost is the same, the switch selects the port with the lower receiver BID as the chosen root port.
  • If the receiver BID is the same (usually the same switch), the port with the lower manual port number on the receiver switch is selected as the root bridge (as the final tiebreaker).

Benefits of STP Protocol

The benefits of the STP protocol are:

  • Stops network loops: When switches connect in circles, data packets can go round and round forever. STP finds these loops and blocks some paths to prevent this problem.
  • Creates backup paths: If your main network cable breaks, STP quickly opens a blocked path. Your network keeps working without you doing anything.
  • Works by itself: Once you turn on STP, it runs on its own. Network admins don’t need to watch it all day. It finds problems and fixes them.
  • Saves network resources: Without STP, loops eat up all your network speed. One small loop can crash your whole network. STP keeps things running smoothly.
  • Easy to set up: Most switches have STP turned on already. You just plug them in, and they start working together to prevent loops.
  • Protects against mistakes: Someone might plug cables wrong by accident. STP catches these errors before they cause big problems.

Drawbacks of STP

Some of the drawbacks of STP are:

  • Makes networks slower: STP takes time to check all paths and decide which ones to block. This can add delays when sending data.
  • Wastes good connections: You might have fast cables that STP blocks. These expensive links sit there doing nothing while data takes slower paths.
  • Takes time to fix problems: When a link fails, STP needs 30-50 seconds to open new paths. During this time, your network stops working.
  • Hard to predict paths: You can’t always tell which path your data will take. This makes it challenging to plan network speed and fix issues.
  • Old technology limits: Basic STP can only handle small networks. Big networks need newer versions that cost more money and need more setups.
  • Blocks half your network: In some setups, STP might block 50% of your network links. You pay for equipment you cannot fully use.

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

The Spanning Tree Protocol is an essential component of modern networking. It ensures loop-free, efficient data paths even in complex network setups. As networks grow and demand more robustness, understanding STP and its variations can empower network professionals to design and maintain reliable systems. 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.

, ,

Leave a Reply

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