The Layer Model: TCP/IP First, OSI as a Map
Networking is stacked because each layer solves one problem for the layer above without knowing what it carries; the four-layer TCP/IP model describes what actually runs, the seven-layer OSI model is a vocabulary — and modern protocols such as TLS, QUIC and ARP refuse to sit in one box.
The problem
Four layers that actually exist
The internet runs on a stack that is best described with four layers, each of which is a real, separately implemented piece of software or hardware with a defined interface to its neighbours. Going down from your code: Application protocols (HTTP, DNS, TLS-as-used-by-HTTP, SMTP, SSH) define *what the bytes mean*. Transport protocols (TCP, UDP, and QUIC) deliver bytes between *processes*, identified by ports, and decide whether delivery is reliable and ordered. The Internet layer (IP, plus ICMP as its control channel) delivers packets between *machines* across many networks, best-effort. The Link layer (Ethernet, Wi-Fi, cellular, PPP) delivers frames between *directly connected* interfaces on one physical medium.
The contract between layers is the important part. Each layer takes an opaque payload from above, adds its own header, and hands the result down; each layer on the receiving side strips its header and passes the payload up. IP does not know whether it carries TCP or UDP beyond a protocol number; Ethernet does not know whether it carries IPv4 or IPv6 beyond an EtherType; TCP does not know whether its bytes are HTTP or SSH. This ignorance is deliberate: it is what let HTTP/3 replace TCP with QUIC without touching a single router, and what lets IPv6 replace IPv4 without touching HTTP.
The model is sometimes drawn with a fifth Physical layer below Link (signal levels, connectors, modulation). Engineers who write software rarely need it, but it is where "the cable is unplugged" and "the Wi-Fi signal is weak" live.
- ApplicationHTTP, DNS, TLS, SSH — the meaning of the bytes↓
- TransportTCP, UDP, QUIC — process to process, via ports↓
- InternetIP (+ ICMP) — machine to machine, across networks, best-effort↓
- LinkEthernet, Wi-Fi — interface to interface on one medium
What each layer promises, and what it refuses to promise
Each layer is defined as much by what it does *not* do. The link layer delivers a frame to a MAC address on the same segment; it makes no attempt to reach another network and (on Ethernet) no attempt to retransmit. IP reaches any network in the world but promises nothing about delivery: a packet may be lost, duplicated, reordered, or arrive with its neighbours missing, and IP will not tell anyone. TCP takes that and produces a reliable ordered byte stream — but knows nothing about messages, so an application that sends two write()s may read() them as one, or as three. UDP deliberately passes IP’s unreliability straight through, keeping only ports and a checksum, because DNS, real-time media and QUIC want to handle loss their own way.
This division is why the same symptom can come from different layers. "The connection dropped" might be the link (Wi-Fi roamed to another access point and got a new IP), IP (a route withdrawn), transport (a RST from a NAT that lost its mapping) or application (an idle timeout on the proxy). Debugging is the act of finding which layer’s promise was broken; see The Tools, and Which Layer Each One Answers for which tool answers which layer.
| Layer | Delivers between | Addressed by | Guarantees | Explicitly does not |
|---|---|---|---|---|
| Application | programs that agree on a format | URLs, names, methods | meaning | delivery — it trusts transport |
| Transport (TCP) | processes | port | reliable, ordered bytes | message boundaries, latency bounds |
| Transport (UDP) | processes | port | a datagram arrives whole or not at all | delivery, order, non-duplication |
| Internet (IP) | hosts across networks | IP address | best-effort forwarding | delivery, order, non-duplication |
| Link | interfaces on one segment | MAC address | a frame reaches a neighbour | crossing a router, retransmission (Ethernet) |
OSI: seven names for the same idea
The OSI model (1984) divides the same work into seven layers: Physical (1), Data Link (2), Network (3), Transport (4), Session (5), Presentation (6), Application (7). No protocol suite in use today was built to it — TCP/IP predates it and won — but its numbers became the industry’s vocabulary. "L2 switch", "L3 routing", "L4 load balancer", "L7 proxy" all refer to OSI numbering, and you need to read them fluently even though the model behind them is a reference, not a specification.
The mapping to TCP/IP is straightforward at the bottom and fuzzy at the top. OSI 1–2 are TCP/IP’s Link layer; OSI 3 is Internet; OSI 4 is Transport. OSI 5–7 are collapsed into TCP/IP’s Application layer, because in practice Session and Presentation never existed as separate protocols — what OSI called "presentation" (encoding, encryption) is done by TLS and by the application’s own serialisation, and what it called "session" is done by TCP connections, cookies and application state. Do not spend energy assigning HTTP headers to layer 6.
| OSI | TCP/IP | Examples | Note |
|---|---|---|---|
| 7 Application | Application | HTTP, DNS, SMTP, SSH | what the bytes mean |
| 6 Presentation | Application | TLS (arguably), JSON, gzip | no standalone protocol; split between TLS and app code |
| 5 Session | Application | nothing distinct | sessions live in TCP, cookies, app state |
| 4 Transport | Transport | TCP, UDP, QUIC | "L4" = ports, segments |
| 3 Network | Internet | IP, ICMP | "L3" = IP addresses, routing |
| 2 Data Link | Link | Ethernet, Wi-Fi (802.11), ARP (arguably) | "L2" = MAC addresses, switches |
| 1 Physical | Link | cables, radio, modulation | signals, not bits with meaning |
Protocols that straddle the boxes
The model is a map, and the territory has protocols that live on borders. TLS runs above TCP and below HTTP: it is addressed like an application protocol, carries a record layer with its own framing, and provides what OSI would call presentation and session services; the honest answer is "between transport and application". QUIC is a transport (it does reliability, ordering, congestion control and multiplexing) that runs *inside* UDP datagrams and has TLS 1.3 *built into its handshake* — so it is a layer-4 protocol carried by another layer-4 protocol, with layer-6 baked in. ARP carries IP addresses (a layer-3 concept) in frames that have no IP header (layer 2), to solve a problem that exists precisely at the seam between the two. ICMP is carried inside IP like a transport, but is part of IP’s own machinery.
The practical rule: "L4" and "L7" are jargon for *what information a device looks at* — ports and connections versus URLs, headers and content — not a law about where a protocol must sit. An "L4 load balancer" forwards on the 4-tuple without decrypting; an "L7 load balancer" terminates TLS and routes on the Host header. That distinction is real and useful; the layer numbers are just its shorthand. See Load Balancers: L4 vs L7.
- TLS: above TCP, below HTTP; QUIC absorbs it entirely.
- QUIC: a transport carried by UDP, with TLS 1.3 inside its handshake.
- ARP: link-layer frames carrying network-layer addresses; IPv6 replaced it with Neighbor Discovery, which runs over ICMPv6 — i.e. inside IP.
- "L4 vs L7" describes what a box inspects, not where a protocol is legally required to live.
Key points
- TCP/IP’s four layers — Application, Transport, Internet, Link — are what actually runs; each adds a header on the way down and strips it on the way up.
- Each layer is defined by what it refuses to do: IP does not guarantee delivery, TCP does not preserve message boundaries, Ethernet does not cross routers.
- The layer-ignorance contract is what let QUIC replace TCP and IPv6 replace IPv4 without touching the other layers.
- OSI is a seven-layer vocabulary, not an implementation. Its lower four map cleanly; 5–7 collapse into "application".
- TLS, QUIC, ARP and ICMP straddle layers. "L4/L7" is shorthand for what a device inspects.
- Debugging is finding which layer’s promise was broken; each layer has its own tool.
Why does this exist?
Mechanisms are answers to constraints. Open each question before reading the answer.
▸Why layers at all?
So that each problem — sharing a cable, crossing networks, reliability, meaning — can be solved, tested and replaced independently. The alternative is one protocol that must change every time any hardware, network or application changes.
▸Why does IP not guarantee delivery when TCP has to build it anyway?
Because not everyone wants it: DNS, video, gaming and QUIC prefer loss to delay. Putting reliability in the ends (the end-to-end argument) keeps routers stateless and fast and lets each application choose.
▸Why do people still say "layer 7" if OSI never shipped?
Vocabulary outlives models. The numbers are a compact way to say "this box looks at ports" (L4) versus "this box looks at HTTP" (L7), and the industry standardised on them.
TCP/IP beside OSI
How it fails
What the failure looks like from inside real software.Reference · showHide
- Debugging at the wrong layer: hours in application logs for a problem that
ping(IP) orip neigh(link) would have shown in seconds. - Assuming message boundaries over TCP: a client sends two JSON objects, the server reads them as one buffer and the parser fails intermittently under load.
- A "layer-7" firewall rule that cannot see inside TLS: it matches nothing and silently allows everything.
- Treating QUIC as "just UDP" in a firewall policy: blocking UDP 443 does not break HTTPS (browsers fall back to TCP), it just makes it slower — and hides the misconfiguration.
Check yourself
Answer out loud or on paper first, then compare. These come from the interview questions linked to this lesson.
What is the difference between the OSI model and the TCP/IP model, and does the difference matter in practice?
Show a strong answerHide the answer
OSI is a reference model from the ISO in the 1980s with seven layers; TCP/IP is the protocol suite the internet runs, usually described with four or five layers (link, internet/IP, transport, application — with physical sometimes split out). The internet protocols were designed and deployed before OSI was finished, so the seven layers never described them exactly: there is no separate session or presentation protocol in the stack; TLS sits awkwardly between transport and application, and HTTP does its own "presentation" (content types, encodings).
What both models get right is encapsulation: each layer adds a header, treats everything above it as opaque payload, and offers a service to the layer above without exposing how. IP moves packets between hosts without caring whether TCP or UDP is inside; TCP gives an ordered byte stream without caring whether HTTP or SSH is inside. That independence is why a new application protocol needs no router changes, and why routers can be replaced without applications noticing.
In practice the numbers survive as vocabulary: an "L2 switch" forwards by MAC, an "L3 router" by IP, an "L4 load balancer" by IP and port, an "L7 proxy" by HTTP content. Engineers say "layer 7" and "layer 4" daily and never say "layer 5 or 6". So the difference matters as language, not as architecture — and the layer boundaries are where you debug: which layer produced this failure, and what tool observes that layer?
Full interview question, with follow-ups and red flags →What is the difference between a layer-4 and a layer-7 load balancer? What does each one see, what can each one do, and what does each one break?
Show a strong answerHide the answer
An L4 balancer sees the IP and TCP/UDP headers — the five-tuple — and nothing inside the payload. It comes in two flavours: packet-forwarding (IPVS/LVS, Google Maglev, AWS NLB, Kubernetes
kube-proxy) which rewrites addresses or uses direct server return and never holds a TCP connection itself, so it moves millions of packets per second and preserves the client IP; and a TCP proxy (HAProxymode tcp, nginxstream) which terminates the client’s connection and opens another to the backend. Either way it distributes connections: every byte of a connection goes to the backend chosen atSYNtime. It cannot route by path or host, cannot retry a request, cannot see whether the backend answered 500, and its health check is "the port accepts a connection", which is not the same as "the service works". It also cannot see TLS, which is a feature when end-to-end encryption or mTLS to the backend is required. See Load Balancers: L4 vs L7.An L7 balancer terminates TCP *and* usually TLS, parses HTTP, and distributes requests: each request on a client connection can go to a different backend over a pool of keep-alive connections. That unlocks routing on host, path, header and cookie; canaries and weighted splits; per-request retries with a budget; timeouts, rate limits and circuit breaking; header injection (
X-Forwarded-For,X-Forwarded-Proto, request ids); HTTP/2 or HTTP/3 toward clients with HTTP/1.1 toward backends; compression, caching, WAF. Its health check can be a realGET /healthz. The price is CPU (TLS + parsing), a little latency, and a new identity in the middle: the backend sees the balancer’s IP, so client identity must travel in a header the backend has to *trust* only from that hop; the balancer becomes the one that generates 502/503/504 and enforces its own idle and request timeouts; request or response buffering silently breaks streaming bodies and SSE; WebSocket needs explicit upgrade support. See Forward and Reverse Proxies.The trade-off in one line: L4 is transparent and cheap but distributes the wrong unit for HTTP, L7 distributes the right unit and can fix things but is itself a component that fails. Connection-level distribution matters more than it sounds — with keep-alive or HTTP/2, one client connection may carry thousands of requests, so an L4 balancer in front of a few chatty clients produces badly uneven backend load, and a freshly added backend gets nothing until connections churn. Most real deployments stack them: an L4 tier for raw ingress and DDoS absorption, an L7 tier (nginx, Envoy, ALB, an ingress controller) behind it for the HTTP intelligence. Non-HTTP protocols — databases, MQTT, raw gRPC-over-TLS with mTLS to the pod — use L4 by necessity.
Full interview question, with follow-ups and red flags →Where does TLS sit?
Show a strong answerHide the answer
Between transport and application: it needs a reliable stream below, and applications above see a stream. OSI would call it session/presentation; nobody does.
Full interview question, with follow-ups and red flags →