Knowledge Guide
HomeSystem DesignNetworking Fundamentals

The Layered Network Model — OSI, TCP/IP, and L4 vs L7

Why a layered model?

Networking is hard because a single request crosses many concerns at once: physical signalling, addressing, reliable delivery, encryption, and application semantics. The industry tames this with layering — each layer solves one problem and hands a clean abstraction to the layer above. You will not memorise the OSI model to build systems, but the vocabulary it gives you ("that's an L4 load balancer", "TLS sits at the session/presentation boundary", "this is an L7 routing rule") is how engineers talk about where a behaviour lives.

The OSI seven layers

OSI is the conceptual reference. Read it bottom-up — bits become frames, frames become packets, packets become reliable streams, streams carry application messages:

  1. Physical — raw bits over a medium (copper, fibre, radio).
  2. Data link — framing and MAC addressing on a local segment (Ethernet, Wi-Fi).
  3. Network — logical addressing and routing across networks (IP).
  4. Transport — end-to-end delivery, ports, reliability (TCP, UDP).
  5. Session — establishing, managing, and tearing down connections.
  6. Presentation — encoding, serialization, encryption (where TLS conceptually lives).
  7. Application — the protocol your software speaks (HTTP, gRPC, SMTP, DNS).
The seven layers of the OSI model
The seven layers of the OSI model

TCP/IP — the model the internet actually runs on

The OSI model is a teaching tool; the internet is built on the leaner TCP/IP stack, which collapses OSI's top three layers into a single Application layer: Link → Internet (IP) → Transport (TCP/UDP) → Application. When people say "the network stack", this is usually what they mean.

TCP vs UDP — the transport choice that matters most

At the transport layer you pick reliability or speed. TCP is connection-oriented: a three-way handshake, ordered delivery, retransmission, and flow/congestion control. It is the right default for anything where correctness beats latency — web pages, APIs, file transfer.

TCP connection-oriented delivery with handshake and acknowledgements
TCP connection-oriented delivery with handshake and acknowledgements

UDP is connectionless: fire-and-forget datagrams with no handshake, no ordering, and no retransmission. You trade guarantees for the lowest possible latency, which is why it underpins DNS lookups, real-time voice/video, and gaming — and why QUIC (the basis of HTTP/3) is built on UDP while re-implementing reliability in user space.

UDP connectionless datagram delivery
UDP connectionless datagram delivery

L4 vs L7 — the distinction you will use constantly

"Layer 4" and "Layer 7" are shorthand for how much of the request a piece of infrastructure understands:

L4 (Transport)L7 (Application)
SeesIP addresses + TCP/UDP portsThe full request: URL, headers, cookies, body
DecisionsForward this connection to a backendRoute /api/* here, /img/* there; rewrite headers; terminate TLS
CostCheap, extremely fastMore CPU, but content-aware
ExampleAn L4 TCP load balancerAn L7 reverse proxy / API gateway

This is exactly why your load balancer can operate at L4 or L7, and why an API gateway is an L7 device — it has to read paths and headers to route. TLS termination happening "at the edge" means the L7 proxy decrypts so it can see the application data underneath.

Takeaways


Re-authored for this guide, with concepts and diagrams adapted from Karan Pratap Singh’s System Design (course, MIT licence) and the System Design Primer (CC BY 4.0). Diagrams © their respective authors.

🤖 Don't fully get this? Learn it with Claude

Stuck on The Layered Network Model — OSI, TCP/IP, and L4 vs L7? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **The Layered Network Model — OSI, TCP/IP, and L4 vs L7** (System Design) and want to truly understand it. Explain The Layered Network Model — OSI, TCP/IP, and L4 vs L7 from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **The Layered Network Model — OSI, TCP/IP, and L4 vs L7** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **The Layered Network Model — OSI, TCP/IP, and L4 vs L7** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **The Layered Network Model — OSI, TCP/IP, and L4 vs L7** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes