the sun is setting over a body of water
Fri Dec 30

What is Spanning Tree Protocol (STP) in Networking?

If you want to learn about STP, it would be easier if you understand a bit of graph theory. Let’s take an example of the scenario we have made beforehand in the [switching loop post](https://www.binaryte.com/blog/what-is-switching- loop). I recommend you to read the post first to get a better understanding of what we are going to learn.

By having this concept in mind, we should have known what the spanning tree really is.

The concepts of complete graph

Look at the diagram below.

Complete
Graph.png

Graphs consist of vertices (V) and edges (E). This triangular shape above is considered as a complete graph, where each distinct pair of vertices is connected by an edge. In other words, the complete graph is the graph with the maximum number of lines. By the definition, we can take another example of a complete graph of four vertices just like the above example.

The concept of spanning tree

Spanning tree is basically the minimum number of edges possible to connect all vertices. Taking the same example as above with three and four vertices, we have these possible spanning trees.

Spanning
tree.png

As we can see, three vertices can form three different spanning trees and four vertices have sixteen different spanning trees possibilities. At this point, you might find something interesting. In comparison to a complete graph, the spanning tree has no loop.

Referring to three vertices spanning trees above, let’s say we try to disconnect the line that joins A to C or disconnect D in four vertices spanning tree possibilities, is it still considered a spanning tree? The answer is no.

By the definition stated at the very first sentence in this section, we know that spanning tree needs to connect all vertices without exception. Thus, we can conclude three important points of spanning tree concepts.

  • It requires the minimum possible edges to connect all the vertices.
  • It has no loop.
  • All vertices need to be connected by a single line.

**What is STP? **

Spanning tree protocol (STP) is a protocol that operates on layer 2 of the OSI model that ensures a loop-free network topology by blocking certain link and enabling others.When STP is enabled on a network, switches communicate with each other to determine the best path for data packets to travel through the network. The concept of spanning tree helps us visualize the link between the switches.

Types of STP

IEEE 802.1D STP

This is what we are going to talk about and the original version of STP. It was developed by Institute of Electrical and Electronics Engineers (IEEE), designed to create a loop-free network and at the same time providing the fault tolerance backup links in case the active link fails.

IEEE 802.1w Rapid STP (RSTP)

The enhanced version of STP that provides even more rapid recovery in case of network failure. RSTP has backward-compatibility with STP.

**PVST+ & Rapid PVST+ **

Cisco proprietary protocol with added per VLAN feature.

IEEE 802.1Q Multiple STP

While STP and RSTP only allow single instances, MSTP allows multiple instances where an instance is a group of VLANs.

Why do we need STP?

By its definition, we know that the main purpose of STP is to eliminate loops in a network. As well as this, it offers many other benefits.

Another important benefit of STP is that it increases network stability. By preventing loops and ensuring a stable network topology, STP helps to ensure reliable network performance. This is especially important in large networks, where a single loop can have a significant impact on the entire network.

STP also allows for easy expansion and reconfiguration of a network. By allowing switches to communicate with each other and dynamically adjust the network topology as needed, STP makes it easy to add or remove devices from the network without disrupting network connectivity.

How does STP work?

STP works by following three basic steps.

  • Elect one switch as root bridge
  • Choose the least cost from the switch to root bridge
  • Block costly links and set it as backup

You can find more detailed information here.

Summary

In summary, STP is an essential networking protocol that helps to ensure stable and reliable network performance. It is a layer 2 protocol that operates at the data link layer of the OSI model. STP works by using algorithms to dynamically selecting a root bridge as central point that interconnects all other devices within a network and blocks links that may cause the switching loops and at the same time use it as a backup link.