Switching basics: MAC learning & flooding
Short answer
A switch learns which port leads to each MAC address by reading the SOURCE MAC of every frame it receives. It then forwards a frame only out the port where the destination MAC was learned, and floods it out every other port when the destination is unknown or is the broadcast address.
An Ethernet switch builds a table of MAC addresses by listening to the source MAC of every frame that arrives. This lesson walks through MAC learning step by step and explains exactly when a switch floods a frame versus forwarding it to a single port.
Open this labFrames, MACs, and the L2 game
An Ethernet switch operates at Layer 2. It does not look at IP addresses; it makes forwarding decisions based on the destination MAC address in the frame header. Every interface on every device has a unique 48-bit MAC address, written like 00:1A:2B:3C:4D:5E.
A switch starts life knowing nothing. As traffic arrives, it observes the source MAC in each incoming frame and records: 'MAC X is reachable through port Y'. Over time, the switch builds a complete map of which MAC sits where.
Flood vs forward
When a frame arrives, the switch looks up the destination MAC in its table:
- Hit — the destination MAC is known: forward only out the matching port.
- Miss — the destination MAC is unknown: flood the frame out every port except the ingress port.
- Broadcast (FF:FF:FF:FF:FF:FF) — always flood, regardless of table state.
Walking through a first conversation
Imagine PC1 wants to ping PC2. PC1 sends an ARP request — a broadcast frame asking 'who has 10.0.0.20?'. The switch floods it to every port. PC2 replies; the reply is a unicast frame back to PC1's MAC. The switch now learns PC2's MAC against PC2's port. From then on, traffic between PC1 and PC2 is forwarded directly — no flooding required.
Hubs, switches, and why hubs lost
A hub is a Layer 1 device — a multi-port repeater. Every frame goes out every other port, every time. There is no learning, no forwarding logic, just electrical repetition. This means every hub creates one giant collision domain, and any two hosts transmitting at once corrupt each other.
A switch creates one collision domain per port. Hosts can transmit simultaneously without interfering, dramatically increasing usable bandwidth. This is why hubs disappeared from production networks two decades ago.
Common questions
- Does a switch look at IP addresses?
- A Layer 2 switch does not: it forwards on the destination MAC address in the Ethernet header. Routing between IP subnets needs a router or a Layer 3 switch.
- When does a switch flood a frame?
- When the destination MAC is not in its MAC address table yet, and always for broadcast frames. It never sends the frame back out the port it arrived on.
- How do I see what a switch has learned?
- Run show mac-address-table on the switch. In the NetForge-AI lab the table fills in as you ping between PCs.
Practice this in the lab
Reading helps. Wiring it up yourself and breaking it makes it stick.
Open the lab