Computer Networks

[Day 9] 3. Spanning Tree Protocol (STP)

D
DITISS Admin
••6 min read

Spanning Tree Protocol (STP) prevents the looping of the frame by putting the interfaces of the switch in either forwarding or blocking state. How Switch is able to decide which interface should be in forwarding or blocking state?

  • BID – It stands for Bridge ID. It is an 8-byte value unique to each switch. The first two bytes are priority bytes and the remaining six bytes contain the built-in MAC addresses of the switch.
  • BPDU – Bridge protocol data unit is a message that switches exchange b/w them. Commonly used BPDU is Hello. It contains cost and BID. These are sent every 2 secs. Only root ports will send BPDUs. The BPDUs from non-root ports are known as inferior BPDUs and are ignored.
  • Path Cost – It is a numeric value given to link between two interfaces based on the speed of the interface. The higher the link speed, the lower will be the cost.

| IEEE | STP Cost | | -------- | -------- | | 10 Mbps | 100 | | 100 Mbps | 19 | | 1 Gbps | 4 | | 10 Gbps | 2 | | 100 Gbps | 1 | Shorter Route Cost is preferred in case of switches.


STP Port States and Selection Criteria

STP (Spanning Tree Protocol) uses three criteria to determine which interfaces will be in forwarding or blocking states:

  • Root Switch Selection: The root switch is selected, and all of its interfaces are placed in a forwarding state.
  • Root Port Selection: For all non-root switches, a root port is chosen. The root port is the interface with the lowest path cost to the root switch. All root ports are placed in a forwarding state.
  • Designated Switch Selection: The switch with the lowest root cost (the shortest path to the root switch) is designated as the Designated Switch. The port on the Designated Switch from which the root cost is calculated is called the Designated Port (DP). The DP is placed in a forwarding state.

|Port Type|STP State| |---|---| |All ports of the root switch|Forwarding State| |Root port of a non-root switch|Forwarding State| |Designated Ports|Forwarding State| |All other operational ports|Blocking State|


Actual Process

Electing Root Switch : 

All switches in a LAN exchange Hello BPDU with each other. Firstly all switches consider themselves root switches but the root switch is selected based on the BID of a switch. A switch having a lower priority bit in BID is a selected root switch. If the priority bit gets tied, then the switch has a lower MAC address in Hello BPDU is the selected root switch.

Choosing Root port on Non-root Switches : 

The ports in each switch having minimum path cost to the root switch are chosen as the root port for that switch. Root port is the shortest path to the root switch.


Steps:
  1. Electing Root switch
  2. Choosing Root port
  3. Accordingly designated ports are defined.
  4. If two designated ports exist on the same link, STP will determine which port should be blocked based on the root path cost and the priority of the switches. The port on the switch that is farther away from the root switch (higher path cost) will be put into a blocking state.

For SWID (Switch ID), Priority (0 - 65535) + MAC address Default value of Priority is 32768.


If in some case, for root port elections: If the cost of 2 ports comes out to be same, then these criteria are considered: first root cost, then Neighbor ID, and finally Port ID.

  • Root Cost:
    • The first criterion for selecting the root port is the path cost to the root switch. The port with the lowest cost is preferred.
  • Neighbor ID:
    • If two ports have the same root cost, the switch will compare their Neighbor IDs (which are part of the Bridge ID). The port with the lower Neighbor ID is preferred.
  • Port ID:
    • If the Neighbor IDs are also the same, the Port ID (which is unique for each port on the switch) is considered. Since Port IDs are unique on a switch, this will effectively resolve any ties.

If the election for Non-Designated Ports are tied: First compare the root cost, if the root costs are same then compare the switch IDs. They can't be same since the switch IDs contain MAC address and they are always unique.

  • Root Cost:
    • The first criterion to resolve ties among Non-Designated Ports is to compare the root costs. The port with the lower root cost is preferred.
  • Switch IDs:
    • If the root costs are the same, the next step is to compare the Bridge IDs (which include the switch's MAC address). Since MAC addresses are unique, this comparison will always resolve any ties.

Stages in STP

  • Blocking:
    • In this state, ports do not forward frames to prevent loops. They listen for BPDUs but do not participate in frame forwarding.
  • Listening:
    • Ports transition to this state to prepare for possible forwarding. They still do not forward frames but begin processing BPDUs to determine the network topology.
  • Learning:
    • In this state, ports learn the MAC addresses of devices on the network. They still do not forward frames but start building the MAC address table.
  • Forwarding:
    • Ports in this state actively forward frames to and from the network. They also continue to learn MAC addresses and send BPDUs.

To complete the process and start forwarding, it takes 50s.


Read Next

8/26/2026

[Day 9] 4. Types of STP

### **Types of STP** 1. **CST (Common Spanning Tree)** - A single spanning tree is used for the entire network, regardless of the number...

8/26/2026

[Day 9] 5. Virtual Local Area Network (VLAN)

### **Introduction** A **VLAN** creates logical partitions within a physical switch, allowing for better traffic management, security, and network...