How STP (Spanning Tree Protocol) Works?

In computer networks, the Spanning Tree Protocol (STP) stops loops. In this article, we’ll look at how STP works on Layer 2 Switches with GNS3.

We’ll explore the selection of Designated, Root, and Blocked Ports. Plus, we’ll go over setting up STP and analyzing packets with Wireshark. If you want to know more about this protocol, keep reading!

How Does STP Work?

Exploring How Spanning Tree Works Using GNS3

The Spanning Tree Protocol (STP) stops loops in OSI layer 2 networks. It does this by making a spanning tree topology. So this means there’s a path for data to go without loops.

The protocol makes sure there’s only one path active between devices. Plus, it picks a root bridge automatically. Basically, this stops extra links from being used.

Spanning Tree keeps the network stable, especially in extensive networks. It handles lots of paths between devices well. Plus, it stops congestion and broadcast storms. And it ensures there are no problems with network loops.

So, it stops network loops, making sure packets get where they need to go on time. That really boosts how well the whole network works.

Understanding How Does Spanning Tree Work

When setting up STP, we look at picking Designated, Root, and Blocked Ports. Because of that, it makes a logical tree shape to stop network loops.

The protocol picks a Root Bridge and then decides on Designated Ports. These ports send traffic to the Root Bridge. On the segment, Spanning Tree blocks other ports to stop traffic. In short, this algorithm works by switches exchanging BPDUs.

By looking at the info in the BPDUs, switches figure out what roles ports should have. Then, they decide which ports should do what jobs in the network topology.

How Does STP Protocol Select Its Root Port, Designated Port, or Blocked Ports?

Preventing loops is super essential for having a backup in the network. That’s where the STP comes in. So, it, which works on Layer 2, stops ports to avoid loops. This means there’s just one primary way for data to go.

Now, let’s use GNS3 to make and try out the STP port states.

Step 1

To start an STP project, first, open the GNS3 software. Then, create a new network project. After that, set up the components and settings you need for your design.

Creating a New Network Project in GNS3

Step 2

Add three Layer 2 switches to your GNS3 workspace. These switches are essential for simulating networks. Moreover, they help you make a virtual setup for testing and fixing network problems.

Adding Layer 2 Switch

Step 3

Once you’ve added three Layer 2 devices, start them all up and open the command prompts. In this setup, I’ve set all the Switches’ ports to GigabitEthernet. So, the GigabitEthernet Cost value for STP is 4.

To pick a Root Bridge, we’ll find the Switch with the smallest MAC address first. If we don’t choose the root device ourselves, it will figure it out automatically by looking at the MAC addresses.

To get the MAC address of the Cisco Switch SW1, go to its command line prompt. Then, type in the show spanning-tree command.

show spanning-tree

Step 4

As you can see in the image below, the MAC Address of SW1 is 00ff.9ee9.8a00. Let me give you additional information: you can understand the logic better if you work by adding notes to the work area. Now, let’s learn the SW2 and SW3 MAC addresses.

Switch MAC Address

Step 5

Likewise, run the same command on the Switch SW2 command prompt. This time, you can see the MAC address of SW2.

L2 Switch MAC Address

Step 6

The MAC address of SW3 is 00ff.9e54.7700, as you can see in the image below. Now, let’s examine the priority values of all switches and compare them.

Switch Priority Value

Step 7

The show spanning-tree shows Cisco Switch Priority values. By default, all switches have a Priority value of 32769.

As you can see, the Priority value of SW1 is 32769.

Priority Default Value: 32769

Step 8

Since we did not manually change the priority values, the value of SW2 remains at 32769. So, this indicates that it has the default Priority value.

show spanning-tree command

Step 9

We’ve got the MAC addresses and Priority values of Cisco Switches. Since all Priority values are the same, the Switch with the smallest MAC address becomes the Root Bridge.

Therefore, SW2 is a Root Bridge. Now, let’s examine the ports selected by the Spanning Tree.

Run the show spanning-tree command on SW2. In the command output, you’ll notice that the Gig0/0 and Gig0/1 interfaces are Designated Ports. That’s because the interfaces of a Switch you pick as the Root Bridge will always be Designated. So, the Root device keeps sending BPDU packets to others regularly.

Examining Port Status of GigabitEthernet Interfaces

Step 10

As SW2 is the Root Bridge, SW1 and SW3 will choose their ports as Root Ports. This occurs because the Cost values of SW1 and SW3 interfaces are equal to those of SW2.

If we had made the connection between SW2 and SW3 with FastEthernet, things would have changed. This time, the SW3 GigabitEthernet 0/1 interface would be “Blocked.” This is because the FastEthernet Cost value is 19.

We can see the details in the show command output of SW1 and SW3. Examine the CLI and verify that the ports are Root Ports.

Root Port

Step 11

One of the remaining interfaces will be “Blocked” because a loop will occur in the network environment. Since the primary purpose of the STP is to prevent loops, SW2’s GE 0/1 interface will be “Blocked.”

If we consider the interfaces between SW2 and SW3, we again consider the smallest MAC address. As a result, SW3’s ID is a Designated Port because it is smaller.

Designated Port

Step 12

You can analyze STP packets using Wireshark. Thus, right-click on the link or start capturing to see the packets sent between SW1 and SW2.

Package Analysis with Wireshark

Step 13

Check the ethernet card in the Packet Capture window and click the OK button.

Packet Capture

Step 14

When you open Wireshark, it starts analyzing packets right away. As shown in the picture below, the STP protocol works smoothly between Layer 2 Switches.

STP Protocol

STP Show Commands

Spanning Tree Command Comparison
1) show spanning-tree summaryIt shows summary information of the entire STP algorithm tree in the network.
2) show spanning-tree detailIt shows detailed information for each VLAN as well as summary information.
3) show spanning-tree rootIt shows the information of the root bridge in the algorithm tree.
4) show spanning-tree interface GigabitEthernet 0/0It shows STP tree information for a specific interface (in this example, GigabitEthernet 0/0).

1) show spanning-tree summary

show spanning-tree summary command output

2) show spanning-tree detail

show spanning-tree detail command output

3) show spanning-tree root

show spanning-tree root command output

4) show spanning-tree interface gigabitEthernet 0/0

show spanning-tree interface gigabitEthernet 0/0 command output

Understanding How STP Works > Video

If you want to know more about how it works, we’ve got you covered. Watch our detailed video review below. Also, if you’re going to support us, please subscribe to our YouTube channel. Thanks a lot!

Frequently Asked Questions (FAQ) About STP Working Logic

  1. How does the STP election process work?
The STP selection process looks at the lowest Bridge ID of all Switches in the LAN. It sends BPDUs to find this value. We see this ID in two ways. For Bridge ID, we look at both the device’s MAC address and Bridge Priority values. In short, the lowest Bridge ID refers to the Root Bridge that will be central in the topology.
  1. How does a spanning tree protocol work?
In simple terms, this protocol makes sure all Switches in the network can work together. It helps them communicate better and makes sure there are no loops in the setup. In terms of physical setup, the main line of the network becomes the Root Bridge. Other devices make a tree structure below it. This means they decide which ports are Root, Designated, and Blocked in the LAN.
  1. What is the mechanism of STP?
STP’s job is to make a tree shape with switches, making sure there are no loops in the network. It picks a Root device and shuts down extra routes in the network. This means there’s only one main path between any two devices. If a link goes down, it figures out a new path automatically.


To sum up, STP is essential for stopping loops and keeping OSI layer 2 networks stable. By making a logical tree shape and choosing ports, this protocol stops loops and congestion. Also, it makes the network work better from loops. GNS3 helps you simulate and try out different STP setups, too.

Knowing how STP works is really important. Using it in network setups makes sure everything stays stable and efficient. In short, this helps build a strong network that lasts a long time.

Add a Comment

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