Switching, Routing, and Why STP Exists

Last Updated:

Hardware / Software Requirements

NetworkNetwork10.4 and up
EnterpriseEnterpriseECS and ECS-S
Pro XGPro XGUSW-Pro-XG
Pro MaxPro MaxUSW-Pro-Max
Flex 2.5GFlex 2.5GUSW-Flex-2.5G
UltraUltraUSW-Ultra
Icon Layer 2 Switching vs. Layer 3 Routing

Layer 2 Switching vs. Layer 3 Routing

Modern networks use two forwarding models: routing (Layer 3) and switching (Layer 2).

Routers maintain routing tables and use protocols to compute efficient paths between networks. Ethernet switching takes a different approach: fast, inexpensive connectivity inside a local network.

Instead of calculating paths, switches rely on MAC learning. When a frame arrives, the switch records the source MAC address and the port it arrived on, building a forwarding table.

If the destination is known, the frame goes directly to that port. If it is unknown, the switch floods the frame to all other ports.

This makes switching extremely fast, but switches have no understanding of network topology, which creates a serious problem when redundant links exist.

Icon Why Ethernet Loops Are Dangerous

Why Ethernet Loops Are Dangerous

If redundant links connect two switches, frames can circulate in a loop indefinitely.

Switches flood looping traffic across multiple ports, and the volume escalates rapidly. The result is catastrophic network failure.

In a switching loop, the network effectively becomes an amplifier: a single frame can multiply into thousands within milliseconds.

Because Ethernet itself cannot prevent loops, networks rely on Spanning Tree Protocol (STP).

Icon How Spanning Tree Works

How Spanning Tree Works

STP forces the network to behave like a loop-free tree even when redundant links exist. It does this using control messages called Bridge Protocol Data Units (BPDUs).

Switches elect a Root Bridge as the reference point for the Layer-2 topology. Each switch then calculates its lowest-cost path to the root.

If BPDUs arrive from multiple directions, the switch keeps the best path and places the remaining ports into a blocking state, physically connected but not forwarding frames.

This creates a loop-free topology while preserving redundant links for failover.

Modern networks use Rapid Spanning Tree (RSTP), which converges much faster when topology changes occur. In effect, STP provides a form of “routing-lite” for switching, ensuring traffic follows a single safe path through the Layer-2 network.

Icon When Loops and Instability Appear in Real Networks

When Loops and Instability Appear in Real Networks

Switching loops rarely surface as clean protocol events. They usually appear as network instability.

Some dual-homed devices, including some smart speakers and wireless bridges, forward traffic between wired and wireless interfaces. When connected to multiple parts of the network, they can create Layer-2 loops. STP will eventually block one side of the loop, but during convergence the network may experience outages, high latency, or widespread packet loss.

Other dual-homed devices do not bridge traffic but still cause problems. Devices like streaming boxes or PCs may transmit from both wired and wireless interfaces at different times, making their MAC address appear on different ports, a behavior known as MAC flapping.

This forces switches to repeatedly relearn device locations, triggering flooding and topology change notifications that users experience as “flaky” networking.

Icon Protecting the Network Edge

Protecting the Network Edge

RSTP includes a feature called STP Edge, designed for ports connected to endpoint devices rather than other switches.

When STP Edge is enabled, the port immediately enters the forwarding state and skips topology recalculations. This prevents dual-homed devices from triggering unnecessary topology convergence events.

The tradeoff is that STP Edge assumes the connected device is not part of the switching topology. If an unmanaged switch or bridge is accidentally connected, the system won't be able to mitigate a real loop.

For this reason, STP Edge is paired with BPDU Guard. If a BPDU is received on an STP Edge port, the port is immediately disabled.

Icon UniFi's Approach

UniFi's Approach

UniFi can automatically enable STP Edge and BPDU Guard on ports connected to endpoint devices while allowing full STP participation on infrastructure links.

Icon Enable STP Edge and BPDU Guard on Endpoint Ports

Enable STP Edge and BPDU Guard on Endpoint Ports

For any port connected to a known endpoint, PCs, IoT devices, or other client devices, confirm that STP Edge and BPDU Guard are active. This prevents dual-homed devices from triggering unnecessary topology recalculations and protects the network if an unmanaged switch is accidentally connected.

Icon Disable Wireless Meshing on Wired Access Points

Disable Wireless Meshing on Wired Access Points

If an access point has a wired uplink, disable wireless mesh uplink. Leaving meshing enabled can create unintended alternate paths through the wireless network, introducing dual-homing behavior that may cause loops or MAC instability.

Icon Intentionally Design STP Root Placement and Priority

Intentionally Design STP Root Placement and Priority

Designate a stable, centrally located switch as the Root Bridge by assigning it the lowest STP priority. Assign progressively higher priority values to each subsequent downstream tier (aggregation/distribution, then access), ensuring that all switches within the same tier use the same priority value.

This approach provides deterministic path selection, stable convergence behavior, and prevents an access-layer switch from unexpectedly becoming the root.

UniFi Assistant

Frequently Asked Questions

We welcome thoughtful discussion related to this article.

To keep things on track, off-topic comments may be removed.