Networking Tutorial · Networking Basics · Lesson 3 of 28
OSI and TCP/IP Models
The layer models engineers use to describe networks, and what lives at each layer.
Why layers?
Networking is split into layers, each solving one problem and relying on the layer below. HTTP doesn't care whether packets travel over Wi-Fi or fibre; TCP doesn't care what's inside the bytes it delivers.
The TCP/IP model (what the internet actually uses)
| Layer | Job | Examples |
|---|---|---|
| Application | What the program wants to say | HTTP, DNS, TLS, SSH, SMTP |
| Transport | Deliver data between programs (ports) | TCP, UDP, QUIC |
| Internet | Deliver packets between hosts (addresses, routing) | IPv4, IPv6, ICMP |
| Link | Deliver frames on one local network | Ethernet, Wi-Fi |
The OSI model (the vocabulary)
The seven-layer OSI model is mostly used for naming things:
| OSI layer | Name | You'll hear |
|---|---|---|
| 7 | Application | "a layer 7 load balancer" (routes by URL or header) |
| 6 | Presentation | encoding, compression (rarely mentioned) |
| 5 | Session | (rarely mentioned) |
| 4 | Transport | "a layer 4 load balancer" (routes by IP and port) |
| 3 | Network | IP addresses, routers, "L3 connectivity" |
| 2 | Data link | MAC addresses, switches, VLANs |
| 1 | Physical | cables, radio, optics |
Encapsulation
Each layer wraps the data from the layer above in its own header: an HTTP request goes inside a TCP segment, inside an IP packet, inside an Ethernet frame. The receiver unwraps them in reverse.
http = b"GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"
layers = [("TCP header", 20), ("IPv4 header", 20), ("Ethernet header + trailer", 18)]
size = len(http)
print(f"{'HTTP request':28} {size:4} bytes")
for name, overhead in layers:
size += overhead
print(f"+ {name:26} {size:4} bytes on the wire")
print(f"headers are {1 - len(http) / size:.0%} of this small packet")
Output
HTTP request 37 bytes + TCP header 57 bytes on the wire + IPv4 header 77 bytes on the wire + Ethernet header + trailer 95 bytes on the wire headers are 61% of this small packet
Test yourself
A load balancer that routes requests by URL path works at which OSI layer?
Layer 2Layer 3Layer 4Layer 7
Show answer
Answer: Layer 7
URL paths and headers are application data (HTTP), so routing by them is layer 7. Layer 4 balancers only see IPs and ports.