Introduction to Spanning Tree

Spanning tree is a protocol that runs on our switches that helps us to solve loops. Spanning tree is one of the protocols that you must understand as a network engineer and you will encounter it for sure if you decide to face the Cisco CCNA R&S exam. This lesson is an introduction to spanning tree, you will learn why we need it, how it works and how you can check the spanning tree topology on your Cisco switches.




Why do we need spanning tree?

What is a loop, and how do we get one? Let me show you an example:

switches single cable

In the picture above, we have two switches. These switches are connected with a single cable, so there is a single point of failure. To get rid of this single point of failure, we will add another cable:

switches redundant cable

With the extra cable, we now have redundancy. Unfortunately for us, redundancy also brings loops. Why do we have a loop in the scenario above? Let me describe it to you:

  1. H1 sends an ARP request because it’s looking for the MAC address of H2. An ARP request is a broadcast frame.
  2. SW1 will forward this broadcast frame on all it interfaces, except the interface where it received the frame on.
  3. SW2 will receive both broadcast frames.

Now, what does SW2 do with those broadcast frames?

  1. It will forward it from every interface except the interface where it received the frame.
  2. This means that the frame that was received on interface Fa0/0 will be forwarded on Interface Fa1/0.
  3.  The frame that was received on Interface Fa1/0 will be forwarded on Interface Fa0/0.

Do you see where this is going? We have a loop! Both switches will keep forwarding over and over again until the following happens:

  • You fix the loop by disconnecting one of the cables.
  • One of your switches will crash because they are overburdened with traffic.

Ethernet frames don’t have a TTL (Time to Live) value, so they will loop around forever. Besides ARP requests, many frames are broadcasted. For example, whenever the switch doesn’t know about a destination MAC address, it will be flooded.

How spanning tree solves loops

Spanning tree will help us to create a loop-free topology by blocking certain interfaces. Let’s take a look at how spanning tree work! Here’s an example:

switches in triangle

We have three switches, and as you can see, we have added redundancy by connecting the switches in a triangle, this also means we have a loop here. I have added the MAC addresses but simplified them for this example:

  • SW1: MAC AAA
  • SW2: MAC BBB
  • SW3: MAC CCC

Since spanning tree is enabled, all our switches will send a special frame to each other called a BPDU (Bridge Protocol Data Unit). In this BPDU, there are two pieces of information that spanning tree requires:

  • MAC address
  • Priority

The MAC address and the priority together make up the bridge ID. The BPDU is sent between switches as shown in the following picture:

switches send bpdu

Spanning tree requires the bridge ID for its calculation. Let me explain how it works:

  • First of all, spanning tree will elect a root bridge; this root bridge will be the one that has the best “bridge ID”.
  • The switch with the lowest bridge ID is the best one.
  • By default, the priority is 32768, but we can change this value if we want.

So who will become the root bridge? In our example, SW1 will become the root bridge! Priority and MAC address make up the bridge ID. Since the priority is the same on all switches, it will be the MAC address that is the tiebreaker. SW1 has the lowest MAC address thus the best bridge ID and will become the root bridge.

The ports on our root bridge are always designated, which means they are in a forwarding state. Take a look at the following picture:

stp root elected

Above, you see that SW1 has been elected as the root bridge and the “D” on the interfaces stands for designated.

Now we have agreed on the root bridge, our next step for all our “non-root” bridges (so that’s every switch that is not the root) will have to find the shortest path to our root bridge! The shortest path to the root bridge is called the “root port”. Take a look at my example:

stp rootport selected

I’ve put an “R” for “root port” on SW2 and SW3. Their Fa0/0 interface is the shortest path to get to the root bridge. In my example, I’ve kept things simple, but “shortest path” in spanning tree means it will actually look at the speed of the interface. Each interface has a certain cost, and the path with the lowest cost will be used. Here’s an overview of the interfaces and their cost:

  • 10 Mbit = Cost 100
  • 100 Mbit = Cost 19
  • 1000 Mbit = Cost 4

Excellent!…we have designated ports on our root bridge and root ports on our non-root bridges, we still have a loop, however, so we need to shut down a port between SW2 and SW3 to break that loop. So which port are we going to shut down? The one on SW2 or the one on SW3? We’ll look again at the best bridge ID:

  • Bridge ID = Priority + MAC address.

Lower is better, both switches have the same priority, but the MAC address of SW2 is lower, which means that SW2 will “win this battle”. SW3 is our loser here which means it will have to block its port, effectively breaking our loop! Take a look at my example:

stp alternate port

We're Sorry, Full Content Access is for Members Only...

If you like to keep on reading, Become a Member Now!

  • Learn any CCNA, CCNP and CCIE R&S Topic. Explained As Simple As Possible.
  • Try for Just $1. The Best Dollar You’ve Ever Spent on Your Cisco Career!
  • Full Access to our 803 Lessons. More Lessons Added Every Week!
  • Content created by Rene Molenaar (CCIE #41726)
469 Sign Ups in the last 30 days
satisfaction-guaranteed

  • 100% Satisfaction Guaranteed!
  • You may cancel your monthly membership at any time.
  • No Questions Asked!

Tags:


Forum Replies

  1. Could you please post some details about RSTP and MSTP.

    Thanks In Advance.

  2. I will add those in the future, no problem.

  3. Possibly the best and simplest explanation I have read, excellent work

  4. Rene,

    Thanks for explaining this. It’s very clear and informative.

    I would like to ask you about what software or stencils (if you use Visio) you use for your diagrams? I really like them and I would like to use something like it for my own (personal) home network.

    Looking at the picture quality, I’m going to assume it’s a Mac OS X based software! Can you please advise?

    Thanks again mate.

214 more replies! Ask a question or join the discussion by visiting our Community Forum