Computer Networks

Layer 2 — Data Link

Hop-to-hop frames: MAC addresses, Ethernet, switches, and error detection.

Level: beginner

What is it?

Layer 2 moves a frame between two NICs on a single link or LAN. Ethernet headers carry MACs and an EtherType (0x0800 for IPv4). Switches learn source MACs and forward/flood. CRC detects corruption on the wire.

Why does it matter?

ARP, VLANs, switching loops, and 'link light up but no ping' are L2 problems. You cannot debug a LAN without this layer.

Mental model

The truck between two adjacent post offices. The city name (IP) stays in the letter; the truck only cares about the next dock (MAC).

How it works

  • Purpose: hop-to-hop transfer, framing, media access, error detection.
  • PDU: frame. Addressing: MAC (48-bit typical).
  • Protocols: Ethernet, Wi-Fi (802.11), PPP, ARP (a glue protocol).
  • Devices: switches, bridges, APs, NICs. Hubs are L1.
  • Switches split collision domains; VLANs split broadcast domains.

Real-world usage

  • LANs
  • Switching
  • Wi-Fi association

Common mistakes

  • Thinking a MAC is globally how the internet routes (it is not)
  • Unmanaged loops without STP

Interview questions

Switch vs router?

Switch: L2, MAC, one broadcast domain (unless VLANs). Router: L3, IP, between subnets.

What is ARP?

Resolve IPv4 → MAC on a LAN so the frame can be addressed.

Field (Ethernet)SizeMeaning
Dest MAC6 BNext hop on this LAN
Src MAC6 BSender on this LAN
EtherType2 B0x0800 IPv4, 0x86DD IPv6, 0x0806 ARP
Payload46–1500 BUsually an IP packet
FCS4 BCRC

Prerequisites

Related concepts

Continue learning

Browse the full computer science library