STP (Spanning Tree Protocol)
Definition
Spanning Tree Protocol (STP) is a Layer 2 protocol that prevents loops between switches when multiple physical paths exist.
Its role is to ensure that only one active path is used for forwarding traffic while keeping other paths available as backups in case the active path fails.
The Problem That Led to It
Imagine a company has one switch connecting all employees.
Router
|
Switch-1
/ | \
PCs PCs PCs
Everything works well because there is only one path. Later, the company grows and adds more switches.
Router
|
Main Switch
/ \
Switch-A Switch-B
Still no problem because each switch has only one connection.
Now management says: "If one cable breaks, we don't want the whole department to lose the network."
So engineers add a backup cable.
Main Switch
/ \
Switch-A ---- Switch-B
Now there are two paths between the switches.
This provides redundancy, but it also creates a new problem.
When a broadcast frame is sent, it can travel around the loop forever.
Switch-A ↓ Main Switch ↓ Switch-B ↓ Switch-A ↓ ...
This creates:
- Broadcast storms
- Duplicate frames
- MAC address table instability
- Network congestion
So how can this problem be solved?
A protocol is needed that keeps the backup link but prevents loops.
That protocol is STP.
What Problem It Solves
STP automatically detects redundant Layer 2 paths and temporarily blocks one of them.
Example:
Before STP:
Main Switch
/ \
Switch-A ---- Switch-B
After STP:
Main Switch
|
|
Switch-A
|
Switch-B
Blocked Link: Main Switch ----X---- Switch-B
The blocked link is not removed—it stays ready as a backup.
If the active link fails, STP unblocks the backup link and traffic continues through the new path.
What Happens If Not Used
Without STP:
- Broadcast frames circulate forever.
- Switches repeatedly learn different MAC addresses on different ports.
- Duplicate frames reach devices.
- The network becomes slow or completely unusable.
Even though redundancy was added to improve reliability, the network becomes less reliable without STP.
Easy Wording
STP allows multiple network paths for safety but keeps only one active at a time to prevent data from endlessly circulating.
Layman Example
Imagine three cities connected by three roads in a triangle.
A delivery truck enters the roads.
Without traffic control, the truck can keep driving around the triangle forever.
STP acts like a traffic controller.
It temporarily closes one road so vehicles can still reach every city without driving in circles.
If the open road is blocked due to an accident, the closed road is reopened automatically.
Technical Example
A company has three switches on different floors.
Core Switch
/ \
Floor-1 ------- Floor-2
Before redundancy Traffic from Floor-1 to the Core:
PC ↓ Floor-1 Switch ↓ Core Switch ↓ Router ↓ Internet
Only one path exists.
After redundancy is added To protect against cable failure, another connection is installed.
Core Switch
/ \
Floor-1 ------- Floor-2
Traffic now has two possible paths.
Without STP:
Floor-1 ↓ Core ↓ Floor-2 ↓ Floor-1 ↓ ...
Frames loop forever.
With STP:
- STP elects one switch as the Root Bridge.
- It calculates the best path to the Root Bridge.
- It places one redundant port into the Blocking state.
- Traffic uses only one active path.
- If the active link fails, STP unblocks the backup port and restores connectivity.
Limitation
Classic STP prevents loops but has a major drawback:
- It can take approximately 30 to 50 seconds to recover after a link failure.
- During this recovery time, users may temporarily lose network connectivity.
This recovery time is too slow for modern enterprise networks where interruptions should be minimal.
Solution
To solve STP's slow recovery time, the IEEE introduced Rapid Spanning Tree Protocol (RSTP - IEEE 802.1w).
RSTP performs the same loop prevention as STP but converges much faster—typically within a few seconds or less—making failover almost unnoticeable in modern networks.