Every time you press Enter in a browser, a few hundred bytes of text leave your computer. They are wrapped in four or five layers of headers and turned into electrical or radio signals. They pass through a dozen machines owned by different companies. Then a server, which may be thousands of kilometres away, unwraps them again. All of this usually takes less than a tenth of a second. The OSI reference model is the vocabulary engineers use to describe that journey. Yet most explanations stop at a list of seven names and never show what really happens to the bytes.
This article closes that gap. First, it explains the seven layers of the OSI model and the protocols in each layer with academic precision. Then it follows concrete requests byte by byte. The main example is a JSON POST from a laptop to a web server, including the DNS lookup, the TLS handshake, every header, the hop-by-hop forwarding across the Internet and the way back. Further examples cover a large download with packet loss, HTTP/3 over QUIC, local traffic with ARP, troubleshooting layer by layer and the security controls of each layer. The article is long on purpose. When you finish it, you should be able to explain every step between "Enter" and "201 Created".
1. Why Networks Are Built in Layers
Computer communication is one of the most complex things engineers have ever standardised. A single web request touches many fields. It needs electrical engineering (how a voltage represents a bit) and radio physics (how Wi-Fi shares the air). It needs graph theory (how routers find paths) and control theory (how TCP avoids overloading the network). It also needs cryptography (how TLS keeps the content secret) and, in the broadest sense, linguistics (how a client and a server agree on the meaning of POST). No single specification could cover all of that, and no single team could implement it. The answer, in networking as in most of computer science, is layering.
A layered architecture divides the problem into a stack of levels. Each level solves one part of the problem. It uses the services of the level directly below it and offers a service to the level directly above it. The level above only needs to know what the level below promises, not how it works. Your browser does not care whether the bits travel over copper, fibre or radio. TCP does not care whether the bytes it carries are HTML, JSON or a video. The Ethernet card does not care whether the packet inside its frame belongs to a web request or a DNS query.
This separation has four practical benefits:
Independent evolution. Ethernet went from 10 Mbit/s to 800 Gbit/s, Wi-Fi went through seven generations, and HTTP went from version 0.9 to 3. Yet no change forced a change in the other layers. Your 1990s web server code still works over 5G.
Interchangeability. During one journey, the same IP packet can travel over Ethernet, Wi-Fi, a cellular link, a satellite link and an undersea cable. Each link only has to know how to carry "an IP packet", not what is inside it.
Division of labour. Chip designers implement the lowest layers in hardware. Operating system developers implement the middle layers in the kernel. Application developers implement the top layers in user space (the area where normal programs run, outside the kernel). Each group works against a stable interface.
Diagnosability. When something fails, a layered model gives you a systematic method: check the layers from the bottom up until you find the first one that does not work. Section 19 turns this into a troubleshooting procedure.
Layering has a price: overhead and some inefficiency. Every layer adds its own header. In our main example, this turns a 63-byte JSON message into a 342-byte burst of energy on the cable. Also, the strict separation sometimes hides useful information. For example, TCP may interpret a lost radio frame as network congestion. We will see both effects in the examples, because the costs are as important to understand as the benefits.
1.1 A Short History of the OSI Model
In the 1970s, every computer vendor had its own network architecture: IBM had SNA, Digital Equipment had DECnet, Xerox had XNS. Machines from different vendors could hardly talk to each other. To fix this, the International Organization for Standardization (ISO) and the telecommunications standards body CCITT (today ITU-T) started the Open Systems Interconnection project. Its goal was a vendor-neutral architecture. The result was the Basic Reference Model for Open Systems Interconnection. It was published in 1984 as ISO 7498 and as ITU-T Recommendation X.200, and revised in 1994 as ISO/IEC 7498-1.
The OSI project defined two things: a reference model (the seven layers) and a full suite of protocols to implement it (for example X.400 for e-mail and FTAM for file transfer). The protocols mostly failed in the market. The simpler TCP/IP suite was already working and spreading, because it was developed for the ARPANET and distributed freely with BSD Unix. The reference model, however, survived. Its vocabulary is so useful that the whole industry still speaks of "Layer 2 switches", "Layer 4 load balancers" and "Layer 7 firewalls". This is true even though those devices run TCP/IP protocols, not OSI protocols.
The OSI model is not a description of how the Internet is built. It is a precise vocabulary for describing how any network is built, including the Internet.
1.2 The Seven Layers at a Glance
The model has seven layers. They are numbered from the bottom (closest to the physical medium) to the top (closest to the user). The traditional memory aid, from bottom to top, is "Please Do Not Throw Sausage Pizza Away".
No.
Layer
Responsibility in one sentence
Typical protocols and technologies
Unit of data
7
Application
Gives applications network services and defines what messages mean
HTTP, DNS, SMTP, IMAP, SSH, FTP, MQTT
Message
6
Presentation
Puts data in an agreed format: encoding, serialisation, compression, encryption
UTF-8, JSON, XML, ASN.1, gzip, TLS (partly)
Message
5
Session
Opens, manages and closes dialogues between applications
TLS sessions, RPC sessions, NetBIOS, SIP (partly)
Message
4
Transport
Delivers data end to end between processes, reliably or not
TCP, UDP, QUIC, SCTP
Segment / datagram
3
Network
Delivers packets between hosts across many networks (routing)
IPv4, IPv6, ICMP, IPsec, OSPF, BGP
Packet
2
Data link
Delivers frames between neighbouring nodes on one link
Ethernet, Wi-Fi (802.11), PPP, ARP, VLAN
Frame
1
Physical
Sends raw bits as signals over a medium
Copper, fibre, radio, line codes, connectors
Bit / symbol
Two points already matter here. First, the boundary between layers 5, 6 and 7 is unclear in practice. The TCP/IP world simply merges them into one application layer (section 3). Second, the unit of data has a different name in each layer. This is not pedantry. When an engineer says "packet", they mean the layer-3 unit including the IP header. When they say "frame", they mean the layer-2 unit including the Ethernet header and trailer. Precise names prevent misunderstandings.
2. The Vocabulary: Services, Protocols, PDUs and Encapsulation
Before we walk through the layers, we need a few terms that the OSI standard defines carefully. They make the rest of the article much easier to follow.
2.1 Entities, Services and Protocols
In OSI terms, the active element in a layer is an entity. An entity is a piece of hardware or software that implements that layer, for example the TCP implementation in the Linux kernel. Entities in the same layer on different machines are called peer entities.
A layer interacts in two directions, and the model gives each direction its own name:
Service (vertical): what a layer offers to the layer above it on the same machine. For example, TCP offers the application the service "reliable, ordered byte stream between two processes". The layer above uses the service through a service access point (SAP). In TCP/IP, the socket API with its port numbers plays this role.
Protocol (horizontal): the rules that peer entities on different machines follow to provide that service. For example, the TCP protocol defines sequence numbers, acknowledgements and retransmissions. With these rules, the two TCP entities together provide the reliable-stream service.
This distinction is the heart of the model. Each layer behaves as if it were talking directly to its peer on the other machine (virtual communication). In reality, it hands its data down to the layer below. Only layer 1 ever transmits anything physically.
Host A Host B
+----------------+ virtual: HTTP protocol +----------------+
| Application | <---------------------------> | Application |
+----------------+ +----------------+
| service ^
v |
+----------------+ virtual: TCP protocol +----------------+
| Transport | <---------------------------> | Transport |
+----------------+ +----------------+
| ^
v |
+----------------+ virtual: IP protocol +----------------+
| Network | <---------------------------> | Network |
+----------------+ +----------------+
| ^
v |
+----------------+ +----------------+
| Data link | | Data link |
+----------------+ +----------------+
| ^
v real transmission |
+----------------+ ============================> +----------------+
| Physical | | Physical |
+----------------+ +----------------+
3. The OSI Model and the TCP/IP Model
The Internet is not built on OSI protocols. It is built on the TCP/IP suite, which has its own, simpler architecture. RFC 1122 (1989), the "Host Requirements" document, describes four layers. Many textbooks use a five-layer hybrid model instead. It splits the lowest TCP/IP layer back into a physical layer and a data link layer, because this distinction is too useful to give up.
OSI layer
TCP/IP layer (RFC 1122)
Hybrid textbook model
Protocols in our examples
7 Application
Application
Application
HTTP/1.1, HTTP/3, DNS
6 Presentation
Application
Application
JSON, UTF-8, gzip, TLS encryption
5 Session
Application
Application
TLS handshake and session resumption
4 Transport
Transport
Transport
TCP, UDP, QUIC
3 Network
Internet
Network
IPv4, IPv6, ICMP
2 Data link
Link
Data link
Ethernet, Wi-Fi, ARP, NDP
1 Physical
Link
Physical
1000BASE-T, 802.11ax radio, fibre
3.1 Why the Internet Merged Layers 5 to 7
The designers of TCP/IP took a practical view. Session and presentation functions are very specific to each application. A general-purpose layer for them adds complexity without benefit. HTTP, for example, manages its own "sessions" with cookies. It encodes its own data with Content-Type and Content-Encoding headers, and it leaves encryption to TLS. So the TCP/IP model has one application layer, and every application protocol decides for itself how much session and presentation logic it needs.
This is also why the popular interview question "On which layer is TLS?" is really hard to answer. TLS sits above TCP and below HTTP. It establishes and resumes sessions (a layer-5 function), and it encrypts and authenticates data (a layer-6 function). But in the TCP/IP model it is simply part of the application layer, implemented as a library inside the application. A precise answer is: "TLS provides session-layer and presentation-layer functions; in the TCP/IP model it is part of the application layer, sitting between the application protocol and TCP." Section 8 and section 12 explain this in detail.
4. Layer 1: The Physical Layer
At the physical layer, information stops being abstract. Its job is to send a sequence of bits from one device to the next, directly connected device as a physical signal. This signal can be a voltage on a pair of copper wires, a pulse of light in a glass fibre or an electromagnetic wave in the air. The physical layer knows nothing about frames, addresses or packets. It only knows bits and, more precisely, symbols: the physical states that the receiver can tell apart, each of which represents one or more bits.
4.1 What the Physical Layer Specifies
A physical-layer standard defines four groups of properties:
Mechanical: connectors, cables and pin assignments, for example the RJ45 plug, the LC fibre connector or the antenna requirements of a Wi-Fi radio.
Electrical or optical: voltage levels, impedance, light wavelength (850 nm for short-range multimode fibre, 1310 nm and 1550 nm for long-range single-mode fibre), transmit power and receiver sensitivity.
Functional and procedural: how a link starts up, how the two ends agree on speed and duplex mode (auto-negotiation), and how the receiver recovers the sender's clock.
Coding and modulation: how bits are mapped to symbols and symbols to signals.
4.2 From Bits to Signals: Line Coding and Modulation
A simple approach would send a high voltage for 1 and a low voltage for 0. In practice, this fails for two reasons. First, a long run of identical bits produces a constant signal, so the receiver loses track of where one bit ends and the next begins (this is the problem of clock recovery). Second, a signal with a non-zero average (a DC component) cannot pass through the transformers that electrically isolate Ethernet ports. Real systems therefore use line codes (rules that map bits to signal patterns) and modulation (changing a carrier wave to represent bits):
Technology
Coding / modulation
Idea
10BASE-T Ethernet
Manchester
Every bit is a transition (high-to-low or low-to-high), so the clock can always be recovered; the cost is double the signalling rate
100BASE-TX
4B5B + MLT-3
4 data bits become 5 code bits that never contain long runs of zeros; MLT-3 cycles through three voltage levels to lower the frequency
1000BASE-T
8B1Q4 / PAM-5 over 4 pairs
Five voltage levels on all four copper pairs at the same time in both directions, with echo cancellation
5. Layer 2: The Data Link Layer
The physical layer delivers a stream of bits that has no structure and may contain errors. The data link layer turns this stream into frames: delimited blocks of data with addresses and an error check. Frames are exchanged between two devices on the same link or local network. The scope of layer 2 is strictly local: a layer-2 frame never travels further than the next router. This single fact explains much of how the Internet works, and section 14 shows it in practice.
IEEE splits the layer into two sublayers. The Media Access Control (MAC) sublayer handles addressing and access to the medium. The Logical Link Control (LLC, IEEE 802.2) sublayer identifies the upper-layer protocol. In Ethernet II framing, which IP uses, the LLC function is reduced to the EtherType field.
5.1 The Functions of Layer 2
Framing: marking where a frame begins and ends.
Physical addressing: identifying sender and receiver on the local network with MAC addresses.
Error detection: a checksum over the frame (the frame check sequence) so that damaged frames are discarded.
Media access control: deciding who may send on a shared medium.
Optionally, reliability and flow control: Wi-Fi acknowledges every unicast frame and retransmits lost ones; Ethernet does not.
5.2 MAC Addresses
A MAC address (officially an EUI-48 address) is 48 bits long. It is written as six hexadecimal bytes, for example 3c:22:fb:4a:10:9e. Traditionally, the first three bytes are the Organizationally Unique Identifier (OUI), which IEEE assigns to the manufacturer. The manufacturer assigns the last three bytes. Two bits of the first byte have a special meaning:
Bit (of the first byte)
Value 0
Value 1
Least significant bit (I/G)
Individual (unicast) address
Group (multicast/broadcast) address
Second least significant bit (U/L)
Universally administered (burned in by the vendor)
Locally administered (set by software)
The address ff:ff:ff:ff:ff:ff is the broadcast address: every device on the local network accepts the frame. Modern phones and laptops use random, locally administered MAC addresses for Wi-Fi to prevent tracking. That is why you sometimes see addresses like whose second-lowest bit is set.
6. Layer 3: The Network Layer
Layer 2 connects devices on one local network. Layer 3 connects networks. It gives every host a logical address that does not depend on the hardware. It also moves packets from the source host to the destination host across any number of networks in between; this process is called routing. On the Internet, layer 3 is the Internet Protocol in its two versions, IPv4 (RFC 791) and IPv6 (RFC 8200).
IP deliberately offers a minimal service: connectionless, best-effort delivery. Every packet is routed independently. Packets may be lost, duplicated, delayed or reordered, and IP does not notice or care. This minimal service is the key design decision of the Internet (the "end-to-end principle"): the network core stays simple and fast, and the end hosts add reliability where they need it.
6.1 IPv4 Addresses, Prefixes and Subnets
An IPv4 address is 32 bits long and is written as four decimal bytes: 192.168.1.23. It consists of a network prefix and a host part. The prefix length is written in CIDR notation (Classless Inter-Domain Routing). 192.168.1.0/24 means "the first 24 bits identify the network". This leaves 8 bits (256 addresses, 254 usable) for hosts. The same information written as a subnet mask is 255.255.255.0.
For every outgoing packet, the host first decides whether the destination is on its own subnet. It computes a bitwise AND of both addresses with its mask:
own address 192.168.1.23 11000000.10101000.00000001.00010111
mask /24 255.255.255.0 11111111.11111111.11111111.00000000
own network 192.168.1.0
destination 203.0.113.10 11001011.00000000.01110001.00001010
AND mask 203.0.113.0 -> different network -> send to the default gateway
If the networks match, the host sends the frame directly to the destination's MAC address (found with ARP). If they do not match, it sends the frame to the MAC address of its default gateway (the router), while the IP destination remains the final server. This is the most important interaction between layers 2 and 3: the IP destination says where the packet ultimately goes, the MAC destination says who receives it next.
Some address ranges have a special meaning. RFC 1918 reserves 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 for private networks. These addresses are not routed on the Internet and need NAT (section 6.6). 127.0.0.0/8 is loopback, and 169.254.0.0/16 is link-local. RFC 5737 reserves , and for documentation, which is why this article uses them.
7. Layer 4: The Transport Layer
IP delivers packets from one host to another, but it does not guarantee delivery. A host also runs many processes at the same time (a browser with twenty tabs, a mail client, a backup agent). Most applications need their data to arrive complete and in the right order. The transport layer solves both problems. It is the first layer that works end to end: only the two communicating hosts implement it, not the routers in the middle of the network (except NAT devices and firewalls, which look into it).
7.1 Ports, Sockets and the 5-Tuple
The transport layer adds port numbers: 16-bit numbers that identify the communicating processes. Servers listen on well-known ports, which are registered with IANA (80 for HTTP, 443 for HTTPS, 53 for DNS, 22 for SSH, 25 for SMTP). Clients use a temporary ephemeral port. The operating system chooses it from a range such as 49152–65535 (Linux uses 32768–60999 by default).
Each connection is uniquely identified by its 5-tuple: protocol, source IP, source port, destination IP and destination port. Our example connection is:
(TCP, 192.168.1.23, 51544, 203.0.113.10, 443)
This is how one server process on port 443 can serve thousands of clients at the same time. Every connection has a different 5-tuple, and the kernel delivers each arriving segment to the right socket (the operating system object that represents one end of a connection). The socket API (socket, connect, bind, listen, accept, send, recv) is the service access point between layer 4 and the application.
7.2 UDP: The Minimal Transport
The User Datagram Protocol (RFC 768) adds exactly two things to IP: ports and a checksum (optional over IPv4, mandatory over IPv6). Its header is 8 bytes long:
UDP has no connection, no acknowledgement, no retransmission, no ordering and no congestion control. This sounds like a weakness. However, it is useful for applications that prefer speed to completeness, or that implement their own reliability. Examples are DNS queries (one request, one response, retry on timeout), voice and video calls (a late packet is useless anyway), online games, and QUIC, which builds a complete modern transport on top of UDP (section 17).
8. Layer 5: The Session Layer
The session layer is the most misunderstood layer, because the Internet has no dedicated protocol for it. In the OSI model, it organises the dialogue between two applications on top of the transport connection. The OSI session service definition (ISO 8326, with the protocol in ISO 8327) lists its functions:
Session establishment, maintenance and release, including authentication of the two partners in the dialogue.
Dialogue control: deciding who may send and when (two-way simultaneous, two-way alternate or one-way). Tokens are used to manage this.
Synchronisation: inserting checkpoints (synchronisation points) into a long transfer. After a failure, the transfer can continue from the last checkpoint instead of starting again.
Activity management: grouping related exchanges into logical units of work.
8.1 Session Functions in Today's Protocols
These functions still exist in the TCP/IP world. However, individual protocols implement them, instead of a shared layer:
Session function
Where it lives today
Example
Establishing an authenticated dialogue
TLS handshake
Client and server agree on keys; the client checks the server's certificate
Resuming a session without full setup
TLS session resumption (PSK, tickets)
A returning browser skips the certificate exchange
Keeping state across many connections
HTTP cookies, tokens
Set-Cookie: session=... keeps you logged in across requests and connections
Checkpoints and restart
HTTP range requests, resumable uploads
Range: bytes=500000000- continues an interrupted download
Dialogue control
Request/response rules of HTTP/1.1, multiplexed streams in HTTP/2
Without pipelining, an HTTP/1.1 client may not send a second request on a connection until the first response is complete
Grouping related channels
RPC frameworks, SIP, WebSocket
A video call has signalling, audio and video streams that belong together
The word "session" has two meanings, and it is important to keep them apart. A TLS session is a cryptographic context between two endpoints. An (a login session) is application state on the server. A cookie or token refers to it, and it lasts across many TCP and TLS connections. In OSI terms, both are session-layer ideas, but at different levels.
9. Layer 6: The Presentation Layer
Two computers can exchange bytes perfectly and still misunderstand each other. One may store integers in big-endian order and the other in little-endian order. One may encode text in UTF-8 and the other in Windows-1252. One may expect XML while the other sends JSON. The presentation layer is responsible for the representation of data: it makes sure that the receiver interprets the bytes as the sender meant them. ISO describes it as the layer that makes applications independent of differences in data representation (syntax).
9.1 The Three Classic Tasks
Translation (encoding and serialisation): converting the application's in-memory data structures into an agreed transfer syntax and back. For this, OSI defined ASN.1 (Abstract Syntax Notation One) with the Basic Encoding Rules. ASN.1 is still used today: with the Distinguished Encoding Rules in X.509 certificates, and with the Basic Encoding Rules in LDAP and SNMP. On the web, the main transfer syntaxes are JSON, XML, Protocol Buffers and HTML.
Compression: making the data smaller, for example with gzip, Brotli or Zstandard for HTTP bodies, or with HPACK and QPACK for HTTP/2 and HTTP/3 headers.
Encryption: protecting confidentiality and integrity. In the OSI model, encryption belongs to this layer. In practice, TLS does it, and TLS also performs session functions.
9.2 Character Encoding: A Concrete Example
Our example request body contains the text "Great explanation of the OSI model!". In UTF-8, every ASCII character takes one byte. So the 63-character JSON object is exactly 63 bytes, and this is why the header says Content-Length: 63. If Alice had written "Großartig!", UTF-8 would encode the ß as two bytes (c3 9f). The content length would then be one byte more than the number of characters. A server that assumes Windows-1252 would display Großartig!. This garbled text is called mojibake, and it is a presentation-layer failure: every lower layer did its job perfectly, but the two ends disagreed about the representation.
HTTP states the representation explicitly in headers. Here an application protocol does the presentation layer's job:
Header
Presentation-layer function
Example
Content-Type
Data format and character set
application/json; charset=utf-8
10. Layer 7: The Application Layer
The application layer is the layer that the user's software speaks. It is not the application itself (the browser is not "in" layer 7). It is the protocol that the application uses to communicate with its peer: HTTP for the web, SMTP and IMAP for mail, DNS for name resolution, SSH for remote shells, MQTT for IoT devices. These protocols define the messages that two applications exchange and the semantics (meaning) of those messages: what a POST means, what a 201 status means, what an MX record is.
10.1 HTTP/1.1 Message Structure
HTTP is defined in RFC 9110 (semantics, common to all versions) and RFC 9112 (the message syntax of HTTP/1.1). An HTTP/1.1 message is plain text with a strict structure:
request-line = method SP request-target SP HTTP-version CRLF
header fields = *( field-name ":" OWS field-value OWS CRLF )
empty line = CRLF
message body = *OCTET (length from Content-Length or chunked coding)
Every line ends with the two bytes 0d 0a (carriage return, line feed). The empty line separates the header from the body. This is our complete example request. It is exactly 230 bytes: 167 bytes of header and 63 bytes of body:
POST /api/posts/42/comments HTTP/1.1
Host: blog.example.com
User-Agent: curl/8.11.1
Accept: application/json
Content-Type: application/json
Content-Length: 63
{"author":"Alice","text":"Great explanation of the OSI model!"}
These are its first 64 bytes as they appear on the wire (before encryption):
Method (POST): the requested action. RFC 9110 defines GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS and TRACE, and RFC 5789 adds PATCH. Methods have formal properties. GET is safe (it has no side effects) and idempotent (repeating it has the same effect as sending it once). PUT and DELETE are idempotent. is neither, and this is why browsers warn you before they submit a form again.
11. Before the First Byte: DNS Resolution
We now know the vocabulary of all seven layers. From here on, the article follows one concrete scenario from start to end. The scenario: Alice sits at her laptop in her home network. She runs the command below to post a comment on a blog. The laptop is connected by cable to the home router; section 5.5 describes what would be different over Wi-Fi.
curl --http1.1 -X POST https://blog.example.com/api/posts/42/comments \
-H "Accept: application/json" -H "Content-Type: application/json" \
-d '{"author":"Alice","text":"Great explanation of the OSI model!"}'
The participants and their addresses (all from the documentation ranges of RFC 5737):
Participant
IP address
MAC address
Role
Alice's laptop
192.168.1.23 (private)
3c:22:fb:4a:10:9e
Client
Home router, LAN side
192.168.1.1
98:9b:cb:21:7e:01
Default gateway, NAT, DNS forwarder
Home router, WAN side
198.51.100.77 (public)
(ISP-side interface)
Public address of the household
ISP DNS resolver
198.51.100.53
–
Recursive resolver
Web server blog.example.com
203.0.113.10
–
Server, port 443
The first problem is that curl has a name, blog.example.com, but IP needs an address. The Domain Name System (DNS, RFC 1034 and RFC 1035) turns names into addresses. DNS is itself an application-layer protocol. So it has to run before the application's own protocol can start.
11.1 The Resolution Chain
Local caches. The operating system's resolver library (called through getaddrinfo) first checks the /etc/hosts file. It then checks its own cache, if the system runs one (systemd-resolved on Linux, mDNSResponder on macOS). It finds nothing.
Stub resolver to recursive resolver. The laptop's simple built-in resolver (the stub resolver) sends a DNS query to the resolver that DHCP configured. In many homes this is the router. The router forwards the query to the ISP's recursive resolver .
12. Establishing Trust: TCP Handshake and TLS 1.3
Now the address 203.0.113.10 is known. curl asks the kernel to open a TCP connection to port 443. The kernel performs the three-way handshake from section 7.5 (one round trip). Then curl uses its TLS library to perform the TLS 1.3 handshake (RFC 8446) inside that connection. TLS has three goals: authentication of the server (and optionally the client), confidentiality of the data (nobody else can read it) and integrity of the data (nobody can change it unnoticed). TLS 1.3 reaches all three in a single round trip.
12.1 The TLS Record Layer
Everything TLS sends travels in records. A record has a 5-byte header followed by the content:
Byte 0 Content type 22 = handshake, 23 = application data,
21 = alert, 20 = change_cipher_spec
Bytes 1-2 Legacy version 03 03 (always "TLS 1.2" on the wire,
for compatibility with old middleboxes)
Bytes 3-4 Length length of the content that follows
(max. 16384 + overhead)
After the handshake, every record is encrypted with an AEAD cipher (authenticated encryption with associated data). This is usually AES-128-GCM, AES-256-GCM or ChaCha20-Poly1305. The real content type moves inside the encrypted part, and the outer type of every encrypted record is 23. (Only the optional, unencrypted ChangeCipherSpec compatibility record keeps type 20.) So an observer cannot even tell handshake messages apart from data. The cipher adds a 16-byte authentication tag at the end. If even one bit of the record changes on the way, the tag check fails and the connection is closed.
12.2 The Handshake Messages
Client Server
| |
|--- ClientHello ---------------------------------------------------->|
| random, cipher suites, key_share (X25519 public key), |
| server_name = blog.example.com (SNI), ALPN = http/1.1, |
| supported_versions = TLS 1.3, signature_algorithms |
| |
|<-- ServerHello ----------------------------------------------------|
| random, chosen cipher suite, key_share (server X25519 key) |
| ===== both sides now compute the shared secret (ECDHE) ===== |
|<-- {EncryptedExtensions} ALPN = http/1.1 --------------------------|
|<-- {Certificate} blog.example.com + intermediate CA -------|
|<-- {CertificateVerify} signature over the handshake so far ------|
|<-- {Finished} MAC over the handshake -------------------|
| |
|--- {Finished} ----------------------------------------------------->|
|--- [Application data: HTTP request] ------------------------------->|
| |
{ } = encrypted with handshake keys [ ] = encrypted with application keys
13. Example 1, Part 1: Encapsulation on the Sender
The TCP connection is open, TLS is complete, and curl passes the 230-byte HTTP request to the TLS library. We now follow these bytes down through the layers of Alice's laptop. For every layer we answer three questions: what does it receive, what does it add, and what decisions does it make?
13.1 Layer 7: The HTTP Message
curl builds the request from section 10.1. All its decisions are about meaning: method POST because it creates a new comment, the request target from the URL, the Host header from the URL's authority part, Content-Type from the -H option, and Content-Length: 63 from the measured size of the body. The output is a sequence of 230 bytes. Layer 7 is now done. It will hear from the network again only when the response arrives.
13.2 Layers 6 and 5: The TLS Record
The TLS library receives the 230 bytes as application data. It adds one byte with the real content type (17, application data). It then encrypts the resulting 231 bytes with AES-128-GCM, using the client's application traffic key, with the next record sequence number as part of the nonce. Finally, it adds the 16-byte authentication tag. The record header gives a length of 231 + 16 = 247 bytes:
From now on, nobody between Alice and the server can read the URL path, the headers or the JSON body. An observer can see the destination IP address, the port, the SNI from the handshake and the size of the record, but not its content. The TLS library writes the 252 bytes into the TCP socket with send().
13.3 Layer 4: The TCP Segment
The kernel's TCP implementation copies the 252 bytes into the socket's send buffer. Its decisions:
Segmentation: 252 bytes is far below the 1448 bytes of payload that fit into one segment (the MSS of 1460 bytes minus 12 bytes of TCP timestamp option), so the data fits into one segment. A larger body would be split into several segments (section 16).
Sequence number: the number of the connection's next unsent byte. After the SYN with ISN 2918733523, the client has sent 581 bytes of TLS handshake: ClientHello 517 bytes, a 6-byte compatibility ChangeCipherSpec record and the 58-byte encrypted Finished. So the next byte is 2918733523 + 1 + 581 = .
14. Example 1, Part 2: The Journey Across the Internet
The frame has left the laptop. Between Alice and the server there are about a dozen devices: a switch, the home router, several routers of her ISP, an Internet exchange or transit provider, and the routers and switches of the data centre. The main idea of this section is simple and fundamental: at every router, the packet is unwrapped up to layer 3 and wrapped again in a brand-new layer-2 frame. Layers 4 to 7 travel untouched from end to end.
14.1 Hop 0: The Switch Inside the Home Router
Most home routers contain a small Ethernet switch. The frame arrives on LAN port 2. The switch learns that 3c:22:fb:4a:10:9e is on port 2 and looks up the destination 98:9b:cb:21:7e:01. It finds that this is the router's own internal port and forwards the frame there. Nothing in the frame changes. The switch read just 12 bytes of it: the two MAC addresses.
14.2 Hop 1: The Home Router
The router's LAN interface receives the frame and works its way up the stack:
Layer 1/2: the frame check sequence is correct, the destination MAC is the router's own, and the EtherType says IPv4. The router removes and discards the Ethernet header and trailer.
Layer 3: the IP header checksum is valid. The destination 203.0.113.10 is not one of the router's own addresses, so the router must forward the packet. It decrements the TTL from 64 to 63 and looks up its routing table. The only matching route is the default route towards the ISP.
Layer 4 (NAT): the source address 192.168.1.23 is private, so it cannot be routed on the Internet. The router's NAT (Network Address Translation) finds or creates a translation entry and rewrites the source to 198.51.100.77:40112. It updates the IP header checksum (now 78 02, which reflects both the new TTL and the new source address). It also updates the TCP checksum, because the TCP checksum covers the pseudo-header, which contains the IP addresses.
Stateful firewall: the connection was opened from the inside, so the packet matches an established connection and the firewall allows it.
New layer 2: the WAN side of a home connection is often not plain Ethernet. On many DSL and some fibre connections, the router encapsulates the packet in PPPoE (PPP over Ethernet). PPPoE adds 8 bytes and therefore reduces the MTU for IP packets to 1492 bytes. On cable networks, DOCSIS frames carry the packet; on fibre-to-the-home, frames carry it. In every case the router puts the IP packet into a new frame with new layer-2 addresses.
15. Example 1, Part 3: Decapsulation, Processing and the Response
The frame arrives at the server's network card. Now the process runs in reverse. Each layer checks its own header and uses it to decide what to do. It then removes the header and passes the payload up to the protocol named in the demultiplexing field (the field that says which protocol comes next).
15.1 Layers 1 and 2 on the Server
The PHY (the physical-layer chip) of the NIC recovers the clock from the preamble, decodes the symbols back into bits and finds the frame boundaries. The MAC checks the CRC-32: correct. It compares the destination MAC address with its own: match. It writes the frame into a receive ring buffer in main memory via DMA (direct memory access, without using the CPU). After a short interrupt-coalescing delay (it waits briefly so that one interrupt can cover several frames), it signals the kernel. The Linux driver processes received frames in batches (NAPI). It reads the EtherType 0x0800 and hands the payload to the IPv4 receive routine.
15.2 Layer 3 on the Server
The IP layer checks the version, the header length and the header checksum. It confirms that the destination 203.0.113.10 is one of the server's own addresses. It also checks the packet against the local firewall rules (netfilter/nftables). The packet is not a fragment. The protocol field 6 sends the payload to TCP.
15.3 Layer 4 on the Server
TCP verifies the checksum. The checksum includes the pseudo-header with the translated source address 198.51.100.77, which is why NAT had to update it. TCP then looks up the socket for the 5-tuple (TCP, 198.51.100.77, 40112, 203.0.113.10, 443). It finds the established connection that the web server accepted during the handshake. The sequence number 2918734105 is exactly the next expected byte. So TCP appends the 252 bytes to the socket's receive buffer, and the ACK it sends back will acknowledge byte 2918734105 + 252 = 2918734357. Linux waits a short time before it sends a pure ACK (delayed ACK), in the hope of piggybacking it on response data. In our case this works: the response will carry the acknowledgement. Finally, TCP wakes up the web server process that is waiting in epoll.
If a segment had arrived out of order, TCP would hold it in an out-of-order queue and wait until the gap is filled. Until then, the application would see nothing. This is head-of-line blocking, a concept that becomes important in sections 16 and 17.
15.4 Layers 5 and 6 on the Server
The web server (say nginx) calls SSL_read. The TLS library reads the 5-byte record header () and waits until all 247 bytes of the record are in the buffer. It then decrypts them with the client-to-server application key and the expected record sequence number. The AES-GCM tag verifies, which proves that nobody altered or replayed the record. The last decrypted byte, , says that the content is application data. The library returns the 230 bytes of HTTP to nginx.
16. Example 2: A Large Download, Packet Loss and MTU Problems
The first example sent a message that fit into a single packet. Most real traffic, however, consists of large transfers. These show mechanisms of the transport layer that a small request never uses. Alice now downloads a 1 MB PDF over the same connection, which is already established:
GET /downloads/osi-poster.pdf HTTP/1.1
Host: blog.example.com
Accept: application/pdf
16.1 Segmentation at Every Layer
The server's response body is 1,000,000 bytes. Each layer cuts the data according to its own size limit:
L7 HTTP 1 response: header (~200 bytes) + body of 1,000,000 bytes
(Content-Length: 1000000)
L6 TLS records of at most 16,384 bytes of plaintext
-> 62 records (+22 bytes overhead each)
L4 TCP segments of at most 1,448 bytes of payload
(MSS 1460 minus 12 bytes timestamps) -> about 692 segments
L3 IP one packet per segment, 1,500 bytes each (no fragmentation)
L2 Ethernet one frame per packet, 1,518 bytes each
The boundaries do not line up. A TLS record of 16,406 bytes spans about 11.3 TCP segments, so TLS records start and end in the middle of segments. This is not a problem, because each layer only cares about its own units. TCP delivers a byte stream, TLS reads records from that stream, and HTTP reads its body from the decrypted stream.
16.2 Slow Start in Numbers
The connection was idle before the download, and Linux resets the congestion window after an idle period. The congestion window is the amount of data the sender may have in flight without an acknowledgement. So the server starts with the initial window of 10 segments (RFC 6928) and doubles the window every round trip:
Round trip
Congestion window (segments)
Sent this round
Cumulative segments
Cumulative data
1
10
10
10
14 KB
2
20
20
30
43 KB
3
40
40
17. Example 3: The Same Request over HTTP/3 and QUIC
Modern browsers send a large share of their traffic over HTTP/3 (RFC 9114). HTTP/3 runs on QUIC (RFC 9000), and QUIC runs on UDP. The application semantics of our request do not change at all: same method, same path, same headers, same JSON body, same 201 Created. What changes is everything between layer 7 and layer 3, and it is useful to see how much changes.
17.1 How the Client Discovers HTTP/3
A client cannot know in advance that a server speaks HTTP/3, because HTTP/3 uses a different transport (UDP instead of TCP). There are two ways to discover it. First, the server can announce it in an HTTP response header over an existing HTTP/1.1 or HTTP/2 connection: Alt-Svc: h3=":443"; ma=86400 ("the same service is available via HTTP/3 on UDP port 443 for the next 24 hours"). Second, DNS can announce it in advance with an HTTPS resource record (RFC 9460), which contains alpn="h3,h2". The client then learns the supported protocols together with the IP address. Some networks block UDP, so browsers usually start QUIC and TCP connections in parallel and use whichever succeeds first.
17.2 The Layering of HTTP/3
HTTP/1.1 over TLS HTTP/3 over QUIC
L7 HTTP/1.1 (text messages) HTTP/3 (binary frames, QPACK headers)
L6/5 TLS 1.3 records QUIC: streams, TLS 1.3 handshake inside,
L4 TCP (in the kernel) packet protection, loss recovery,
congestion control (in user space)
L4 - UDP (in the kernel)
L3 IP IP
L2 Ethernet Ethernet
QUIC does not fit neatly into one OSI layer. Like TCP, it provides transport functions: reliability, ordering per stream, flow control and congestion control. It also provides session functions: connection establishment, migration and resumption. And it includes the TLS 1.3 handshake for encryption (presentation). QUIC uses UDP only as a thin layer to get through the operating system and through middleboxes (devices in the path, such as firewalls and NAT routers). The reason is that deploying a truly new layer-4 protocol on the Internet is practically impossible: countless firewalls and NAT devices only understand TCP and UDP. This problem is called protocol ossification: the network "hardens" around the protocols it already knows. QUIC's answer is to encrypt almost everything, including most of its own headers, so that middleboxes cannot ossify it again.
17.3 One Round Trip Instead of Two
18. Example 4: Local Traffic, ARP, Ping and IPv6 Neighbour Discovery
Not every packet goes to the Internet. Alice may print a document on the network printer at 192.168.1.40, or her laptop may ping the printer to check that it is on. In these cases the layers behave differently, because no router is involved. This small example isolates the interaction between layer 2 and layer 3.
18.1 Ping on the Same Subnet
Alice types ping -c 1 192.168.1.40. The ping program asks the kernel for a raw ICMP socket. It sends an ICMP Echo Request (type 8) with an identifier, a sequence number and 56 bytes of payload. Ping has no layer 4: ICMP sits directly on IP.
Layer 3 decision:192.168.1.40 AND 255.255.255.0 = 192.168.1.0, which is the laptop's own network. The laptop therefore sends the packet directly, without the router. The next hop is the destination itself.
ARP: the laptop has no cache entry for 192.168.1.40, so it broadcasts "Who has 192.168.1.40? Tell 192.168.1.23" (EtherType 0x0806, destination ff:ff:ff:ff:ff:ff). Every device on the LAN receives this request, because the switch floods it to all ports. Only the printer replies, with a unicast frame: "192.168.1.40 is at 00:1b:a9:5c:33:e1". The printer also stores the laptop's mapping, because it will need it for the reply.
Frame: the Echo Request (8 bytes ICMP header + 56 bytes payload = 64 bytes, plus 20 bytes IP header = 84 bytes) goes in an Ethernet frame directly to the printer's MAC address. Now the IP destination and the MAC destination belong to the same device. This is the defining property of local delivery.
Reply: the printer's IP layer recognises its own address. ICMP creates an Echo Reply (type 0) with the same identifier, sequence number and payload, and sends it back directly.
Result:64 bytes from 192.168.1.40: icmp_seq=1 ttl=64 time=1.8 ms. The TTL of 64 tells us that the reply crossed no router (after one router, it would be 63).
The first ping is often clearly slower than the following ones, because it includes the ARP exchange. This is a small, visible piece of layer-2 machinery behind a layer-3 tool.
18.2 Local Versus Remote: The Decisive Difference
Local destination (printer 192.168.1.40)
19. Example 5: Troubleshooting Layer by Layer
Sooner or later, a request fails. The layered model then becomes a method: start at the bottom and move up until you find the first layer that does not work. A failure at a lower layer always causes failures at every layer above it. The lowest failing layer is therefore almost always the one to fix. Each layer has its own tools. If you know which tool tests which layer, guesswork becomes a procedure.
19.1 The Toolbox
Layer
Question
Tools
1
Is there a link? At what speed? Are there physical errors?
Link LED, ip link, ethtool eth0, Wi-Fi signal strength and noise, cable tester
2
Do I see my neighbours? Is the gateway's MAC address known?
ip neigh (Linux), arp -a, tcpdump -e arp, switch MAC tables
3
Do I have an address and a route? Is the destination reachable? Where does the path break?
ip addr, ip route, ping, traceroute, mtr, ping -M do -s 1472 (MTU test)
4
Is the port open? Is the connection established?
nc -vz host 443, ss -tan, telnet host 443, tcpdump 'tcp port 443'
5/6
Does the TLS handshake succeed? Is the certificate valid?
curl -v, browser developer tools, dig for DNS, server logs
All
What exactly is on the wire?
tcpdump, Wireshark
19.2 Walking Up the Stack
Suppose curl https://blog.example.com fails with a timeout. A systematic diagnosis looks like this:
# Layer 1/2: is the interface up, does it have a link?
ip link show eth0 # look for "state UP" and "LOWER_UP"
ip addr show eth0
ip route
ping -c 2 192.168.1.1
ip neigh show 192.168.1.1
ping -c 2 1.1.1.1
dig +short blog.example.com
mtr -rwc 10 203.0.113.10
nc -vz -w 3 203.0.113.10 443
openssl s_client -connect 203.0.113.10:443 -servername blog.example.com </dev/null
curl -v https://blog.example.com/
20. Security at Every Layer
Each layer was designed with a particular threat model, that is, a set of assumptions about who might attack it and how. Most of the original designs assumed a friendly network. So each layer has its typical attacks and its typical defences. When you know which layer an attack targets, you know which defence can stop it. Just as important, you also know which defences cannot. A TLS certificate does nothing against a SYN flood, and a firewall that filters ports does nothing against SQL injection.
20.1 Attacks and Defences by Layer
Layer
Typical attacks
Defences
1 Physical
Wiretapping, cutting cables, radio jamming, rogue devices plugged into open ports
Input validation, output encoding, parameterised queries, CSP, authentication and authorisation, web application firewalls, rate limits per endpoint
20.2 Three Attacks in Detail
ARP spoofing (layer 2). ARP has no authentication (section 5.7). So an attacker on the same local network can send unsolicited ARP replies that claim "192.168.1.1 is at MAC address". Alice's laptop updates its cache and sends all Internet traffic to the attacker. The attacker forwards it to the real router so that nobody notices. This is a classic man-in-the-middle attack, where the attacker sits secretly between the two sides. Look at what the attacker actually gets. For our TLS-protected request, it gets only encrypted records, because TLS works end to end above layer 2. However, if Alice ignored a certificate warning, the attacker could present its own certificate and read everything. Layer-2 attacks are one reason why end-to-end encryption at a higher layer is necessary. They are also a reason why users must never click away certificate warnings.
21. The Limits of the Model and a One-Page Summary
The OSI model is a reference model, which means it is an idealised picture. Real protocols break its rules in many places. A full understanding of the model includes knowing where and why.
21.1 Where Reality Breaks the Boxes
Protocols between layers: ARP and NDP connect layers 2 and 3. MPLS sits between them ("layer 2.5"). ICMP is carried in IP but serves IP.
Lower layers depend on higher ones: routing (a layer-3 function) is computed by BGP, which runs over TCP, and hosts learn their default gateway from DHCP, which runs over UDP. DNS is needed before any connection. So the stack is not a strict hierarchy of dependencies.
Layer violations for good reasons: TCP checksums include IP addresses. NAT rewrites ports. Routers clamp (lower) the TCP MSS option. Load balancers read HTTP headers. Each violation gives up clean layering to get a practical benefit.
Merged layers: the Internet merges layers 5 to 7. TLS covers layers 5 and 6. QUIC covers layers 4 to 6 and has TLS built in.
Tunnels make the stack recursive: in a VPN, an entire IP packet (layers 3 to 7) becomes the payload of another layer-4 protocol (UDP for WireGuard). That protocol is then carried in another IP packet. VXLAN puts complete Ethernet frames into UDP packets, so that data-centre networks can stretch layer 2 across layer 3. With tunnels, one packet can contain the same layer several times.
None of this makes the model wrong. It makes it what it was always meant to be: a reference for describing functions and how they relate to each other. It is not a blueprint that every implementation must copy. The real value of the model is that it gives every function a name and a position. Engineers can then say precisely what they mean.
21.2 The Seven Layers on One Page
What each layer does and how it addresses its peer:
Layer
Core question
PDU
Addressing
7 Application
What does the message mean?
Message
URLs, host names
6 Presentation
How is the data represented?
Message
–
5 Session
How is the dialogue managed?
Message
Session IDs, tickets
4 Transport
Which process, reliably or not?
22. Conclusion and Further Reading
The OSI model is more than a list to learn by heart for an exam. It is a way of thinking about systems that do something very complicated by doing many simple things in a strict order. When you follow a single request through the layers, as this article did, a few principles become clear:
Each layer talks only to its peer, through the services of the layer below. HTTP talks to HTTP, TCP to TCP, IP to IP. Only the physical layer actually transmits anything.
Encapsulation is the mechanism. Every layer adds a header that only its peer reads. Every header contains a field that tells the receiver where the payload goes next: the EtherType, the IP protocol number, the port.
Layer 2 is hop by hop; layers 3 and above are end to end. MAC addresses change at every router. IP addresses do not (except at NAT). TCP, TLS and HTTP are invisible to the network in between.
Specific layers create reliability, security and meaning. IP does not guarantee delivery; TCP does. The network does not keep secrets; TLS does. Bytes have no meaning; HTTP and JSON give them one.
Latency is round trips. DNS, TCP and TLS 1.3 each cost a round trip before the first useful byte (TLS 1.2 even costs two). Modern protocols such as TLS 1.3 and QUIC exist mainly to remove these round trips.
Troubleshoot from the bottom up. The lowest failing layer is the one to fix, and every layer has its own tools.
If you are a developer, the most practical advice is to look at your own traffic. Open the developer tools of your browser, run curl -v against your API, start Wireshark and watch your next request leave your machine. Every field described in this article is there for you to read. Once you have seen a TCP handshake, a TLS ClientHello and an HTTP request in a real capture, the seven layers will never again be just seven words.
Recommended Sources
The primary sources are free to access and easy to read:
Topic
Source
OSI reference model
ISO/IEC 7498-1:1994 and ITU-T Recommendation X.200
Internet host requirements and the TCP/IP layers
RFC 1122, RFC 1123
Ethernet and Wi-Fi
IEEE 802.3, IEEE 802.11, IEEE 802.1Q
ARP and IPv6 neighbour discovery
RFC 826, RFC 4861, RFC 4862
IPv4, IPv6 and ICMP
Written by
Maziar Farschidnia
Software and integration engineer in Cologne with a background in computer engineering — building backend systems, integration platforms, commerce and payment solutions that hold up in production.
No comments yet — be the first to share your thoughts.
· 54 min read
Caching in Distributed Systems: The Science, Architecture and Engineering of High-Performance Applications
2.2 SDU, PCI and PDU
When layer N+1 hands data to layer N, layer N calls this data a service data unit (SDU). Layer N does not interpret it; it treats it as an opaque payload (data whose content it does not look at). Layer N adds its own protocol control information (PCI). This is usually a header and sometimes a trailer. It carries the information that the peer needs: addresses, sequence numbers, lengths, checksums. The PCI plus the SDU form the protocol data unit (PDU) of layer N.
PDU(N) = PCI(N) + SDU(N) and SDU(N) = PDU(N+1)
The PDU of one layer becomes the SDU of the layer below. This simple recursion is called encapsulation. The reverse process on the receiving side is called decapsulation.
2.3 Encapsulation Visualised
The following picture shows the encapsulation of our main example from section 13: 230 bytes of HTTP request become a 322-byte Ethernet frame. The numbers are exact, and we will derive them step by step later.
L7 HTTP message [ HTTP header + JSON body ] 230 B
L6/5 TLS record [ hdr 5 ][ encrypted HTTP + type 1 ][ tag 16 ] 252 B
L4 TCP segment [ hdr 32 ][ TLS record ... ] 284 B
L3 IP packet [ hdr 20 ][ TCP segment ... ] 304 B
L2 Ethernet [ hdr 14 ][ IP packet ... ][ FCS 4 ] 322 B
L1 Signal [ preamble+SFD 8 ][ frame ... ][ gap 12 ] 342 B
hdr = header tag = authentication tag FCS = frame check sequence
gap = inter-frame gap L1 counts the bytes on the wire
Notice three things. First, most layers only add to the front (Ethernet also adds a trailer at the end) and never change the payload they were given. TLS is the exception: it encrypts its payload and appends an authentication tag. Second, the useful data (230 bytes) is about two thirds of what is transmitted (342 byte times). For small messages the overhead dominates; for large ones it shrinks to a few percent. Third, the receiving side removes the layers in exactly the reverse order. Each layer uses only its own header to decide what to do, including which upper-layer protocol should receive the payload. This last point is called demultiplexing, and each header contains a field for it:
Header
Demultiplexing field
Example value
Meaning
Ethernet
EtherType
0x0800
The payload is an IPv4 packet (0x86DD = IPv6, 0x0806 = ARP)
IPv4 / IPv6
Protocol / Next Header
6
The payload is a TCP segment (17 = UDP, 1 = ICMP)
TCP / UDP
Destination port
443
The payload belongs to the process listening on port 443
TLS record
Content type
23
The record contains application data (22 = handshake)
HTTP
Content-Type header
application/json
The body is a JSON document
2.4 Connection-Oriented and Connectionless Services
A layer can offer its service in one of two styles. A connection-oriented service has three phases: establishment, data transfer and release. The peers keep state about the connection. This state makes ordering, reliability and flow control possible. TCP is the classic example. A connectionless service sends every unit independently, without prior agreement, like a letter. IP and UDP work this way. The two styles can be stacked: TCP builds a connection-oriented, reliable service on top of IP's connectionless, unreliable one. So reliability is not a property of the network as a whole. A particular layer creates it.
2.5 Where the Layers Live
In a typical computer, the layers are implemented in different places. This explains much of their behaviour:
Libraries and applications in user space (OpenSSL, browser, curl, web server)
Application developers
QUIC (section 17) is the main exception. It implements transport functions in user space, and this is one reason why it could be deployed so quickly.
3.2 Why the OSI Model Is Still Worth Learning
If the Internet does not use OSI protocols, why learn the OSI model? Because it is the more precise language. "Layer 2" says more than "link layer", because it excludes the physical signalling. Every cloud provider uses the terms "Layer 4 load balancer" (one that decides on IP addresses and ports) and "Layer 7 load balancer" (one that reads HTTP paths and headers) in its product names. Security frameworks, network certifications and vendor documentation all use the OSI numbering. In practice, engineers describe Internet protocols with OSI layer numbers, and this article does exactly that.
3.3 Where Common Devices Operate
We usually classify a device by the highest layer whose headers it reads to make its forwarding decision. This is a helpful mental model for the journey in section 14.
Device
Highest layer it inspects
What it decides on
What it changes in transit
Repeater, hub, media converter
1
Nothing: it regenerates signals
Nothing
Switch, Wi-Fi access point (bridge)
2
Destination MAC address
Nothing (an AP translates 802.11 to Ethernet framing)
Router
3
Destination IP address (longest prefix match)
New layer-2 header, TTL (IPv6: hop limit) minus 1, IPv4 header checksum
NAT gateway (home router)
4
IP addresses and ports
Source IP and port, checksums
Stateful firewall
4
5-tuple and connection state
Nothing, or drops the packet
Layer-4 load balancer
4
IP and port
Destination IP (or encapsulates)
Reverse proxy, layer-7 load balancer, WAF
7
HTTP method, host, path, headers, body
Terminates TCP and TLS, opens a new connection to the backend
10GBASE-R, 25G, 100G
64B/66B
64 data bits plus a 2-bit sync header; only 3 % overhead
400G Ethernet
PAM4
Four amplitude levels carry 2 bits per symbol
Wi-Fi 6 (802.11ax)
OFDMA with up to 1024-QAM
Hundreds of subcarriers; each symbol carries up to 10 bits (1024 constellation points)
The difference between the symbol rate (measured in baud) and the bit rate is important. 1000BASE-T sends 125 million symbols per second on each of four pairs, and each symbol carries 2 bits of data: 125 M × 4 × 2 = 1000 Mbit/s.
4.3 The Limits of a Channel
Two classic results describe how much information a physical channel can carry. The Nyquist limit gives the maximum bit rate of a noiseless channel with bandwidth B: at most 2B symbols per second, each carrying log2(V) bits. The Shannon–Hartley theorem gives the maximum error-free bit rate of a noisy channel:
Nyquist: maxBitRate = 2 × B × log2(V) V = number of signal levels
Shannon: C = B × log2(1 + S/N) S/N = signal-to-noise ratio (linear)
Example: Wi-Fi channel, B = 80 MHz, S/N = 30 dB = 1000
C = 80e6 × log2(1001) ≈ 80e6 × 9.97 ≈ 797 Mbit/s
per spatial stream (theoretical upper bound)
This explains why a Wi-Fi connection slows down when you walk away from the access point. The signal-to-noise ratio falls, so the radio switches to a modulation with fewer bits per symbol (from 1024-QAM to 256-QAM, 64-QAM and finally BPSK), and the bit rate drops. Higher layers only notice that the data rate changes and that more frames are lost.
4.4 Topology, Duplex and Media
The physical layer also defines how devices are connected. Modern wired Ethernet is a point-to-point, full-duplex star: every device has its own cable to a switch port, and both directions send at the same time without collisions. Wi-Fi, in contrast, is a shared, half-duplex medium. All devices on a channel hear each other, only one can send successfully at a time, and the data link layer has to organise access (section 5.5).
Medium
Typical reach
Typical speed
Notes
Twisted-pair copper (Cat 6A)
100 m
1–10 Gbit/s
Cheap, powers devices via PoE, sensitive to interference
Multimode fibre
100–550 m
10–400 Gbit/s
Inside data centres and buildings
Single-mode fibre
10–80 km per span, thousands of km with amplifiers
Up to many Tbit/s per fibre (DWDM)
Backbones, undersea cables, FTTH
Wi-Fi 6/7
10–50 m indoors
Hundreds of Mbit/s to several Gbit/s
Shared medium, variable quality
5G cellular
Hundreds of metres to kilometres
Tens of Mbit/s to Gbit/s
Access is scheduled by the base station
4.5 What the Physical Layer Adds to Our Frame
Before every Ethernet frame, the physical layer sends a 7-byte preamble and a 1-byte start frame delimiter (0xD5). The preamble consists of alternating 1s and 0s, and the receiver uses it to synchronise its clock. After the frame, the line stays idle for at least 12 byte times (the inter-frame gap). These 20 bytes are not part of the frame and never reach the operating system, but they use link capacity. That is why the 322-byte frame of our example occupies 342 byte times on the cable.
The physical layer is the only layer that actually transmits anything. All the others only add information that tells their peers how to interpret what layer 1 delivers.
a6:...
5.3 The Ethernet Frame, Field by Field
This is the Ethernet II frame that carries our example request from the laptop to the home router. The byte values come from section 13.
Field Size Value in our example Purpose
---------------------------------------------------------------------------------
(Preamble) 7 B 55 55 55 55 55 55 55 Clock sync (layer 1)
(Start frame delimiter) 1 B d5 "Frame starts" (layer 1)
Destination MAC 6 B 98:9b:cb:21:7e:01 Home router's LAN port
Source MAC 6 B 3c:22:fb:4a:10:9e Laptop's network card
EtherType 2 B 08 00 Payload is IPv4
Payload 46-1500 304 B IPv4 packet The layer-3 PDU
Frame check sequence 4 B CRC-32 (header+data) Error detection
Several details are important:
The destination comes first. A switch can start forwarding the frame as soon as it has read the first six bytes (cut-through switching).
Minimum and maximum size. The payload must be at least 46 bytes (shorter payloads are padded), so that the frame is at least 64 bytes long. This minimum originally made collision detection possible on shared cables. The maximum payload of 1500 bytes is the Maximum Transmission Unit (MTU) of standard Ethernet. Data-centre networks often use 9000-byte "jumbo frames".
The FCS detects errors but does not correct them. The CRC-32 (a 32-bit cyclic redundancy check) detects all single-bit and double-bit errors and all burst errors up to 32 bits. The receiving NIC silently drops a frame with a wrong FCS. Ethernet does not retransmit it; if the data mattered, TCP will notice the gap and retransmit the whole segment later.
5.4 Switches and MAC Learning
A switch connects many devices into one local network. It forwards each frame only to the port where the destination is. It learns where devices are by watching traffic, without any configuration:
A frame arrives on port 3 with source MAC 3c:22:fb:4a:10:9e. The switch records in its MAC address table (also called CAM table): "3c:22:fb:4a:10:9e is reachable on port 3".
It looks up the destination MAC. If the table knows the port, the switch sends the frame only to that port (forwarding).
If the destination is unknown, or is the broadcast address, the switch sends the frame out of every port except the one it arrived on (flooding).
Entries expire after a period of inactivity (typically 300 seconds), so the table adapts when devices move.
A switch never changes the frame, so it is transparent: the laptop and the router do not know that it exists. Layer 2 has no TTL, so in networks with redundant links, frames could circulate forever. To prevent this, switches run the Spanning Tree Protocol (IEEE 802.1D/802.1w), which disables redundant paths until they are needed.
5.5 Wi-Fi: Layer 2 on a Shared Medium
Wi-Fi (IEEE 802.11) uses the same 48-bit MAC addresses as Ethernet, but a different frame format and a different access method:
CSMA/CA instead of full duplex. A station listens before it sends (carrier sense) and waits a random backoff time to avoid collisions (collision avoidance). It then expects an acknowledgement frame from the receiver. If the ACK does not arrive, it retransmits, up to a retry limit. Wi-Fi is therefore reliable at layer 2, unlike Ethernet, because radio loses frames far more often than copper.
Three or four addresses. An 802.11 data frame from a laptop to the Internet carries three addresses: the access point's address (receiver), the laptop's address (transmitter) and the router's address (final layer-2 destination). This is because the access point is a bridge between the radio and the wired network.
Encryption at layer 2. WPA2 and WPA3 encrypt frame payloads between the station and the access point (with AES-CCMP or GCMP). This only protects the radio link. Once the frame reaches the access point, it is decrypted, which is why end-to-end encryption with TLS is still necessary.
The access point translates every 802.11 frame into an Ethernet frame and back. The IP packet inside is passed on unchanged.
5.6 VLANs
A virtual LAN (IEEE 802.1Q) divides one physical switch infrastructure into several isolated layer-2 networks. A 4-byte tag is inserted after the source MAC address. It contains a 12-bit VLAN ID (1 to 4094) and a 3-bit priority. Frames are only forwarded within their own VLAN. Traffic between VLANs must pass through a router or a layer-3 switch, where firewall rules can apply. Home routers use VLANs internally to separate the guest network from the main network, and ISPs often deliver the Internet connection on a specific VLAN.
5.7 ARP: The Bridge Between Layer 3 and Layer 2
The laptop wants to send an IP packet to the router at 192.168.1.1, but an Ethernet frame needs a MAC address. The Address Resolution Protocol (ARP, RFC 826) finds it. ARP is a helper protocol between layer 2 and layer 3. It is carried directly in Ethernet frames with EtherType 0x0806.
The laptop checks its ARP cache (its local table of known IP-to-MAC mappings). If there is no entry for 192.168.1.1, it broadcasts an ARP request: "Who has 192.168.1.1? Tell 192.168.1.23".
Every device on the network receives the broadcast. Only the device that owns 192.168.1.1 answers, with a unicast ARP reply: "192.168.1.1 is at 98:9b:cb:21:7e:01".
The laptop stores the mapping in its cache (typically for a few minutes) and can now build the frame.
This is the exact 28-byte ARP request that the laptop sends, inside a broadcast Ethernet frame (destination ff:ff:ff:ff:ff:ff, EtherType 08 06):
ARP has no authentication: any device can answer, and the cache accepts the answer. Section 20 shows how this makes ARP spoofing possible. IPv6 replaces ARP with the Neighbor Discovery Protocol (section 18).
192.0.2.0/24
198.51.100.0/24
203.0.113.0/24
6.2 The IPv4 Header, Field by Field
This is the exact 20-byte IPv4 header of our request packet as it leaves the laptop:
Each router decrements it; the packet is discarded at 0
06
Protocol
6
The payload is TCP
df c3
Header checksum
0xdfc3
One's-complement sum over the header only
c0 a8 01 17
Source address
192.168.1.23
The laptop
cb 00 71 0a
Destination address
203.0.113.10
The web server
Three fields change in transit, and it is useful to know why. Every router decrements the TTL, so a packet caught in a routing loop dies after at most 255 hops. The router that discards it sends an ICMP "Time Exceeded" message back, and traceroute uses this (section 19). Because the TTL changes, the header checksum must be recomputed at every hop. The checksum only protects the header, because the payload has its own checksums at layer 4. Finally, the home router's NAT changes the source address (section 6.6).
6.3 Routing: How a Router Decides
Every router has a routing table: a list of destination prefixes, each with a next hop and an outgoing interface. For every packet, the router selects the entry with the longest matching prefix, because a longer prefix is a more specific route. A simplified table of an ISP edge router:
Destination prefix
Next hop
Interface
Learned from
0.0.0.0/0
192.0.2.1
uplink-1
Static default route
203.0.113.0/24
192.0.2.9
uplink-2
BGP
203.0.113.0/26
192.0.2.17
uplink-3
BGP
198.51.100.0/24
directly connected
customer-access
Connected
For destination 203.0.113.10, three entries match: /0, /24 and /26 (because 10 is in the range 0 to 63). The /26 wins, and the packet leaves through uplink-3 towards 192.0.2.17. Real backbone routers hold more than one million IPv4 routes. They do this lookup in specialised hardware (TCAM, a special memory that searches all entries at once) in a few nanoseconds per packet.
Routing protocols fill the routing tables. Inside an organisation, interior gateway protocols such as OSPF or IS-IS compute shortest paths over the known topology. The Internet consists of more than 75,000 independent networks, called autonomous systems; each has a number, such as AS15169 for Google. Between them, the Border Gateway Protocol (BGP) exchanges reachability information and applies business policies: who pays whom for transit, and which paths are preferred. Note a subtle point about layering: BGP runs over TCP port 179, so a "layer-3 function" is implemented by a protocol that uses layer 4. The OSI layers describe functions, not a strict dependency graph.
6.4 Fragmentation and Path MTU Discovery
Sometimes a router must forward a packet onto a link whose MTU is smaller than the packet. There are two possibilities. If the DF flag is not set, IPv4 allows the router to fragment the packet into smaller pieces. The fragments share the same Identification value, and only the destination host reassembles them. Fragmentation is inefficient (losing one fragment loses the whole packet) and causes security problems. Modern hosts therefore set DF = 1 and use Path MTU Discovery. If a packet is too big, the router drops it and returns an ICMP "Fragmentation Needed" message that states the MTU of the next link, and the sender reduces its packet size. IPv6 does not allow routers to fragment packets at all. Section 16 shows what happens when firewalls block these ICMP messages.
6.5 ICMP: The Network's Error Channel
The Internet Control Message Protocol (ICMP, RFC 792; ICMPv6, RFC 4443) carries error and diagnostic messages for IP. It is carried inside IP (protocol number 1), but it is considered part of layer 3. The most important message types:
Type
Name
Sent when
0 / 8
Echo reply / echo request
ping
3
Destination unreachable
No route, port closed (for UDP), fragmentation needed (code 4)
11
Time exceeded
TTL reached 0 (traceroute)
5
Redirect
A better first-hop router exists on the same subnet
6.6 NAT: Why Your Laptop Does Not Have a Public Address
IPv4 has only about 4.3 billion addresses, far fewer than the number of connected devices. Network Address Translation (NAT, more precisely NAPT or port address translation) lets a whole home network share one public address. The home router rewrites outgoing packets and stores the mapping in a translation table:
When the reply for 198.51.100.77:40112 arrives, the router looks up the entry and rewrites the destination back to 192.168.1.23:51544. NAT clearly breaks the clean layering. A "layer-3 device" must read and change layer-4 port numbers. It must also recompute the TCP checksum, which covers the IP addresses through a pseudo-header (section 7). NAT also means that a server on the Internet cannot open a connection to a device behind NAT. Many people mistake this side effect for a firewall.
6.7 IPv6
IPv6 solves the address shortage with 128-bit addresses. They are written as eight groups of four hexadecimal digits, with runs of zeros compressed: 2001:db8:4a2b:10::23. A typical home network gets a /56 or /64 prefix from the ISP. Every device has a globally routable address, so NAT is not needed. The IPv6 header is simpler and has a fixed size of 40 bytes:
Field
Size
IPv4 counterpart
Version (6)
4 bits
Version
Traffic class
8 bits
DSCP/ECN
Flow label
20 bits
(none) – identifies packets of one flow for load balancing
Payload length
16 bits
Total length (minus the header)
Next header
8 bits
Protocol
Hop limit
8 bits
TTL
Source and destination address
128 bits each
32 bits each
IPv6 has no header checksum, because layer 2 and layer 4 already check for errors. It has no fragmentation fields, because only the sender fragments, using an extension header. Options are moved to optional extension headers, which are chained via the Next Header field. Address resolution uses ICMPv6 Neighbor Discovery instead of ARP. Hosts can also configure their own addresses from the router's advertisements (SLAAC, section 18).
7.3 TCP: Reliable Byte Streams
The Transmission Control Protocol (RFC 9293, which consolidated the original RFC 793 of 1981) provides a byte stream that is connection-oriented, reliable, ordered and full-duplex (data flows in both directions at once). It also provides flow control and congestion control. "Byte stream" is an important detail: TCP does not keep message boundaries. If the application writes 230 bytes and then 100 bytes, the receiver may read them as one 330-byte block or as three pieces. Application protocols must therefore define their own message boundaries. HTTP/1.1 does this with the Content-Length header, as our example will show.
7.4 The TCP Header, Field by Field
This is the 32-byte TCP header of our request segment. The checksum is shown as zero here, because it is computed over the encrypted payload, which we cannot show:
ACK field is valid; pass the data to the application without delay
08 0a
Window
2058
Receive window, multiplied by 2 to the power of the scale factor agreed in the handshake
00 00
Checksum
computed
Over a pseudo-header (IP addresses, protocol, length), the TCP header and the payload
00 00
Urgent pointer
0
Unused
01 01
Options: NOP, NOP
Padding to align the next option
08 0a ...
Option: timestamps
TSval 1843202117, TSecr 3710455022
RTT measurement and protection against wrapped sequence numbers
You should learn the six classic flags: SYN (synchronise sequence numbers, opens a connection), ACK (acknowledgement field is valid), PSH (push), FIN (sender has finished sending), RST (reset: stop the connection immediately) and URG (urgent data, almost never used). Two more flags, ECE and CWR, are used for Explicit Congestion Notification.
The pseudo-header in the checksum breaks strict layering. TCP includes the IP source and destination addresses in its checksum, so that it can detect a segment delivered to the wrong host. The cost is that every NAT device that rewrites an IP address must also update the TCP checksum.
7.5 The Three-Way Handshake
Before any data flows, the two TCP entities synchronise their initial sequence numbers (ISNs). The ISNs are chosen randomly for two reasons. First, this avoids confusion with segments of an earlier connection on the same 5-tuple. Second, it makes it hard for attackers to inject forged segments.
The SYN uses up one sequence number, so the server acknowledges ISN + 1. The options agreed here affect the whole connection:
MSS (Maximum Segment Size): the largest payload the receiver wants in one segment. On Ethernet it is 1460 bytes: 1500 bytes MTU minus 20 bytes IP header minus 20 bytes TCP header. With the 12-byte timestamp option, the actual payload per segment is 1448 bytes.
Window scale: the 16-bit window field allows at most 65,535 bytes in flight. This is far too little for fast long-distance links. The scale option multiplies the window by 2 to the power of the scale factor. Each side announces the factor for the windows that it will advertise itself. Our client announced 9, so its window value 2058 means 2058 × 512 = 1,053,696 bytes. The server announced 7.
SACK permitted: allows selective acknowledgements. After a loss, the receiver can report exactly which blocks it has received.
Timestamps: allow precise measurement of the round-trip time (RTT).
The handshake costs one full round trip before the client can send the first byte of data. On a connection from Europe to the US east coast, the RTT is about 90 ms. That is 90 ms of pure waiting. This is why TCP Fast Open, TLS 1.3 and QUIC all try hard to save round trips.
7.6 Reliability: Sequence Numbers, Acknowledgements and Retransmission
TCP numbers every byte, not every segment. The sequence number of a segment is the number of its first payload byte. The acknowledgement number tells the peer "I have received everything up to this byte, but not including it". Acknowledgements are cumulative: one acknowledgement confirms all earlier bytes. The sender keeps every unacknowledged byte in a retransmission buffer. It sends the bytes again in two cases:
The retransmission timeout (RTO) expires. The RTO is computed from the smoothed RTT and its variance (RFC 6298). In Linux it is at least 200 ms.
The sender receives three duplicate ACKs. This means the receiver keeps acknowledging the same byte because a segment in between is missing. The sender then performs a fast retransmit and does not wait for the timeout.
The receiver uses the sequence numbers to put segments back in order and to discard duplicates. As a result, the application always reads a perfect copy of the stream. Section 16 follows a lost segment through this process with concrete numbers.
7.7 Flow Control and Congestion Control
TCP controls its sending rate for two different reasons. Mixing up these two reasons is a classic mistake.
Flow control protects the receiver. In every segment, the receiver advertises how many bytes of free buffer space it has (the receive window, rwnd). The sender never has more unacknowledged bytes in flight than this value. If the receiving application is slow, the window shrinks to zero and the sender pauses.
Congestion control protects the network. The sender keeps a second limit, the congestion window (cwnd). It estimates how much data the path can carry without overflowing the queues in the routers. The amount of data in flight is the smaller of the two windows. Classic congestion control (Reno, RFC 5681) works like this:
Slow start: a new connection starts with an initial window of 10 segments (about 14 KB, RFC 6928). It doubles cwnd every round trip, as long as no loss occurs.
Congestion avoidance: above the slow-start threshold, cwnd grows by only one segment per round trip (additive increase).
Reaction to loss: TCP treats a loss as a sign of congestion. After a fast retransmit it halves cwnd (multiplicative decrease); after a retransmission timeout it starts again from one segment with slow start.
Linux uses CUBIC by default. CUBIC grows the window as a cubic function of the time since the last loss, and it works better on fast long-distance links. Google's BBR uses a different approach. Instead of reacting to loss, it builds a model of the path's bottleneck bandwidth and minimum RTT. The ideal amount of data in flight is the bandwidth-delay product (BDP):
BDP = bandwidth × RTT
= 100 Mbit/s × 30 ms = 3,000,000 bit = 375,000 bytes
≈ 259 full segments of 1448 bytes
If the window is smaller than the BDP, the link is never fully used, no matter how fast it is. This is why window scaling matters. It is also why a single TCP connection across an ocean often cannot fill a gigabit link.
7.8 Closing a Connection
TCP closes a connection in each direction separately. The side that finishes first sends FIN. The other side acknowledges it and can continue sending until it sends its own FIN. The side that sent the first FIN then waits in the TIME_WAIT state for twice the maximum segment lifetime (2 × MSL; Linux uses a fixed 60 seconds in total). This ensures that delayed segments of the old connection are not mistaken for a new connection on the same 5-tuple. An RST stops a connection immediately. A host sends it, for example, when a segment arrives for a port where no process is listening.
In our main example, two things do the session-layer work. The first is the TLS handshake of section 12, which authenticates the server and establishes keys. The second is the decision of the browser or client to reuse the established connection for further requests (HTTP keep-alive). If the client returns before its session ticket expires, it can resume the TLS session. It can even send data in its first flight of messages (0-RTT). This is the session layer's "continue from checkpoint" idea applied to cryptography.
Content-Encoding
Compression applied to the body
br (Brotli), gzip, zstd
Accept, Accept-Encoding, Accept-Language
Negotiation of acceptable representations
Accept-Encoding: gzip, br
Transfer-Encoding
How the body is framed in transit (HTTP/1.1 only)
chunked
9.3 Byte Order
Network protocols send multi-byte integers in big-endian order ("network byte order"): the most significant byte comes first. That is why port 443 appears in the TCP header as 01 bb (1 × 256 + 187 = 443). Most processors (x86, and ARM in its usual mode) are little-endian and store the same number in memory as bb 01. The functions htons and ntohs ("host to network short" and back) exist for exactly this reason: they perform this presentation-layer translation in every networking program.
POST
Request target (/api/posts/42/comments): the resource, as a path with an optional query.
Host header: required in HTTP/1.1. It allows one IP address to host many websites (virtual hosting). Note that information is repeated across layers here. The server's IP address is in the IP header, but the name that the client asked for is only in the Host header and in the TLS SNI extension (section 12).
Content-Type and Content-Length: the presentation information (JSON) and the framing information (63 bytes). TCP is a byte stream without boundaries, so the server needs Content-Length (or, alternatively, chunked transfer coding) to know where this request ends and the next one begins.
10.2 The Response
The server answers with a status line, header fields and an optional body. Our example response is 238 bytes (177 bytes of header, 61 bytes of body):
HTTP/1.1 201 Created
Date: Tue, 01 Dec 2026 09:30:12 GMT
Content-Type: application/json
Content-Length: 61
Location: /api/posts/42/comments/1337
Cache-Control: no-store
{"id":1337,"postId":42,"author":"Alice","status":"published"}
The status code classes form a short language of their own: 1xx informational, 2xx success (200 OK, 201 Created, 204 No Content), 3xx redirection (301, 304 Not Modified), 4xx client error (400, 401, 403, 404, 429 Too Many Requests) and 5xx server error (500, 502 Bad Gateway, 503, 504 Gateway Timeout). From a layering point of view, 502 and 504 are special. A proxy in the middle generates them, and they mean "I am fine, but the connection to the server behind me failed". In other words, a layer-4 or layer-7 failure on the next hop is reported as a layer-7 status.
10.3 HTTP Versions and Their Layering
Version
Transport
Framing
Key property
HTTP/1.1 (1997, RFC 9112)
TCP (+ TLS)
Text, one request at a time per connection
Simple; head-of-line blocking per connection, so browsers open up to 6 connections per host
HTTP/2 (2015, RFC 9113)
TCP + TLS
Binary frames, many streams multiplexed on one connection, HPACK header compression
One connection per host; TCP still blocks all streams when a packet is lost
HTTP/3 (2022, RFC 9114)
QUIC over UDP
Binary frames on independent QUIC streams, QPACK
No head-of-line blocking at transport level; faster handshakes
The semantics (methods, status codes, headers) are the same in all three versions. Only the representation on the wire changes. This is exactly the separation of concerns that the layered model promises. RFC 9110 defines the layer-7 semantics once, and each version defines a different mapping to the layers below. Our main example uses HTTP/1.1 because its text format makes every byte visible. Section 17 shows the same request over HTTP/3.
10.4 Other Application-Layer Protocols
Protocol
Transport and port
Purpose
DNS
UDP and TCP 53; DoT 853; DoH 443
Name resolution (section 11)
SMTP
TCP 25, 587
Sending and relaying e-mail
IMAP
TCP 993 (TLS)
Reading e-mail stored on a server
SSH
TCP 22
Encrypted remote shell, file transfer, tunnelling
MQTT
TCP 1883, 8883 (TLS)
Lightweight publish/subscribe for IoT
NTP
UDP 123
Clock synchronisation
DHCP
UDP 67, 68
Automatic IP configuration of hosts
DHCP needs a short comment, because it answers a question that the main example takes for granted. Where did the laptop get 192.168.1.23, the subnet mask, the default gateway and the address of the DNS server? It got them from a DHCP server (usually the home router), through a four-message exchange: DISCOVER, OFFER, REQUEST, ACK. These messages are broadcast on the local network, before the laptop even has an IP address. DHCP is an application-layer protocol whose only purpose is to configure layer 3.
198.51.100.53
Recursive resolution. If the recursive resolver has no cached answer, it walks down the name hierarchy. First it asks one of the 13 root server names for blog.example.com (each name is really many anycast instances in different places). The root answers with a referral: a pointer to the servers responsible for .com. The .comTLD servers (top-level domain servers) then refer it to the authoritative servers of example.com. These finally answer with the A record.
Caching. Every answer carries a TTL (time to live) in seconds. The recursive resolver and the stub keep the answer in their caches for that long. So the next lookup for the same name takes microseconds instead of tens of milliseconds.
Laptop ─(1)─> Resolver ─(2)─> Root server "ask the .com servers"
─(3)─> .com TLD server "ask ns1.example.com"
─(4)─> example.com NS "203.0.113.10, TTL 3600"
Laptop <─(5)─ Resolver
Resolver = the home router, which forwards to the ISP's recursive resolver
11.2 The DNS Query, Byte by Byte
The query is a 34-byte DNS message. It travels inside a UDP datagram (8-byte header, so the UDP length is 42), which travels inside an IPv4 packet (62 bytes in total). It goes from a random source port to destination port 53:
A query has no answer, authority or additional records
04 62 6c 6f 67
Label
Length 4, "blog"
07 65 78 61 6d 70 6c 65
Label
Length 7, "example"
03 63 6f 6d 00
Label, end
Length 3, "com", then the root label (length 0)
00 01
QTYPE
A (IPv4 address); a modern client also asks for AAAA (IPv6) at the same time
00 01
QCLASS
IN (Internet)
This is a presentation-layer detail: DNS does not send the dots. It encodes a name as a sequence of labels, and each label starts with its length. This format was defined in 1987 and is still used without change.
11.3 The Answer
The 50-byte answer repeats the question and adds one resource record:
The flags 81 80 mean: response (QR = 1), recursion desired and recursion available, no error (RCODE 0). The answer record starts with c0 0c, a compression pointer. The two top bits 11 mark it as a pointer. The remaining bits point to offset 12, where the name blog.example.com already appears in the question, so the name is not repeated. Next come type A (00 01), class IN (00 01), TTL 3600 seconds (00 00 0e 10), data length 4 (00 04) and the address cb 00 71 0a = 203.0.113.10.
11.4 DNS and the Layers
DNS shows that the layers do not run just once from top to bottom. To send a layer-7 HTTP request, the client first runs a complete, separate layer-7 exchange (DNS). This exchange itself goes through layers 4 (UDP), 3 (IP), 2 (Ethernet, possibly with ARP first) and 1. More and more modern clients send DNS through encrypted channels: DNS over TLS (port 853) or DNS over HTTPS (port 443). These protect the query from eavesdroppers on the local network and from the ISP. In that case a DNS lookup is itself an HTTPS request, carried by TCP or QUIC, and it needs its own handshake. The layers nest inside each other again and again.
Typical timing: 0 ms for a cached name, 1–5 ms if the home router has it cached, 10–30 ms for the ISP resolver's cache, up to 100–200 ms for a full uncached resolution across the hierarchy.
What each element does:
Random values from both sides make every handshake unique. They prevent an attacker from replaying old handshakes.
Key share (ECDHE): the client sends an ephemeral (short-lived, single-use) public key on the X25519 elliptic curve and keeps the private key. The server does the same. Each side combines its own private key with the other side's public key and gets the same shared secret. An eavesdropper cannot compute this secret. The keys are ephemeral and are thrown away after the handshake. So if someone records the traffic today and steals the server's private key next year, they still learn nothing. This property is called forward secrecy. More and more clients also add a post-quantum hybrid key share (X25519MLKEM768) to protect against future quantum computers.
SNI (Server Name Indication): the host name in clear text. A server that hosts many sites uses it to choose the right certificate. Any observer on the path can see SNI, which is why Encrypted Client Hello (ECH) is now being deployed.
ALPN (Application-Layer Protocol Negotiation): client and server agree on the layer-7 protocol (h2, http/1.1) inside the TLS handshake, which saves a round trip. Here the session/presentation layer negotiates the application protocol, a good example of layers working together.
Certificate and CertificateVerify: the server proves its identity. The certificate binds the public key to the name blog.example.com, and a certificate authority (CA) has signed it. CertificateVerify is a signature with the server's private key over the whole handshake transcript (all handshake messages so far). It proves two things: the server has the private key that belongs to the certificate, and nobody changed the negotiation.
Finished: a MAC (message authentication code) over the complete transcript, with keys derived from the shared secret. Suppose an attacker changed any message, for example removed a strong cipher suite to force a weak one. Then the Finished values would not match.
12.3 Certificate Validation
Before the client sends its Finished message, it validates the certificate chain. It checks that:
The certificate's subject alternative name includes blog.example.com.
The certificate is within its validity period. Under the CA/Browser Forum rules, publicly trusted certificates may be valid for at most 200 days since March 2026, 100 days from March 2027 and 47 days from March 2029.
Each certificate in the chain is signed by the next one, and the chain ends at a root certificate in the client's trust store.
The certificate has not been revoked (checked via OCSP or CRLs, though clients handle this inconsistently).
The key usage allows TLS server authentication.
If any check fails, curl stops with an error such as "SSL certificate problem: unable to get local issuer certificate", and it never sends a single HTTP byte. This is a layer-5/6 failure. The troubleshooting section shows how to diagnose it with openssl s_client.
12.4 Key Derivation
TLS 1.3 derives all keys from the shared secret with HKDF (HMAC-based key derivation), following a fixed schedule. First comes an early secret, then a handshake secret (used to encrypt the server's certificate and the Finished messages), and then a master secret. From the master secret, TLS derives separate application traffic keys for each direction. Each direction has its own key and its own 64-bit record sequence number, which becomes part of the nonce (a number used only once per key). Because of this, nobody can reorder records, replay them or move them from one direction to the other without being detected.
12.5 The Cost in Round Trips
Step
Round trips before the first HTTP byte
Example time at 30 ms RTT
DNS (uncached at the ISP resolver)
1
30 ms + resolver time
TCP handshake
1
30 ms
TLS 1.3 handshake
1
30 ms
TLS 1.2 handshake (for comparison)
2
60 ms
HTTP request and response
1
30 ms + server time
Total for a new connection with TLS 1.3
3 (+ DNS)
about 90–120 ms
TLS 1.3 also offers 0-RTT resumption. A client that has a session ticket from an earlier connection can send its HTTP request in the first flight, together with the ClientHello. The downside is that an attacker can replay 0-RTT data. So servers should accept only idempotent requests (like GET) this way. Our POST would never be sent as 0-RTT data.
2918734105
Acknowledgement number: the next byte expected from the server. After its SYN (ISN 1064549700), the server has sent 2690 bytes of handshake data. So the ACK is 1064549700 + 1 + 2690 = 1064552391.
Windows: the advertised receive window (2058 × 512 bytes) tells the server how much it may send. The congestion window allows sending at once, because almost nothing is in flight.
Flags: ACK (always set after the handshake) and PSH (deliver to the application without waiting for more data).
Checksum: computed over the pseudo-header, the header and the payload. Most network cards compute it in hardware (checksum offload). This is why packet captures on the sending machine often show "incorrect checksum": the capture sees the packet before the card fills in the checksum.
Retransmission timer: started, in case the segment is lost.
The result is a 284-byte segment: 32 bytes of header (shown in section 7.4) and 252 bytes of TLS record. TCP passes it to IP together with the destination address.
13.4 Layer 3: The IP Packet
The IP layer receives the segment and the destination 203.0.113.10. Its decisions:
Route lookup. The laptop's routing table has two entries: 192.168.1.0/24, directly connected on en0, and the default route 0.0.0.0/0 via 192.168.1.1. The destination is not in the local network (see the AND computation in section 6.1), so the default route wins: the next hop is 192.168.1.1.
Source address selection. The packet leaves through en0, whose address is 192.168.1.23.
MTU check. 304 bytes is below the interface MTU of 1500, so fragmentation is not needed. DF (Don't Fragment) is set because the host uses Path MTU Discovery.
Header construction. TTL 64 (the default on Linux and macOS; Windows uses 128), protocol 6, identification 23610, total length 304 and the header checksum df c3.
You can check the checksum by hand. Doing it once makes "the internet checksum" easy to understand: set the checksum field to zero, add all 16-bit words of the header using one's-complement addition, and invert the result.
The packet's IP destination is the server, but the laptop must hand it to the router. That is the job of layer 2.
13.5 Layer 2: The Ethernet Frame
The IP layer passes the packet and the next-hop address 192.168.1.1 to the Ethernet driver. The driver needs the router's MAC address and finds it in the ARP cache. (If the entry had expired, the ARP exchange of section 5.7 would happen first, and the packet would wait a few milliseconds.) The driver builds the header:
0000 98 9b cb 21 7e 01 3c 22 fb 4a 10 9e 08 00
└─ destination ──┘ └──── source ───┘ └type┘
router MAC laptop MAC IPv4
The NIC adds the 4-byte CRC-32 frame check sequence at the end, also in hardware. The frame is now 14 + 304 + 4 = 322 bytes.
13.6 Layer 1: The Signal
The NIC's PHY (the physical-layer chip) first sends the 8-byte preamble and start frame delimiter. Then it sends the 322 bytes of the frame, scrambled and encoded for 1000BASE-T as five-level symbols on all four copper pairs. After that it stays quiet for the 12-byte inter-frame gap. At 1 Gbit/s, the 342 byte times take 342 × 8 ns = 2.7 microseconds. The electrical signal travels along the cable at about two thirds of the speed of light, roughly 5 nanoseconds per metre.
13.7 The Complete Picture at the Sender
bytes
L7 HTTP request 230 POST /api/posts/42/comments + JSON body
L6 TLS: + inner type 1 + tag 16 247 encrypted, authenticated
L5 TLS record header 5 252 17 03 03 00 f7 ...
L4 TCP header 32 284 51544 -> 443, PSH ACK,
seq 2918734105, ack 1064552391
L3 IPv4 header 20 304 192.168.1.23 -> 203.0.113.10,
TTL 64, proto 6, DF
L2 Ethernet header 14 + FCS 4 322 3c:22:fb:4a:10:9e -> 98:9b:cb:21:7e:01,
type 0x0800
L1 preamble/SFD 8 + gap 12 342 2.7 µs at 1 Gbit/s
Useful data (JSON body): 63 bytes = 18 % of the bytes on the wire
Whole HTTP message: 230 bytes = 67 % of the bytes on the wire
The ratio improves quickly for larger messages. A full-sized segment carries 1448 bytes of payload in 1538 byte times on the wire, an efficiency of 94 %.
GPON
The packet that leaves the home router differs from the one that left the laptop in exactly five fields: TTL, source address, source port, IP checksum and TCP checksum. The TLS record, and with it the HTTP request, is bit-for-bit identical.
Laptop -> router Router -> ISP
Source MAC 3c:22:fb:4a:10:9e router WAN MAC (new)
Destination MAC 98:9b:cb:21:7e:01 ISP access router MAC (new)
TTL 64 63
Source IP:port 192.168.1.23:51544 198.51.100.77:40112 (NAT)
Destination IP:port 203.0.113.10:443 203.0.113.10:443
IP checksum df c3 78 02
TLS record + HTTP 252 bytes same 252 bytes
MSS clamping: PPPoE reduces the MTU to 1492, so home routers usually rewrite the MSS (Maximum Segment Size) option in SYN packets that pass through them, from 1460 to 1452. This is another layer violation: a router changes a TCP option. It does this to prevent the MTU problems described in section 16.
14.3 Hops 2 to 4: The ISP
The packet reaches the ISP's broadband network gateway (BNG). The BNG terminates the subscriber's PPPoE session, removes that framing and routes the packet into the ISP's core. Large ISP cores often use MPLS (Multiprotocol Label Switching). The ingress router (the router where the packet enters the core) pushes a 4-byte label between the layer-2 header and the IP header. The core routers then forward the packet based on that label instead of doing a full IP lookup. MPLS sits between layer 2 and layer 3, so people informally call it "layer 2.5". This is another sign that real networks do not follow the seven boxes exactly. At the egress of the core (where the packet leaves it), the router removes the label.
Each of these routers repeats the same cycle: receive the frame, check it, strip the layer-2 header, decrement the TTL, recompute the IP checksum, look up the longest matching prefix, build a new frame for the outgoing link, and transmit. The links between them are usually 100 or 400 Gbit/s Ethernet over fibre. So the layer-2 framing is Ethernet again, but with the MAC addresses of the two routers on each link.
14.4 Hops 5 to 8: Between Networks
The ISP's border routers have learned via BGP (Border Gateway Protocol, the routing protocol between networks) which neighbouring network offers the best path to 203.0.113.0/24. The packet may cross an Internet exchange point (IXP). An IXP is a large layer-2 switching fabric where hundreds of networks connect their routers to exchange traffic directly (peering). Or the ISP may hand the packet to a transit provider, which carries it further for a fee. Every network on the way makes its own routing decision based on its own BGP policy. This is why the path to a server and the path back from it are often different (asymmetric routing).
14.5 Hops 9 to 12: The Data Centre
The packet arrives at the edge routers of the hosting provider. It passes a firewall that only allows ports 80 and 443 to this server. The data-centre fabric then switches it to the top-of-rack switch and finally to the server's network card. This fabric is usually a leaf-spine architecture of layer-3 switches. In larger installations, a layer-4 load balancer chooses one of many servers based on the 5-tuple (protocol, source and destination address, source and destination port). Alternatively, a layer-7 reverse proxy terminates the TLS connection, reads the HTTP request and opens a separate connection to an application server. To keep things clear, our server terminates TLS itself.
After twelve routers, the packet arrives with TTL 52 and IP checksum 83 02.
14.6 What Changes and What Does Not
Field
Laptop
Home router (NAT)
Each ISP and transit router
Arrival at server
Layer 1 signal and coding
1000BASE-T copper
DSL/fibre/cable
Optical, 100–400G
25G or 100G fibre/DAC
Layer 2 source and destination MAC
Laptop → router
New on every link
New on every link
Switch → server NIC
Layer 2 framing
Ethernet
PPPoE / DOCSIS / GPON
Ethernet (+ MPLS label)
Ethernet
IP TTL
64
63
Minus 1 per router
52
IP source
192.168.1.23
198.51.100.77
Unchanged
198.51.100.77
IP destination
203.0.113.10
Unchanged
Unchanged
203.0.113.10
TCP ports
51544 → 443
40112 → 443
Unchanged
40112 → 443
TCP sequence numbers
2918734105
Unchanged
Unchanged
2918734105
TLS record (encrypted HTTP)
252 bytes
Unchanged
Unchanged
Unchanged
This table shows what the layered model means in practice. Layer 2 is hop by hop. Layer 3 is end to end, but its addresses may be translated. Layers 4 to 7 are end to end. A router in Frankfurt or Ashburn neither knows nor cares that it is carrying a blog comment.
14.7 How Long the Journey Takes
The time a packet needs to cross the network has four parts, and each belongs to a specific layer or device:
delay = propagation + transmission + queuing + processing
propagation = distance / signal speed
1000 km of fibre ≈ 5 ms (light in glass: ~200,000 km/s)
transmission = frame size / link rate
342 bytes at 1 Gbit/s = 2.7 µs; at 10 Mbit/s = 274 µs
queuing = time waiting in router buffers
0 ms on an idle path, up to hundreds of ms ("bufferbloat")
processing = header checks, lookup
microseconds in hardware routers
For a server 1500 km away, the round-trip time (RTT) is therefore at least about 15 ms from propagation alone. In practice it is 20–30 ms, because fibre paths are not straight lines. No protocol optimisation can beat the speed of light. This is why content delivery networks place servers close to users: they reduce the one part of latency that engineering cannot otherwise change.
17 03 03 00 f7
17
15.5 Layer 7 on the Server
The HTTP parser reads the request line and the header fields up to the empty line. The Host header selects the virtual host blog.example.com, and the path /api/posts/42/comments matches a proxy location. Content-Length: 63 tells the parser to read exactly 63 more bytes as the body. The server passes the request to the application. The application performs a sequence of steps. In the OSI model they all belong to layer 7, but in software architecture they form an entire world of their own:
Presentation: parse the body as JSON in UTF-8 into an object {author: "Alice", text: "Great explanation of the OSI model!"}.
Validation: check required fields and lengths, and reject markup to prevent stored XSS (cross-site scripting).
Authorisation and abuse protection: rate limits, spam checks.
Business logic: store the comment in the database. This is another network conversation, to a database server, through all the layers again.
Response: build the 201 Created response with a Location header and a JSON body.
15.6 The Response Travels Back
The 238-byte response from section 10.2 takes the same path down the server's stack. It becomes a TLS record of 5 + 238 + 1 + 16 = 260 bytes. This goes into a TCP segment from port 443 to port 40112, which also acknowledges the request (ACK 2918734357). The segment goes into an IP packet from 203.0.113.10 to 198.51.100.77, and the packet into a new Ethernet frame for the first hop. Routers forward it back, possibly along a different path. At the home router, the NAT entry translates the destination back to 192.168.1.23:51544. The router uses ARP (or its ARP cache) to address the final frame to the laptop's MAC address.
On the laptop, the layers decapsulate again. TCP delivers the bytes to the socket of curl, and the TLS library decrypts them. curl parses the response and prints the body:
Assume an RTT of 30 ms to the server and a cold start (no cached DNS answer, no existing connection). From the laptop's point of view, the whole exchange then looks like this. curl -w can print these exact phases for any request.
Time
Event
Layer(s)
0 ms
DNS query sent to the router
7 (DNS), 4 (UDP), 3, 2 (possibly ARP first), 1
24 ms
DNS answer: 203.0.113.10 (resolver had it cached)
7
24 ms
TCP SYN sent
4
54 ms
SYN-ACK received, ACK sent: connection established
Response received (30 ms RTT + 9 ms server processing incl. database)
7
125 ms
curl prints the body
7
Three of the four round trips are used to set up the conversation (DNS, TCP, TLS). Only one carries the actual request. This is the most important performance lesson of the layered model: for small requests, round trips, not bandwidth, decide the latency. Connection reuse (keep-alive), TLS session resumption, DNS caching and protocols with fewer round trips (QUIC) all target exactly this problem.
15.8 Ending the Conversation
curl has nothing more to send. It sends a TLS close_notify alert, an encrypted record that says "I will send no more data". The kernel then closes the TCP connection with FIN segments, as shown in section 7.8. The laptop's socket stays in the TIME_WAIT state for 60 seconds. The home router keeps the NAT entry for a short time and then deletes it. A browser would behave differently: it would keep the connection open for further requests to the same host and save two round trips (TCP and TLS handshakes) on each of them; DNS caching saves the third.
70
101 KB
4
80
80
150
217 KB
5
160
160
310
449 KB
6
320
320
630
912 KB
7
640
62 (rest)
692
1,000 KB
The transfer needs 7 round trips: about 210 ms at 30 ms RTT. On a 100 Mbit/s link, the pure transmission time of 1 MB is only 80 ms. For files of this size, slow start and RTT limit the throughput, not the bandwidth. The link becomes the limit only for much larger transfers, when the window reaches the bandwidth-delay product (BDP). The BDP is 259 segments at 100 Mbit/s and 30 ms (see section 7.7). In fact, from round trip 6 on, the window of 320 segments is already larger than the BDP. The extra packets wait in the queue of the bottleneck router, which adds delay.
16.3 A Lost Segment
During round trip 5, the queue of the bottleneck router overflows and drops one segment, number 200. Its payload covers bytes 288,153 to 289,600 of the stream (relative sequence numbers; segment n starts at (n − 1) × 1448 + 1). What happens next shows the transport layer at its best:
Server sends seg 199 (bytes 286705-288152)
seg 200 (bytes 288153-289600) LOST
seg 201 ... seg 204
Client acks ACK 288153 (nothing for seg 200)
seg 201 arrives: ACK 288153, SACK 289601-291048 duplicate ACK 1
seg 202 arrives: ACK 288153, SACK 289601-292496 duplicate ACK 2
seg 203 arrives: ACK 288153, SACK 289601-293944 duplicate ACK 3
Server 3 duplicate ACKs -> fast retransmit of seg 200 (bytes 288153-289600)
congestion window reduced (CUBIC: × 0.7; Reno: × 0.5)
Client seg 200 arrives: ACK jumps to 295393
(everything up to seg 204 is now complete)
The receiver keeps acknowledging the first missing byte, 288,153. At the same time, it uses SACK (Selective Acknowledgement) blocks to report which data after the gap it already has. After the third duplicate ACK, the sender retransmits only the missing segment. It does not wait for the retransmission timeout. Once the segment arrives, the cumulative ACK jumps forward over all the data that was buffered behind the gap.
Now look at the effect on the upper layers. Segments 201 to 204 arrived on time, but TCP does not deliver them to TLS, because TCP guarantees order. The TLS record that contains bytes 288,153 to 289,600 cannot be decrypted until it is complete, so HTTP cannot pass on the body bytes. For one round trip, the application sees nothing at all, even though most of the data is already in the receiver's memory. This is TCP's head-of-line blocking. For a single download it costs little. But HTTP/2 multiplexes many independent resources over one TCP connection, so there a single lost packet stalls every resource at once. This is the main reason for HTTP/3 (section 17).
Who noticed the loss? Not layer 1 or 2 on the link where it happened, because the frame was dropped from a queue, not corrupted. Not layer 3, because IP never reports congestion drops. Not TLS and not HTTP. Only TCP, the end-to-end reliability layer, detected and repaired the loss, and only TCP's congestion control reacted to it. This division of work is exactly what the end-to-end principle requires.
16.4 The MTU Black Hole
Now suppose Alice connects through a VPN that wraps every packet in an extra 60 bytes of headers. The effective MTU of the path is then 1440 bytes instead of 1500. Small packets (the TCP handshake, the TLS ClientHello, short API calls) work. But the server sends full-sized 1500-byte packets with the DF (Don't Fragment) flag set. A router at the VPN entry cannot forward them, so it sends back an ICMP "Fragmentation Needed" message with the correct MTU. If a misconfigured firewall somewhere blocks all ICMP "for security", that message never arrives. The server keeps retransmitting the same 1500-byte packet, and the router keeps dropping it. Once you know the symptom, it is easy to recognise: the connection is established, small requests work, and large responses hang forever. This is called a PMTU black hole (PMTU: path MTU, the smallest MTU on the whole path).
The fixes work on different layers:
Layer 3: allow ICMP type 3 code 4 (and ICMPv6 "Packet Too Big") through firewalls. Blocking all ICMP is a configuration mistake, not a security measure.
Layer 4: clamp the TCP MSS on the VPN or PPPoE router (section 14.2), so that endpoints never create packets that are too large.
Layer 4, end host: Packetization Layer PMTU Discovery (RFC 4821), enabled in Linux with net.ipv4.tcp_mtu_probing, uses TCP itself to probe the path size and does not depend on ICMP.
The MTU black hole is a clear example of why the layered model matters for troubleshooting: the symptom appears at layer 7 (a hanging download), the cause lies at layer 3 (a dropped ICMP message), and the workaround is at layer 4 (MSS clamping).
QUIC merges the transport handshake and the TLS handshake. The first packet from the client, a QUIC Initial packet, already carries the TLS ClientHello. The server's response carries the ServerHello and, in encrypted form, the certificate and Finished. After one round trip, the client can send the HTTP request.
With a session ticket from an earlier visit, QUIC can also send the request in the very first flight (0-RTT). The same replay risk applies as with TLS 1.3 (section 12.5).
17.4 What the Packet Looks Like
On the wire, the request is a UDP datagram to port 443. Inside is a QUIC packet with a short header (used after the handshake). The header has one flags byte, a destination connection ID chosen by the server (for example 8 bytes) and an encrypted packet number. The encrypted payload follows. The payload contains QUIC frames. Here it is a STREAM frame for stream 0 (the first bidirectional stream that the client opens), and this frame contains the HTTP/3 frames:
UDP datagram (198.51.100.77:40113 -> 203.0.113.10:443)
└── QUIC short-header packet
(connection ID 4a 8f 21 c3 09 7d e2 55, packet number protected)
└── STREAM frame, stream ID 0, offset 0, FIN
├── HTTP/3 HEADERS frame (QPACK-encoded):
│ :method POST :scheme https
│ :authority blog.example.com
│ :path /api/posts/42/comments
│ content-type application/json
│ content-length 63
└── HTTP/3 DATA frame:
{"author":"Alice","text":"Great explanation of the OSI model!"}
The pseudo-header fields (:method, :path, :authority) replace the HTTP/1.1 request line and the Host header. QPACK compresses them with two tables: a static table of common fields and a dynamic table of fields seen earlier on the connection. For example, :method POST is a single byte, because it is in the static table. The QUIC packet is protected with AEAD (authenticated encryption) exactly like a TLS record. An observer therefore sees UDP, the connection ID and encrypted bytes, and nothing else.
17.5 Streams Remove Head-of-Line Blocking
In QUIC, every HTTP request has its own stream, and QUIC guarantees order only within a stream. If a packet with data of stream 4 is lost, only stream 4 waits for the retransmission. Streams 0 and 8 continue to deliver data to the application. Compare this with section 16.3, where a single lost TCP segment blocked everything. QUIC moves the reliability mechanism from the byte stream of a whole connection to individual streams. This is exactly what a multiplexed protocol like HTTP needs.
17.6 Connection Migration
A TCP connection is bound to its 5-tuple (protocol, source and destination address, source and destination port). Suppose Alice walks out of the house and her phone switches from Wi-Fi to the cellular network. Her IP address changes, every TCP connection breaks, and every TLS session must be set up again. A QUIC connection, in contrast, is identified by its connection IDs, not by addresses. When the client's address changes, the client continues the connection from the new address. It switches to a fresh connection ID that the server issued earlier, so that observers cannot link the old and the new path. After a quick path validation, the connection continues. The session layer was defined in the 1980s as a dialogue that is independent of the underlying transport connection; this idea becomes reality in a 2021 protocol.
17.7 The Trade-offs
QUIC has costs. It runs in user space and encrypts every packet individually, so it uses more CPU per byte than kernel TCP with hardware offloads. Some corporate networks block UDP 443, so clients must always be able to fall back to TCP. And because the headers are encrypted, network operators lose the visibility they used for troubleshooting. In a capture, TCP sequence numbers told them about loss and retransmission; QUIC hides them by design and exposes only a single "spin bit" for latency measurement. Each of these trade-offs is, again, a statement about which layer is allowed to see what.
Remote destination (server 203.0.113.10)
Routing decision
Same subnet: deliver directly
Different subnet: send to default gateway
ARP lookup for
192.168.1.40 (the destination)
192.168.1.1 (the router), never for the server
Destination MAC in the frame
Printer
Router
Destination IP in the packet
Printer
Server
TTL on arrival
64
64 minus the number of routers
Many people believe that a computer sends ARP requests for Internet servers. It never does: ARP only resolves addresses on the local link. If the gateway's MAC address is unknown, the computer cannot reach anything outside the local network. This is why a wrongly configured default gateway produces exactly the symptom "local network works, Internet does not".
18.3 The Same with IPv6: Neighbour Discovery
IPv6 replaces ARP with the Neighbor Discovery Protocol (NDP, RFC 4861). NDP uses ICMPv6 messages instead of a separate protocol:
Neighbour Solicitation and Advertisement replace ARP request and reply. The solicitation is not broadcast. Instead, it goes to a solicited-node multicast address, which is derived from the last 24 bits of the target address (ff02::1:ffxx:xxxx). As a result, only a handful of devices have to process it, not every device on the network. IPv6 has no broadcast at all.
Router Solicitation and Advertisement let hosts find their routers and learn the network prefix. With SLAAC (stateless address autoconfiguration), a host combines the advertised /64 prefix with an interface identifier that it generates itself (randomised for privacy, RFC 8981). In this way it configures its own global address without any DHCP server.
Duplicate Address Detection checks that no other device already uses the address.
Redirects tell a host about a better first-hop router, like ICMPv4 redirects.
NDP runs on ICMPv6. Firewalls that block ICMPv6 therefore do not only break PMTU discovery; they break IPv6 completely. The layering lesson is the same as with ARP: the network layer cannot work without a mechanism that maps its logical addresses to link-layer addresses.
18.4 Broadcast Domains and Collision Domains
This example also clarifies two terms that appear in every networking exam. A broadcast domain is the set of devices that receive each other's layer-2 broadcasts, for example ARP requests. Routers (and VLANs) form its boundaries. A collision domain is the set of devices whose transmissions can collide on a shared medium. With full-duplex switched Ethernet, every switch port is its own collision domain, and collisions no longer happen at all. In Wi-Fi, all stations on one channel effectively form one collision domain. The home network in our examples is one broadcast domain. The Internet is a network of millions of broadcast domains connected by routers, and a broadcast never crosses from one to another.
# Layer 3: do I have an address and a default route?
# expect "default via 192.168.1.1 dev eth0"
# Layer 2: is the gateway resolvable?
# expect "lladdr 98:9b:cb:21:7e:01 REACHABLE"
# Layer 3: is the Internet reachable at all?
# Layer 7 (DNS): does the name resolve?
# expect 203.0.113.10
# Layer 3: does the path to the server work?
# Layer 4: is the port open?
# Layers 5/6: does TLS work, and is the certificate valid?
# Layer 7: what does HTTP say?
The first step that fails names the layer to investigate. If ping 1.1.1.1 works but dig fails, the problem is DNS, not "the Internet". If nc connects but openssl fails, the network is fine and the TLS configuration is not. You save many hours of debugging if you refuse to look at layer 7 before you have checked layers 1 to 4.
19.3 How Traceroute Works
traceroute makes clever use of a layer-3 safety mechanism. It sends packets towards the destination with deliberately small TTL values: first TTL 1, then 2, then 3, and so on. The first router decrements TTL 1 to 0, discards the packet and returns an ICMP Time Exceeded message, which reveals its address. The second packet dies at the second router, and so on. Finally a packet reaches the destination, which answers with an ICMP Echo Reply or a Port Unreachable.
$ traceroute -n 203.0.113.10
1 192.168.1.1 0.6 ms 0.5 ms 0.5 ms home router
2 198.51.100.1 7.9 ms 8.1 ms 7.8 ms ISP BNG
3 192.0.2.9 9.2 ms 9.0 ms 9.4 ms ISP core
4 * * * no reply (ICMP rate-limited/filtered)
5 192.0.2.17 14.6 ms 14.4 ms 14.8 ms ISP border / IXP
...
12 203.0.113.10 28.9 ms 28.7 ms 29.1 ms destination
Two rules help you avoid wrong conclusions. First, stars in the middle of the path with good results after them are harmless. Many routers do not send ICMP messages, or they rate-limit them, but they still forward traffic perfectly. Only stars that continue to the end suggest a real break, and even then the destination may simply be filtering the probes; confirm with a TCP test such as nc. Second, a jump in latency that stays until the destination points to a slow link at that hop. A jump that appears at one hop and disappears at the next only means that this router's control plane (the part that handles its own messages, such as ICMP) answers slowly.
19.4 Symptoms and Their Layers
Symptom
Likely layer
Typical cause
No link light, "NO-CARRIER"
1
Cable, port, Wi-Fi off
Link up, but many CRC or FCS errors
1/2
Damaged cable, duplex mismatch, interference
Address 169.254.x.x
3 (via 7)
No DHCP server reachable
Local hosts reachable, Internet not
3
Missing or wrong default gateway, router down
IP addresses reachable, names not
7
DNS server down or misconfigured
"Connection refused" immediately
4
Nothing listens on the port; the host answered with RST
"Connection timed out"
3/4
Firewall silently drops packets, host down, routing problem
The difference between "refused" and "timed out" is especially useful. "Refused" shows that layers 1 to 3 work all the way to the host that sent the TCP RST, normally the destination itself (occasionally a firewall in between answers with an RST). "Timed out" means that something on the way, or the host itself, silently discarded the packets. This points to a firewall or a routing problem.
19.5 Reading a Packet Capture
When the tools disagree, the packets decide. A short capture of our main example with tcpdump shows the whole connection in a few lines:
After the SYN, tcpdump shows relative sequence numbers. seq 582:834 is our 252-byte request record (absolute 2918734105), and length 260 in the reply is the TLS record that carries the 238-byte response. Note that the capture on the laptop shows the private address 192.168.1.23. A capture on the server would show 198.51.100.77 and port 40112 for the same connection. The 30 ms between the SYN and the SYN-ACK is the RTT. The 39 ms between the request and the response is one RTT plus the server's processing time. You can check every number in this article in a capture like this one. (A real capture of a server's first flight would show it split into two segments, because 2690 bytes exceed one MSS. Here it is shown as one line to keep it short.)
my
SYN flood (layer 4). An attacker sends a flood of TCP SYN segments with spoofed (faked) source addresses. For each one, the server stores state for a half-open connection, sends a SYN-ACK to an address that will never answer, and waits. In the end, the queue of half-open connections is full, and real clients cannot connect. The defence is SYN cookies. When the queue is full, the server encodes the connection parameters into its initial sequence number and keeps no state at all. Only when the final ACK arrives with the cookie + 1 does the server rebuild the connection. The defence works entirely inside layer 4.
Vulnerability scanning (layer 7). Automated scanners send requests for typical exploit paths, such as /.env, /wp-login.php or /actuator/env, to millions of servers. They hope to find an exposed configuration file or an unpatched admin interface. Every request is a fully valid TCP connection and a fully valid HTTP request. So layer-3 and layer-4 defences cannot tell it apart from a normal visitor. Only a layer-7 control that understands what the path means can recognise the behaviour. However, layer-7 behaviour alone can be misleading: search engine crawlers follow links to such paths when they find them somewhere on the web. A sound defence therefore combines layers. It recognises suspicious behaviour at layer 7 and checks the identity of the sender at layer 3. For example, it can verify that a client that claims to be Googlebot really comes from an address in Google's published ranges. Or it can check that the client's reverse DNS name ends in googlebot.com and resolves back to the same address. Behaviour and identity live on different layers, and robust security needs both.
20.3 Where Encryption Can Live
You can apply encryption at several layers. Each choice protects a different part of the path:
Layer
Technology
Protects
Visible to observers
2
WPA3, MACsec (802.1AE)
One link (laptop to access point, switch to switch)
Everything, on every other link
3
IPsec, WireGuard (VPNs)
Between two networks or hosts (the tunnel)
Tunnel endpoints, packet sizes and timing
4/5/6
TLS, QUIC
End to end between client and server application
IP addresses, ports, SNI (unless ECH), sizes, timing
7
End-to-end encrypted messaging (e.g. Signal protocol), S/MIME, PGP
Between users, even across servers
Metadata of the application (who talks to whom, when)
The higher the layer, the further the protection reaches. But the lower layers still reveal more metadata, that is, data about the communication rather than its content. A VPN hides from the local Wi-Fi which servers you talk to. TLS hides from the VPN provider what you say to them. Neither hides from the server what you send it. Defence in depth means using several layers on purpose and knowing exactly what each one protects.
Segment, datagram
Ports
3 Network
Which host, across which networks?
Packet
IP addresses
2 Data link
Which neighbour on this link?
Frame
MAC addresses
1 Physical
How are bits transmitted?
Bit, symbol
–
Its typical protocols, the header fields it reads and the devices that work at this layer:
Layer
Key protocols
Main header fields
Devices
7 Application
HTTP, DNS, SMTP, SSH
Method, path, status, headers
Proxies, WAFs, L7 load balancers
6 Presentation
TLS (encryption), JSON, UTF-8, gzip
Content type, encoding
TLS terminators
5 Session
TLS handshake, cookies, RPC
Session identifiers
–
4 Transport
TCP, UDP, QUIC
Ports, sequence/ack numbers, flags, window
Firewalls, NAT, L4 load balancers
3 Network
IPv4, IPv6, ICMP, BGP
Addresses, TTL, protocol
Routers
2 Data link
Ethernet, Wi-Fi, ARP, VLAN
MAC addresses, EtherType, FCS
Switches, access points
1 Physical
1000BASE-T, fibre optics, 802.11 radio
– (signals, coding)
Cables, hubs, transceivers
21.3 The Whole Journey in Twelve Steps
The application builds a layer-7 message: POST /api/posts/42/comments with a JSON body.
DNS translates blog.example.com into 203.0.113.10, and DNS itself uses all the layers to do this.
TCP sets up a connection with a three-way handshake.
TLS authenticates the server and agrees on keys in one round trip.
TLS encrypts the HTTP message into a record (presentation and session functions).
TCP puts the record into a segment with ports and sequence numbers.
IP puts the segment into a packet with the final destination address and decides on the next hop.
ARP finds the MAC address of the next hop, and Ethernet puts the packet into a frame.
The physical layer turns the frame into signals.
Every router removes the layer-2 frame, decreases the TTL by one, chooses the next hop and builds a new frame. The home router also translates the address (NAT).
The server's stack removes each header in reverse order. At each layer it uses the demultiplexing field (the field that names the next protocol) to find the next protocol. This continues until the application receives the exact 230 bytes that Alice's client sent.
The response travels back the same way. The conversation ends with TLS close_notify and TCP FIN.
For a textbook treatment, the classics are still Computer Networking: A Top-Down Approach by Kurose and Ross, Computer Networks by Tanenbaum, Feamster and Wetherall, and TCP/IP Illustrated, Volume 1 by Stevens and Fall. Like this article, the last one explains protocols by showing the packets.
Which layer gave you the most trouble in your own projects? The next time a request fails, try the bottom-up walk from section 19 before you open the application logs. See how quickly the layered view leads you to the cause.