OSI Reference Model

Layer 2 & Layer 3
Networking Explained

Understanding how data moves across a local network — and across the entire internet.

The OSI Model

The OSI model has 7 layers. Each layer handles a specific job. Layer 2 and Layer 3 are the foundation of all modern networking.

7 Application HTTP, DNS, SMTP
6 Presentation TLS, encoding
5 Session RPC, sockets
4 Transport TCP, UDP
3 🌐 Network IP, routing, packets
2 🔵 Data Link Ethernet, MAC, frames
1 Physical Cables, signals, bits

What Each Layer Does

Layer 2 — Data Link

Local Delivery

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.

Ethernet Wi-Fi (802.11) MAC Addresses Frames VLANs ARP
Layer 3 — Network

Global Routing

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.

IPv4 / IPv6 Routing Protocols IP Addresses Packets Subnets ICMP

MAC vs. IP Addresses

Each layer uses a different type of address. MAC addresses are fixed to hardware; IP addresses are logical and can change.

Layer 2 — MAC Address
A4:C3:F0:85:AC:2D
A4:C3:F0
85:AC:2D

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.

Layer 3 — IP Address (v4)
192.168.1.42
192.168
1
42

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.

Frame vs. Packet

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)

Dest MAC
6 bytes
Src MAC
6 bytes
EtherType
2 bytes
IP Packet (payload)
46–1500 bytes
FCS checksum
4 bytes

IP Packet (Layer 3 — inside the frame)

Version / TTL
header flags
Src IP
4 bytes
Dest IP
4 bytes
TCP/UDP Payload (data)
variable

Which Devices Operate at Which Layer

🔀

Network Switch

Layer 2

Forwards frames based on MAC address tables. Connects devices within the same network (LAN). Has no concept of IP addresses.

📡

Wi-Fi Access Point

Layer 2

Bridges wireless and wired segments at the MAC level. Devices on the same AP share a Layer 2 broadcast domain.

🌐

Router

Layer 3

Forwards packets between different networks using IP addresses and a routing table. Your home router connects your LAN to the internet.

🔥

Firewall (L3)

Layer 3

Filters IP packets by source/destination IP and port. Can block or allow traffic between networks or the internet.

L3 Switch

Layer 2 + Layer 3

A switch with built-in routing capability. Can forward frames (L2) within VLANs and route packets (L3) between VLANs — all at wire speed.

🔌

Network Bridge

Layer 2

Connects two separate network segments at Layer 2, forwarding frames only when the destination is on the other side.

How a Packet Travels: Your Browser to Google

Each hop rewrites the Layer 2 frame headers while the Layer 3 IP addresses remain constant end-to-end.

💻
Your PC
Creates L2 Frame
ARP finds router MAC. Frame: src=your MAC, dst=router MAC
🔀
Home Switch
L2 Forwarding
Forwards frame by MAC table — no IP inspection
🌐
Home Router
L3 Routing
Strips L2, reads IP packet, rewrites new frame for next hop
🏢
ISP Router
L3 Routing
BGP routing — picks best path across the internet
☁️
Google DC
L3 → L2 delivery
Final router delivers frame to Google's server MAC

Quick Reference

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

Important Terms

📢

Broadcast Domain

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.

🗺️

ARP (Address Resolution Protocol)

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."

🧱

VLANs

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.

TTL (Time to Live)

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.

🔢

Subnetting

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.

🔄

Encapsulation

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.

The One-Sentence Summary

Layer 2 (Data Link) gets data between two devices on the same network using MAC addresses and frames — while Layer 3 (Network) gets data between different networks anywhere on the planet using IP addresses and packets. They always work together: L3 decides where to go, L2 handles each individual hop to get there.