Computer Networks

Switch

A data-link device that forwards frames by MAC and splits collision domains.

Level: beginner

What is it?

An Ethernet switch is a multiport bridge that forwards frames using a MAC-address forwarding database, typically scoped by VLAN. Modern switches often include many additional functions but basic L2 switching uses source learning and destination lookup.

Why does it matter?

Switches allow local networks to scale beyond a shared medium. Correct learning, VLAN configuration, and loop prevention keep traffic localized and protect the network from broadcast storms.

Mental model

Learn where a source MAC was seen, then use the destination MAC to choose an egress port. Unknown destinations may be flooded within the VLAN; known unicast traffic is sent only where needed.

How it works

  • The switch learns source MAC addresses and associates them with ingress ports.
  • Forwarding decisions use the destination MAC and VLAN context.
  • Broadcast and unknown-unicast frames may be flooded to eligible ports in the VLAN.
  • Spanning Tree Protocol or related mechanisms prevent redundant L2 links from forming forwarding loops.
  • Layer-3 switches add routing capabilities, but those are distinct from basic L2 forwarding.

Steps

  • Receive a frame on a port and identify its VLAN context.
  • Learn or refresh the source MAC-to-port entry.
  • Look up the destination MAC; forward to the known egress port when allowed.
  • If unknown or broadcast, flood only eligible ports in the same VLAN, excluding the ingress port.

Real-world usage

  • Troubleshooting missing MAC entries, VLAN mismatch, and broadcast flooding.
  • Explaining campus LAN forwarding behavior.

Common mistakes

  • Assuming switch forwarding uses IP addresses in basic L2 mode.
  • Ignoring VLAN context in a MAC-table lookup.
  • Forgetting redundant links can create layer-2 loops without appropriate control.

Interview questions

How does a switch learn a host's location?

It records the source MAC address and incoming port from a received frame, scoped to the relevant VLAN.

Does a switch always flood unknown unicast frames?

Many switches do by default within the VLAN, but behavior can be affected by configuration and security features.

Prerequisites

Related concepts

Continue learning

Browse the full computer science library