Switching Basics

How Layer 2 Switches Work: MAC Tables and Forwarding

A Network Switch is a Layer 2 device that connects devices within a Local Area Network (LAN) and uses MAC addresses to forward data to the correct destination. Unlike a hub, which broadcasts data to everyone, a switch intelligently directs traffic.

The MAC Address Table (CAM Table)

The core of switching logic is the MAC Address Table (Content Addressable Memory). This table maps MAC addresses to specific switch ports and VLANs.

How a Switch Learns (The Process)

  1. Learning (Source MAC): When a frame enters a port, the switch reads the Source MAC address. If it's not in the table, the switch adds it, associating it with that port and VLAN.
  2. Forwarding (Destination MAC): The switch then looks at the Destination MAC address.
    • Known Unicast: If the destination MAC is in the table, the switch forwards the frame only to that specific port.
    • Unknown Unicast / Broadcast: If the destination MAC is not in the table (or is FFFF.FFFF.FFFF), the switch floods the frame out all ports (except the incoming one).

Aging Timer

MAC address entries do not stay in the table forever. To keep the table current and save memory, switches use an Aging Timer.

Frame Switching Methods

Switches use different methods to process and forward frames:

1. Store-and-Forward

The switch receives the entire frame and checks it for errors (CRC check) before forwarding. It is the most reliable but has higher latency.

2. Cut-Through

The switch starts forwarding the frame as soon as the Destination MAC is read. It is faster (lower latency) but may forward corrupted frames.

VLAN Tables

Switches also maintain VLAN information. The MAC table includes the VLAN ID for each entry. Traffic from one VLAN is never forwarded to a port in a different VLAN (unless routed by a Layer 3 device).

Switch# show mac address-table
          Mac Address Table
-------------------------------------------

Vlan    Mac Address       Type        Ports
----    -----------       --------    -----
   1    0001.42a1.3e01    DYNAMIC     Fa0/1
  10    0002.1b2c.4d02    DYNAMIC     Fa0/2
  20    0003.5c3d.5e03    DYNAMIC     Fa0/3
Key Takeaway: Switches learn from the Source MAC and forward based on the Destination MAC.