Skip to main content
networking

Network Layers — OSI 1-7 and TCP/IP

13 min read
Fully authored

The 7-layer model that lets you reason about any network problem. Where each protocol sits and what real systems live at each layer.

In 1978 the International Organization for Standardization (ISO) started work on a universal model for computer networks — a way to divide the messy problem of "get bits from computer A to computer B" into layered pieces that could be designed, replaced, and reasoned about independently. In 1984 they published ISO/IEC 7498 — the OSI 7-layer reference model.

By the time the OSI model was standardized, the internet was already running on a competing model: TCP/IP (RFC 1122, 1989). TCP/IP has 4 layers instead of 7 and it's what actually runs the real internet. But the OSI 7-layer model won as the teaching and troubleshooting vocabulary. When a networking engineer says "it's a Layer 2 problem" or "we terminate TLS at Layer 7," they mean OSI layers. Every network engineer, sysadmin, and distributed-systems architect speaks this language.

The layers matter because they let you localize failure and compose functionality. Cable cut? Layer 1. WiFi authentication failing? Layer 2. Can't reach the gateway IP? Layer 3. Connection refused? Layer 4. TLS cert expired? Layer 6/7 boundary. HTTP 502? Layer 7. The vocabulary also tells you where each product plays: AWS NLB is L4 (packet-level). AWS ALB / Nginx / HAProxy L7 mode operate at L7 (HTTP-aware). Cloudflare spans L3-L7. Understanding what layer something lives at tells you what it can and can't do.

The standards

  • ISO/IEC 7498 (1984) — "Information Processing Systems — Open Systems Interconnection — Basic Reference Model." The OSI 7-layer standard.
  • RFC 1122 (1989) — "Requirements for Internet Hosts." The definitive TCP/IP 4-layer model.
  • Andrew Tanenbaum Computer Networks (1st ed. 1981, now in 6th edition). The textbook that taught the OSI model to a generation of engineers.

Interactive: click any layer to explore

Click any of the 7 layers below to see its purpose, the protocols that live at that layer, and the real-world systems you can point at as concrete examples.

Interactive OSI layer explorer
Layer 7
Application
The protocols your apps speak: request-response, publish-subscribe, streaming. What the end user actually sees.
Protocols
  • HTTP/1.1, HTTP/2, HTTP/3
  • HTTPS (HTTP + TLS)
  • gRPC (over HTTP/2)
  • GraphQL
  • FTP, SFTP
  • SMTP, IMAP, POP3
  • SSH
  • DNS (queries)
  • MQTT, AMQP
  • WebSocket
  • RTP/RTSP
Devices
  • Web browsers
  • API gateways
  • L7 load balancers (Nginx, HAProxy L7, AWS ALB, Envoy)
  • Web application firewalls (Cloudflare WAF, AWS WAF)
  • Reverse proxies
Real-world examples
  • Chrome loading google.com — HTTP/3
  • Slack desktop client — WebSocket for real-time messages
  • Gmail SMTP for send + IMAP for receive
  • GitHub Actions calling GitHub REST API — HTTPS
  • Zoom RTP for video/audio (over UDP)
  • AWS CloudFront serving static assets — HTTP/2
  • Redis clients (like redis-cli) — Redis protocol (RESP) over TCP

Animated: watch an HTTP request travel down and up the stack

Theory is cheap. Watching a packet actually descend through Layer 7 → Layer 1, gain a header at each layer (encapsulation), cross the wire, then ascend back up on the server side (decapsulation) — that's where it clicks. Play the animation. Pause at any layer to see what gets added.

HTTP request encapsulation journey
Client side: descending L7 → L1 (encapsulation)
Client (Alice's browser)
L7Applicationadding header ↓
GET /orders HTTP/1.1\r\nHost: acme.com\r\nAuthorization: Bearer eyJ...
L6Presentation
L5Session
L4Transport
L3Network
L2Data Link
L1Physical
Wire
encapsulating
Server (acme.com origin)
L1Physical
L2Data Link
L3Network
L4Transport
L5Session
L6Presentation
L7Application
Step 1: Encapsulating at L7 (Application)
HTTP request line + headers + body
Encapsulation (client): Each layer wraps the previous layer's data in its own header. Original HTTP request grows from ~500 bytes to ~600 bytes as headers stack.
Decapsulation (server): Each layer strips its own header and passes the inner payload up. Original HTTP request is reconstructed exactly as sent.

The layers in one sentence each

Layer 7Application(Away)
What the user's app speaks — HTTP, gRPC, SMTP, WebSocket.
Layer 6Presentation(Pizza)
Encoding, encryption, compression — TLS, gzip, JPEG.
Layer 5Session(Sausage)
Session setup / teardown — SSH, VPN handshake, SIP.
Layer 4Transport(Throw)
TCP / UDP / QUIC — reliable streams vs fire-and-forget.
Layer 3Network(Not)
IP addresses + routing — get packets to any host, anywhere.
Layer 2Data Link(Do)
MAC addresses + frames — one hop across the same LAN.
Layer 1Physical(Please)
Bits on the wire — cables, fiber, radio, connectors.
Mnemonic to remember: "Please Do Not Throw Sausage Pizza Away" — top-down: A-P-S-T-N-D-P.

OSI vs TCP/IP — the model reality gap

The OSI model has 7 layers. TCP/IP has 4. What's the difference, and why do we still teach OSI if the internet runs on TCP/IP?

Model comparison
OSI Model (1984)
7. Application
6. Presentation
5. Session
4. Transport
3. Network
2. Data Link
1. Physical
TCP/IP Model (1989)
4. Application (= OSI 5-7)
3. Transport (= OSI 4)
2. Internet (= OSI 3)
1. Link (= OSI 1-2)
"Application" layer here just means "whatever the app protocol does"
The reality: The internet runs on TCP/IP's 4 layers. OSI's 7 layers exist to make the pieces easier to talk about. Both are correct — the OSI numbering is the shared vocabulary of every networking engineer.

The answer: OSI's 5, 6, and 7 all became "application layer" in TCP/IP because in practice, application developers own all three. HTTPS is an application-layer protocol even though it uses TLS (technically layer 6) for encryption. The 7-layer OSI vocabulary is more precise for reasoning, but the 4-layer TCP/IP model is what you actually build against.

Encapsulation — how data becomes bits

When you send an HTTP request, it goes through every layer on the way down (each layer wraps the previous with its own header), then the bits arrive at the destination and get unwrapped in reverse.

Data encapsulation — step 1 of 6
Watch a 40-byte HTTP request become 119 bytes on the wire.
Layer
7
GET / HTTP/1.1\nHost: example.com
Total
40B
Layer
6
+ TLS record
🔒 [encrypted]
Total
65B
Layer
4
+ TCP header (20 B: src port, dst port, seq, ack, flags)
🔒 [encrypted]
Total
85B
Layer
3
+ IP header (20 B: src IP, dst IP, TTL, protocol)
🔒 [encrypted]
Total
105B
Layer
2
+ Ethernet frame header (14 B: src MAC, dst MAC, EtherType)
🔒 [encrypted]
Total
119B
Layer
1
+ Serialized bits over physical medium
10110100 01001011 11010010…
Total
119B
Layer 7: Your app produces an HTTP request. ~40 bytes.

This is why a single HTTP request can end up as ~20 bytes of TCP header + 20 bytes of IP header + 14 bytes of Ethernet frame header around your actual payload. For a 1-byte HTTP body, you're sending ~55 bytes of overhead. This is also why Ethernet MTU (~1500 bytes) matters — larger packets get fragmented at Layer 3.

Where common systems live — a real-world map

L7
Application
Nginx (L7)AWS ALBHAProxy L7EnvoyCloudflare WAFAWS API GatewayKongIstio ingress
L6
Presentation
Let's Encrypt (TLS certs)AWS ACM (cert manager)AWS ALB TLS terminationCloudflare Universal SSLOpenSSL library
L4
Transport
AWS NLBHAProxy TCP modeHAProxy UDP modeF5 Big-IPGoogle Maglev (L4)AWS Global Accelerator (L4)
L3
Network
AWS VPCAWS Transit GatewayGCP Cloud RouterCloudflare Anycast IPsGoogle DNS 8.8.8.8Cisco routersJuniper routers
L2
Data Link
Cisco Catalyst switchesArista data-center switchesUbiquiti UniFi APs (WiFi 6)AWS Direct ConnectAWS ENI (Elastic Network Interface)
L1
Physical
Google submarine cables (Curie, Dunant, Grace Hopper)Corning fiberCat6 Ethernet cables5G mm-waveAWS Outposts fiber to your DC

The interview litmus test

Every serious system design interview probes your layer vocabulary. Common questions:

  • "L4 vs L7 load balancer — when to pick which?" L4 = fast, TCP-level, can't inspect content (AWS NLB, HAProxy L4 mode). L7 = HTTP-aware, can route by URL / header / cookie, slower, more expensive (AWS ALB, Nginx, HAProxy L7, Envoy).
  • "Where does TLS terminate in your architecture?" Usually at the L7 load balancer or CDN edge. Origin then sees plain HTTP.
  • "How does Anycast work?" L3 — the same IP is announced from many places via BGP. Routers pick the "nearest" one. Used by Cloudflare, Google DNS (8.8.8.8), root DNS servers.
  • "What's the difference between WebSocket and HTTP long-polling?" Both L7. WebSocket upgrades an HTTP connection to a full-duplex persistent channel; long-polling reuses HTTP request-response pattern.
  • "Why is UDP the wrong choice for reliability but the right choice for video?" Layer 4 — UDP has no retransmit, no ordering. For video, retransmitting old frames is worse than dropping them.

Applied in real systems — one company per layer

Layer 1
Deep dive

Google's submarine cables — physical layer at planet scale

Google co-owns Curie (Chile-LA), Dunant (US-France), Equiano (Portugal-South Africa), and Grace Hopper (US-UK). These are 100+ Tbps fiber-optic pipes across ocean floors. Every packet you send to a Google service crosses one of them. The physical layer, in the most literal sense.

Read the deep dive →
Layer 2
Deep dive

WiFi 802.11 — the data-link protocol you use daily

802.11ax (WiFi 6) frames carry your data between your laptop and your access point. MAC addresses identify devices. CSMA/CA handles collisions. This is Layer 2. Your home router does the L2-to-L3 translation to the WAN.

Read the deep dive →
Layer 3
Deep dive

Cloudflare 1.1.1.1 — Anycast at Layer 3

Cloudflare announces the IP 1.1.1.1 from 300+ data centers worldwide via BGP. Your router picks the "nearest" one automatically. Layer 3 makes this possible — routing is per-packet, not per-connection.

Read the deep dive →
Layer 4
Deep dive

AWS Network Load Balancer — pure L4

AWS NLB routes TCP and UDP at layer 4. Ultra-low latency (~100µs), millions of connections per second, no HTTP awareness. Perfect for gRPC, Postgres, Redis, or any non-HTTP protocol. Cheaper than the L7 ALB.

Read the deep dive →
Layer 6
Deep dive

TLS 1.3 — presentation-layer encryption

TLS 1.3 (RFC 8446, 2018) sits between the transport (L4) and application (L7) layers. It encrypts and authenticates — that's traditionally a Layer 6 concern ("presentation"). Most L7 load balancers terminate TLS here.

Read the deep dive →
Layer 7
Deep dive

AWS Application Load Balancer — HTTP-aware routing

ALB inspects HTTP requests: can route by URL path (/api/* → API service, /static/* → S3), header, cookie, or query string. Also terminates TLS. Slower than NLB but way more flexible.

Read the deep dive →
Layer 7
Deep dive

Nginx — the HTTP reverse proxy standard

Nginx is L7 by design: parses HTTP, routes by location blocks, caches responses, terminates TLS. Runs on 30%+ of internet-facing web servers. Every big website is either Nginx or an Nginx-alike.

Read the deep dive →
Layer 4 → 7
Deep dive

QUIC / HTTP/3 — collapsing the layers

HTTP/3 (RFC 9114, 2022) breaks the clean layer boundary. It runs over QUIC (a new L4 protocol on UDP) that includes encryption (traditionally L6) and streams (traditionally L7). Modern protocols are increasingly cross-layer.

Read the deep dive →

Key takeaways

  • 7 OSI layers: 1 Physical · 2 Data Link · 3 Network · 4 Transport · 5 Session · 6 Presentation · 7 Application. Mnemonic: "Please Do Not Throw Sausage Pizza Away".
  • TCP/IP collapses OSI layers 5-6-7 into a single "Application" layer. That's what actually runs the internet.
  • Data encapsulation: your HTTP request gets wrapped in TLS (L6), then TCP (L4), then IP (L3), then Ethernet (L2), then sent as bits (L1). Each layer adds ~14-40 bytes of header.
  • L4 vs L7 load balancers: L4 = fast + protocol agnostic + can't inspect (NLB, HAProxy TCP mode). L7 = HTTP-aware + route by URL/header/cookie + terminates TLS (ALB, Nginx, Envoy).
  • Anycast is L3: same IP announced from many places via BGP. Cloudflare, Google DNS, root DNS.
  • Every product plays at a specific layer. Know which. AWS Direct Connect = L1/L2. VPN = L3. Load balancer "L4 vs L7" you have to pick. Firewall "L3 filtering vs L7 WAF" you have to pick.
  • Modern protocols like QUIC/HTTP/3 increasingly blur the layer boundaries — encryption + transport + streams in one protocol.

References

  • ISO/IEC 7498-1 (1984, revised 1994) — the OSI reference model standard.
  • RFC 1122 (1989) — Requirements for Internet Hosts (TCP/IP model).
  • Tanenbaum & Wetherall Computer Networks, 6th ed. The definitive textbook.
  • Kurose & Ross Computer Networking: A Top-Down Approach. The other textbook, and more approachable.
  • Cloudflare Learning Center — free layer-by-layer articles at cloudflare.com/learning/.

Practice what you just read

Every foundation concept has a companion quiz to close the loop.