OSI & TCP/IP Models
The 7-layer OSI model and the 4-layer TCP/IP model, what each layer does, encapsulation, and which protocols and devices live where.
Networking is split into layers so each problem can be solved independently: how to send bits over a wire, how to deliver a frame to the next device, how to route across the world, how to make delivery reliable, and what the application actually says. Each layer offers a service to the layer above and uses the layer below.
The two models
The OSI model (7 layers) is the standard vocabulary — engineers say "a layer 7 load balancer" or "a layer 2 switch". The TCP/IP model (4 layers) is what the Internet actually implements. OSI's session and presentation layers don't exist as separate protocols in practice; their jobs are done by applications and TLS.
What each layer does
| Layer | Unit of data | Addressing | Job | Devices |
|---|---|---|---|---|
| Application (7) | Message | URLs, hostnames | What the program means: request a page, send an email | — |
| Transport (4) | Segment (TCP) / datagram (UDP) | Ports | Deliver between processes; reliability, ordering, flow and congestion control (TCP) | Firewalls, L4 load balancers |
| Network (3) | Packet | IP addresses | Deliver between hosts across networks; routing | Routers |
| Data link (2) | Frame | MAC addresses | Deliver to the next device on the same link; error detection | Switches, access points |
| Physical (1) | Bits | — | Signals on the medium | Cables, hubs, repeaters, radios |
Encapsulation
Going down the stack, each layer wraps the data from above with its own header (and the link layer adds a trailer too). Going up at the receiver, each layer strips its header and passes the payload up.
Typical overhead: Ethernet 14 bytes + 4-byte trailer, IPv4 20 bytes, TCP 20 bytes (more with options). With a 1500-byte MTU (maximum transmission unit), that leaves about 1460 bytes of application data per packet — the MSS (maximum segment size).
Where common things live
| Thing | Layer |
|---|---|
| HTTP, DNS, SMTP, SSH, gRPC, WebSocket | 7 |
| TLS | Between 4 and 7 (often called 6, or "layer 4.5") |
| TCP, UDP, QUIC (over UDP) | 4 |
IP, ICMP (ping), IPsec | 3 |
| ARP (IP → MAC lookup) | Between 2 and 3 |
| Ethernet, Wi-Fi (802.11), VLANs | 2 |
| Fibre, copper, radio | 1 |
| L4 load balancer (by IP and port) | 4 |
| L7 load balancer / API gateway (by URL path, headers) | 7 |
Why layering matters in practice
- Independence — HTTP works the same over Wi-Fi, Ethernet or 5G; TCP doesn't care whether the link is fibre or radio.
- Debugging — work bottom-up: is the link up (1/2)? Is there an IP and a route (3)? Is the port open (4)? Is the application responding correctly (7)?
- Vocabulary — "it's a layer 7 problem" means the network is fine and the application isn't.
- OSI has 7 layers (vocabulary); TCP/IP has 4 (implementation).
- Transport delivers between processes (ports); network between hosts (IP); link between neighbours (MAC).
- Data units: frame (L2), packet (L3), segment/datagram (L4).
- Encapsulation wraps each layer's header around the payload from above.
- Debug bottom-up through the layers.
QAt which layers do a switch, a router and a load balancer operate?easy
A switch at layer 2 (MAC addresses), a router at layer 3 (IP addresses). A load balancer at layer 4 (IP and port, forwarding TCP/UDP connections) or layer 7 (understanding HTTP and routing by path, host or headers).