Understanding how data moves across a local network — and across the entire internet.
The OSI model has 7 layers. Each layer handles a specific job. Layer 2 and Layer 3 are the foundation of all modern networking.
Responsible for transferring data between two devices on the same network. It packages raw bits into frames and uses MAC addresses to identify devices.
Think of Layer 2 like the internal mail system of a building. It only knows about rooms inside that building — it has no idea how to reach the outside world.
Responsible for routing data between different networks. It uses IP addresses to find the best path from source to destination across the internet.
Think of Layer 3 like the postal service. It handles delivery across cities and countries, choosing the best route regardless of local geography.
Each layer uses a different type of address. MAC addresses are fixed to hardware; IP addresses are logical and can change.
48-bit address, burned into the network interface card (NIC) at manufacture. The first 3 bytes identify the vendor (OUI); the last 3 are unique to the device. Only used within a single network segment — not routable.
32-bit logical address assigned by DHCP or manually. The network portion identifies the subnet; the host portion identifies the device. Can be changed — is routable across the internet. IPv6 extends this to 128 bits.
Layer 2 wraps data in a frame. Layer 3 wraps data in a packet. A packet is carried inside a frame as it travels over a local link.
Ethernet Frame (Layer 2)
IP Packet (Layer 3 — inside the frame)
Forwards frames based on MAC address tables. Connects devices within the same network (LAN). Has no concept of IP addresses.
Bridges wireless and wired segments at the MAC level. Devices on the same AP share a Layer 2 broadcast domain.
Forwards packets between different networks using IP addresses and a routing table. Your home router connects your LAN to the internet.
Filters IP packets by source/destination IP and port. Can block or allow traffic between networks or the internet.
A switch with built-in routing capability. Can forward frames (L2) within VLANs and route packets (L3) between VLANs — all at wire speed.
Connects two separate network segments at Layer 2, forwarding frames only when the destination is on the other side.
Each hop rewrites the Layer 2 frame headers while the Layer 3 IP addresses remain constant end-to-end.
| Feature | Layer 2 — Data Link | Layer 3 — Network |
|---|---|---|
| Address type | MAC address (48-bit) | IP address (32/128-bit) |
| Data unit | Frame | Packet |
| Scope | Single network segment (LAN) | Between networks (WAN / Internet) |
| Main device | Switch | Router |
| Address assignment | Burned in at manufacture | Configured / DHCP |
| Key protocol | Ethernet, ARP, 802.11 | IPv4, IPv6, OSPF, BGP |
| Broadcast domain | All devices on same VLAN | Routers separate broadcast domains |
| Analogy | Room number in a building | Full postal address |
All devices that receive a broadcast message. Layer 2 switches forward broadcasts to everyone. Routers (L3) block broadcasts — every subnet is its own broadcast domain.
The bridge between L2 and L3. When your device knows the IP it wants to reach but not the MAC, it broadcasts an ARP request: "Who has 192.168.1.1? Tell me your MAC."
Virtual LANs logically segment a physical switch into multiple isolated broadcast domains — all at Layer 2. Traffic between VLANs requires a router or L3 switch.
A Layer 3 field in the IP packet header. Each router decrements it by 1. When it hits 0, the packet is dropped — preventing infinite routing loops.
Dividing an IP network into smaller sub-networks using a subnet mask (e.g. /24). Devices in the same subnet can communicate at Layer 2 without a router.
Each layer wraps the layer above in its own header. An HTTP request becomes a TCP segment → IP packet → Ethernet frame → electrical signal. Decapsulated in reverse on arrival.