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.
- 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.