Web and networkingDive 04 of 12
HTTP/3 and QUIC, from request to datagram
How HTTP moved off TCP: head-of-line blocking, QUIC streams and packets, a TLS 1.3 handshake folded into the transport, and the UDP datagrams carrying it all.
- Levels
- 10
- Reading
- 45 min
- Depth
- Idea to Machine
- Published
- HTTP request
GET https://example.com/ - HTTP/3 HEADERS frame
01 12 - QUIC STREAM frame
0b 00 14 - QUIC 1-RTT packet
flags, 8-byte connection ID, packet number - UDP datagram
ports, length, checksum - IPv4 packet
addresses, protocol 17, DF set
GET https://example.com/, wrapped layer by layer until it is a 78-byte IPv4 packet. Bars are drawn to scale in bytes. Each layer's payload is the whole layer above it, except that QUIC encrypts its frames and appends a 16-byte authentication tag. A real first request shares its packet with other frames; this one travels alone so you can see the nesting.Why HTTP left TCP
You are on a train, opening a news site on your phone. The page needs an HTML document, two stylesheets, a few scripts and a dozen images, all from the same host. The mobile link loses a packet here and there, and every loss costs a round trip to repair. That is the scene this whole dive is about: one page, many resources, an imperfect network, and the question of what happens to everything else when a single packet goes missing.
HTTP itself is a simple idea: a client sends a request (a method, a target, some header fields, maybe a body) and gets back a response. What has changed over thirty years is not that idea but how many of those exchanges you can run at once over one connection, and what the transport underneath does when the network misbehaves.
HTTP/1.1: one exchange at a time
HTTP/1.1 is text on a TCP connection. A request goes out, the response comes back, and only then can the next request use that connection. HTTP/1.1 did define Sending several requests back to back without waiting for the responses. Responses must still come back in request order, so one slow response delays all the others., but responses still had to come back in order, and enough proxies mishandled it that browsers shipped with it switched off.
So browsers opened several TCP connections per host, typically up to six, and sites learned workarounds: spreading assets across extra hostnames, gluing images into sprite sheets and concatenating scripts. Each extra connection paid for its own TCP handshake and TLS handshake, and each ran its own congestion control, starting slow and competing with its siblings.
HTTP/2: many streams, one TCP connection
HTTP/2 (RFC 7540 in 2015, revised as RFC 9113) kept HTTP's meaning and replaced the wire format. Messages became binary frames, each tagged with a stream ID, and frames from many streams interleave on one TCP connection. Headers are compressed with HPACK. One connection, one handshake, one congestion controller, and no more waiting for a slow response before sending the next request.
The catch is underneath. TCP gives its user exactly one thing: an ordered stream of bytes. It has no idea that bytes 10,000 to 11,400 belong to a stylesheet and the next 1,400 to an image. If the segment carrying the stylesheet bytes is lost, the kernel keeps every later byte in its receive buffer, even ones that arrived intact and belong to other streams, until the retransmission fills the gap. HTTP/2 removed head-of-line blocking at the HTTP layer and inherited it from the transport. On a lossy link, a single HTTP/2 connection can do worse than six HTTP/1.1 connections, because one loss stalls everything instead of one sixth of everything.
HTTP/1.1
Several TCP connections, one exchange at a time on each
Cost: a TCP and TLS handshake per connection, separate congestion control for each, and a queue behind every slow response.
HTTP/2
One TCP connection, frames from many streams interleaved
Cost: head-of-line blocking moved down from HTTP into TCP, where HTTP/2 cannot see or fix it.
HTTP/3
One QUIC connection over UDP, each stream ordered on its own
Cost: transport in user space over UDP, more CPU per byte, and networks that block or throttle UDP.
HTTP/3: put the streams in the transport
The fix is to make the transport understand streams, so that a loss on one stream does not hold back the others. You cannot change TCP to do that: TCP is implemented in every operating system kernel and inspected by middleboxes all over the internet, and both resist change (more on that at the bottom of this dive). So a new transport was built on top of UDP, which the internet already carries everywhere.
That transport is QUIC. It began as an experiment at Google, later called gQUIC, which ran its own cryptography. The IETF then standardised a reworked design: QUIC version 1 in RFC 9000 (transport), RFC 9001 (using TLS 1.3 for its keys), RFC 9002 (loss detection and congestion control) and RFC 8999 (the properties every future version must keep), all published in May 2021. HTTP/3, the mapping of HTTP onto QUIC, followed as RFC 9114 in June 2022, together with RFC 9204 for QPACK header compression.
| HTTP/1.1 | HTTP/2 | HTTP/3 | |
|---|---|---|---|
| Transport | TCP (+ TLS for https) | TCP + TLS | QUIC over UDP (TLS 1.3 built in) |
| Wire format | Text | Binary frames | Binary frames on QUIC streams |
| Parallel requests | One per connection; several connections | Many streams on one connection | Many streams on one connection |
| Header compression | None | HPACK | QPACK |
| Round trips before a new connection's first request | 2 with TLS 1.3, 3 with TLS 1.2 | 2 with TLS 1.3, 3 with TLS 1.2 | 1, or 0 when resuming |
| A lost packet stalls | Its connection | Every stream on the connection | Only the streams it carried data for |
| Survives an IP address change | No | No | Yes, via connection IDs |
The last rows hint that QUIC fixes more than head-of-line blocking. Because it is designed alongside TLS 1.3, the transport and cryptographic handshakes happen in the same round trip. Because connections are named by IDs rather than by IP addresses and ports, a connection can survive your phone moving from Wi-Fi to cellular. Because almost the entire packet is encrypted, routers and firewalls cannot come to depend on its details, which keeps the protocol free to change. And because it runs in user space, browsers and servers can ship improvements with their next release instead of waiting for operating systems to update.
HTTP/3 is HTTP/2's idea, many streams on one connection, moved onto a transport that understands streams itself.
The rest of the dive follows one request, GET https://example.com/, from the moment the browser decides to use HTTP/3 down to the bytes of the UDP datagram that carries it. The figure at the top of the page is the map: each level below peels off one of those layers.
Finding the HTTP/3 door
The URL https://example.com/ names a scheme, a host and a path. It says nothing about which version of HTTP to speak. For HTTP/1.1 and HTTP/2 that never mattered much: both run over TCP port 443, and TLS negotiates between them with Application-Layer Protocol Negotiation (RFC 7301): a TLS extension in which the client lists protocols it speaks, such as h2 and http/1.1, and the server picks one inside the handshake. during the handshake.
HTTP/3 cannot be negotiated that way, because it does not run over TCP at all. A browser that wants it has to send UDP packets to the server before any TCP or TLS exchange has happened, and it needs some reason to believe the server will answer. The ALPN token for HTTP/3 is h3, and there are two standard ways to learn that a server accepts it.
Alt-Svc: learn it on the first visit
The older mechanism is the Alt-Svc response header (RFC 7838). The server answers over HTTP/1.1 or HTTP/2 as usual and adds a line advertising an alternative service: "the same origin is also reachable with h3 on UDP port 443, and you may remember this for ma seconds".
HTTP/2 200
content-type: text/html; charset=utf-8
alt-svc: h3=":443"; ma=86400- First visit. The browser knows nothing about HTTP/3 support, so it does what it always does: resolve the name, open TCP, run TLS and let ALPN pick HTTP/2.
- The response carries an
alt-svcheader.h3=":443"means "HTTP/3, same host, port 443".ma=86400is the max age in seconds, which is also the default when it is left out. - The browser stores the alternative for this origin. The page that is already loading keeps using HTTP/2; switching protocols mid-flight is not worth it.
- The next time the browser needs a connection to this origin, it tries QUIC. Because UDP may be blocked on this network, browsers commonly start a TCP connection in parallel or shortly after, and use whichever is ready.
- QUIC wins and the browser uses HTTP/3 from now on. If QUIC had failed, the browser would fall back to TCP and remember for a while that HTTP/3 does not work here.
HTTPS records: learn it before connecting
Alt-Svc has an obvious weakness: the first connection to a site is always over TCP. The newer mechanism moves the hint into DNS. An HTTPS resource record (RFC 9460, record type 65) can list the ALPN tokens a service supports, plus address hints and other connection parameters. A browser that queries it alongside the usual A and AAAA records can go straight to QUIC on the very first visit.
$ dig +short example.com HTTPS
1 . alpn="h3,h2" ipv4hint=203.0.113.5 ipv6hint=2001:db8::5Reading that record: priority 1 means this is a service record rather than an alias; the target . means "the same name you asked about"; alpn="h3,h2" lists the protocols; the hints let the client start connecting before its A and AAAA answers come back. The same record type also carries the keys for Encrypted Client Hello, so it is becoming a general "how to connect to me" record.
Same HTTP, new frames
Open your browser's network panel on an HTTP/3 site and the requests look like any others: GET, 200, content-type, cookies. That is deliberate. Since 2022 the meaning of HTTP has its own specification, RFC 9110, and HTTP/1.1, HTTP/2 and HTTP/3 are three ways to put that meaning on the wire. Your application code, your caches and your fetch() calls do not change.
What changes is the framing. Like HTTP/2, HTTP/3 carries the request line as Header-like fields whose names start with a colon. They carry what HTTP/1.1 put in the request line and status line: :method, :scheme, :authority and :path for requests, :status for responses. (:method, :scheme, :authority, :path, and :status on responses), lowercases all field names and sends everything in binary frames.
One request, one stream
Every request gets its own QUIC stream, specifically a client-initiated bidirectional one. On it the client sends a HEADERS frame, then zero or more DATA frames for a body, optionally a final HEADERS frame for trailers, and then closes its side of the stream. The server answers on the same stream in the same shape. The end of the stream marks the end of the message, so chunked transfer encoding has no place in HTTP/3.
Notice what is missing from that description: stream IDs. In HTTP/2 every frame header carries a 31-bit stream ID because all streams share one TCP byte stream. In HTTP/3 the frame already sits inside a QUIC stream, so the frame header shrinks to two fields: a type and a length, both variable-length integers (decoded byte by byte five levels down). A HEADERS frame of 18 bytes therefore costs exactly two bytes of framing: 01 12.
| Type | Frame | Where | Carries |
|---|---|---|---|
0x00 | DATA | Request streams | Message body bytes |
0x01 | HEADERS | Request streams | A QPACK-compressed field section: headers or trailers |
0x03 | CANCEL_PUSH | Control stream | Cancels a server push |
0x04 | SETTINGS | Control stream, first frame | Configuration for the whole connection, sent once by each side |
0x05 | PUSH_PROMISE | Request streams | Announces a pushed response |
0x07 | GOAWAY | Control stream | Graceful shutdown: "I will not process requests at or above this stream ID" |
0x0d | MAX_PUSH_ID | Control stream | The highest push ID the server may use |
Several HTTP/2 frames are simply gone, because QUIC now does their job. WINDOW_UPDATE became QUIC flow control, RST_STREAM became QUIC's RESET_STREAM and STOP_SENDING, PING moved to QUIC, and CONTINUATION is unnecessary because a frame can be as long as it needs to be. The type codes of HTTP/2's PRIORITY (0x02), PING (0x06), WINDOW_UPDATE (0x08) and CONTINUATION (0x09) are reserved in HTTP/3, and receiving one is a connection error. RST_STREAM's old code, 0x03, was reused for CANCEL_PUSH. HTTP/2's PRIORITY frame was dropped too; prioritisation now uses the Priority header and a PRIORITY_UPDATE frame from RFC 9218, which works on both versions.
Streams that are not requests
Connection-wide state travels on unidirectional streams. The first byte of each says what kind of stream it is: 0x00 for the control stream, 0x01 for a push stream, 0x02 and 0x03 for the QPACK encoder and decoder streams. Each side opens exactly one control stream, and its first frame must be SETTINGS. Here is a complete client control stream opening, byte for byte:
- Stream type: control
- Frame type: SETTINGS
- Frame length5 bytes of settings follow
- QPACK_MAX_TABLE_CAPACITYSetting identifier 0x01
- = 40962-byte varint
- QPACK_BLOCKED_STREAMSSetting identifier 0x07
- = 16
QPACK, in brief
HTTP headers are repetitive: the same user-agent, accept and cookies on every request. HTTP/2's HPACK compresses them with a static table of common fields plus a dynamic table that both ends build up as headers flow. Each header block can add entries, and later blocks refer to them by position.
That relies on header blocks being decoded in exactly the order they were encoded, which TCP guarantees. On QUIC, request streams arrive in whatever order the network allows, so a block could refer to an entry whose insertion is stuck in a lost packet on another stream. QPACK (RFC 9204) splits the work: insertions travel on the dedicated encoder stream, every entry keeps a fixed absolute index (the first insertion is 0, the next 1, and so on), and each header block starts with a prefix holding a Required Insert Count, how many insertions the decoder must have seen before it can decode the block, and a Base. Field lines in the block refer to dynamic entries relative to that Base, so the same block decodes correctly however many other insertions have happened since. If they have not arrived, that one stream waits, and only up to the number of blocked streams the decoder allowed in its SETTINGS. An encoder that never wants to block can stick to entries the decoder has already acknowledged on the decoder stream, trading compression for independence.
QPACK's static table has 99 entries, chosen from real traffic, so a typical request compresses well even with no dynamic table at all. Build one below. The encoder here uses only the static table and plain (non-Huffman) strings, so you can read every byte; real encoders also Huffman-code string literals.
1 · QPACK field section
2 · HTTP/3 HEADERS frame wraps it
3 · QUIC STREAM frame wraps that
HTTP/3 keeps HTTP's meaning and moves everything that was about multiplexing, flow control and stream lifetimes down into QUIC.
Streams and head-of-line blocking
The previous level kept saying "QUIC stream". A QUIC stream is an ordered, reliable byte stream, which is exactly what a TCP connection is, except that one QUIC connection can carry many of them at once, and they are cheap. There is no handshake to open one: a stream exists as soon as either side sends data on a new stream ID. Closing one is a flag on its last frame.
Stream IDs carry their own type
A stream ID is a 62-bit integer, and its two lowest bits say who opened the stream and whether data flows both ways. Bit 0 is the initiator (0 for the client, 1 for the server). Bit 1 is the direction (0 for bidirectional, 1 for unidirectional). The rest of the number counts streams of that type. So the client's requests go on streams 0, 4, 8, 12 and so on, and neither side can ever collide with the other when picking a new ID.
| Low bits | Initiator | Direction | IDs | Used in HTTP/3 for |
|---|---|---|---|---|
0b00 | Client | Bidirectional | 0, 4, 8, 12 … | Requests: one per request and response |
0b01 | Server | Bidirectional | 1, 5, 9, 13 … | Not used by HTTP/3 (a connection error if opened) |
0b10 | Client | Unidirectional | 2, 6, 10, 14 … | Client control stream, QPACK encoder and decoder streams |
0b11 | Server | Unidirectional | 3, 7, 11, 15 … | Server control and QPACK streams, server push |
Data moves in STREAM frames. Each one names its stream, gives the offset of its first byte within that stream, and carries a run of bytes. The frame type itself is a little bit field: types 0x08 to 0x0f are all STREAM, with the low three bits saying whether an offset is present (0x04), whether a length is present (0x02) and whether this frame ends the stream (0x01). The request you built in the last level started a stream, so it needed no offset: type 0x0b is length plus FIN.
- Type 0x0e: STREAM + OFF + LEN
- Stream ID 8
- Offset 2400Where these bytes go in stream 8
- Length 4
- Stream dataThe text </p>
The offset is what makes streams independent. When a packet arrives, the receiver files each STREAM frame into its stream's reassembly buffer at the given offset. If a stream has no gaps up to that point, its bytes go straight to the application. A gap in one stream says nothing about any other stream. TCP has one sequence number space for the whole connection, so a gap anywhere blocks everything after it.
Drop a packet and watch
Below, nine packets carry three responses, interleaved the way an HTTP/2 or HTTP/3 server would send them. Drop any packet, or several, and compare what the browser receives over each stack. The top row is physical arrival, identical for both. The rows below are when each chunk is actually handed to the browser.
Packets in send order. Press one to drop it.
On the wire when each packet reaches the receiver
HTTP/2 over TCP TCP hands bytes up strictly in order
HTTP/3 over QUIC each stream is ordered on its own
- Data handed to the browser
- Arrived, sitting in the receive buffer
- Held back, waiting for earlier bytes
- Lost, waiting for the retransmission
Model: packets leave every 10 ms, one-way delay 50 ms (a 100 ms round trip), one chunk of one stream per packet, and retransmissions are never lost. A lost packet is detected by the RFC 9002 rules: once a packet three or more numbers later is acknowledged, or once a later packet is acknowledged and 112.5 ms (9/8 RTT) have passed since the lost one was sent. If nothing later is ever acknowledged, as when the last packets are lost, only a probe timeout can rescue it; here that fires 150 ms after the last send and the probe carries all the missing data, so tail losses take longest.
TCP orders bytes across the whole connection; QUIC orders bytes within each stream. That difference is the whole cure for transport head-of-line blocking.
What the simulation leaves out
Real packets carry more than one chunk. A server that round-robins small frames from many streams into every packet makes each loss touch several streams, and burst losses hit everything regardless. How the sender packs and schedules streams matters as much as the transport's ability to deliver them independently.
HTTP/3 also still has head-of-line blocking in two places by design. Within one stream, bytes are delivered in order, so a large response stalls behind its own gap. And as you saw in QPACK, a header block that references a dynamic-table entry still in flight waits for it, which is why the decoder caps the number of blocked streams.
Limits: flow control and stream counts
Cheap streams need limits. A receiver advertises how many bytes it is willing to buffer per stream (MAX_STREAM_DATA) and across the whole connection (MAX_DATA), and raises those limits as the application consumes data. It also caps how many streams the peer may open (MAX_STREAMS), separately for bidirectional and unidirectional streams. For HTTP/3, the bidirectional limit is the server's way of saying how many requests may be in flight at once, which in HTTP/2 was the SETTINGS_MAX_CONCURRENT_STREAMS setting.
One round trip, or zero
Before the first byte of GET / can leave your phone, two things must be agreed: that the server is listening and will keep state for you (the transport handshake), and which keys will protect the conversation (the TLS handshake). Over TCP these are two separate protocols run one after the other, and each costs at least one round trip. On a mobile network a round trip can take tens or hundreds of milliseconds, so the handshake is often a large share of the time to load a small page.
QUIC does both at once. It does not reinvent the cryptography: it uses the TLS 1.3 handshake messages, but without the TLS record layer. QUIC carries those messages itself, in CRYPTO frames, instead of inside TLS records on a TCP stream, and the record-layer leftovers have no place: QUIC never sends ChangeCipherSpec, and it drops the EndOfEarlyData message. TLS hands its secrets back to QUIC, and QUIC encrypts its own packets with them (RFC 9001). QUIC's own connection settings, called Limits and options such as initial flow-control windows, the maximum number of streams, idle timeout and the connection IDs used. They travel inside a TLS extension, so the handshake authenticates them., ride along inside a TLS extension so that the handshake authenticates them too.
Encryption levels and packet types
A TLS 1.3 handshake produces keys in stages, and QUIC sends each stage in its own packet type. Initial packets carry the ClientHello and ServerHello, protected with keys anyone can compute (you will compute them yourself four levels down). Handshake packets carry the rest of the handshake under keys derived from the Diffie-Hellman exchange. 1-RTT packets carry application data under the final keys. A resumed connection can also use 0-RTT packets, explained below. Pick a handshake and compare.
- 0 RTTClient to server:SYN
- 0.5 RTTServer to client:SYN-ACK
- 1 RTTClient to server:ACKClientHello
- 1.5 RTTServer to client:ServerHello, Certificate, ServerKeyExchange, ServerHelloDone
- 2 RTTClient to server:ClientKeyExchange, ChangeCipherSpec, Finished
- 2.5 RTTServer to client:ChangeCipherSpec, Finished
- 3 RTTClient to server:GET /
- 3.5 RTTServer to client:200 OK
- 4 RTTRequest sent at 3 RTT, first response byte back at 4 RTT
A full TLS 1.2 handshake with ECDHE key exchange. TLS False Start lets the client send its request with its Finished message, saving one round trip, but needs a forward-secret cipher suite and support on both sides.
- TCP control
- TLS record
- HTTP over TLS
- 0 RTTClient to server:SYN
- 0.5 RTTServer to client:SYN-ACK
- 1 RTTClient to server:ACKClientHello + key_share
- 1.5 RTTServer to client:ServerHello + key_share, {EncryptedExtensions, Certificate, CertificateVerify, Finished}
- 2 RTTClient to server:{Finished}GET /
- 2.5 RTTServer to client:200 OK
- 3 RTTRequest sent at 2 RTT, first response byte back at 3 RTT
TLS 1.3 sends key shares in the first message, so the handshake itself takes one round trip. TCP still needs its own before TLS can start.
- TCP control
- TLS record
- HTTP over TLS
- 0 RTTClient to server:Initial: CRYPTO[ClientHello], PADDING to 1200 bytes
- 0.5 RTTServer to client:Initial: ACK, CRYPTO[ServerHello]Handshake: CRYPTO[EncryptedExtensions, Certificate, CertificateVerify, Finished]
- 1 RTTClient to server:Initial: ACKHandshake: ACK, CRYPTO[Finished]1-RTT: STREAM 0 [GET /]
- 1.5 RTTServer to client:1-RTT: ACK, HANDSHAKE_DONE, STREAM 0 [200 OK]
- 2 RTTRequest sent at 1 RTT, first response byte back at 2 RTT
The transport and TLS handshakes are the same handshake. TLS messages ride in CRYPTO frames inside Initial and Handshake packets; the request rides in a 1-RTT packet next to the client's Finished.
- QUIC Initial
- QUIC Handshake
- QUIC 1-RTT
- 0 RTTClient to server:Initial: CRYPTO[ClientHello + pre_shared_key, early_data]0-RTT: STREAM 0 [GET /]
- 0.5 RTTServer to client:Initial: ACK, CRYPTO[ServerHello]Handshake: CRYPTO[EncryptedExtensions, Finished]1-RTT: STREAM 0 [200 OK]
- 1 RTTClient to server:Handshake: ACK, CRYPTO[Finished]1-RTT: ACK
- 1 RTTRequest sent at 0 RTT, first response byte back at 1 RTT
Resuming a session with a ticket from an earlier connection. The client encrypts the request with keys derived from that ticket and sends it in the very first flight. No certificate this time: the earlier connection already authenticated the server.
- QUIC Initial
- QUIC Handshake
- QUIC 0-RTT
- QUIC 1-RTT
The QUIC timeline saves a full round trip over TCP with TLS 1.3 because the client's very first packet already contains the ClientHello with its key share. The server can reply with everything it needs to send, and the client's second flight carries both its Finished message and the request. The server can even send data in its first flight, before the handshake completes, which is sometimes called 0.5-RTT data; it just cannot know yet who the client is.
0-RTT: the request in the first packet
If you have talked to this server recently, it may have given you a session ticket. On the next connection, TLS 1.3 lets the client derive keys from that ticket and send application data straight away, in 0-RTT packets alongside the Initial. The request reaches the server after half a round trip, and the response can come back in the server's first flight.
Proving your address
A TCP server learns that a client really owns its IP address from the three-way handshake: the client could not have answered the SYN-ACK otherwise. QUIC's server answers the very first packet with a large flight, including a certificate chain that can run to several kilobytes. That is the recipe for an amplification attack, where an attacker spoofs a victim's address and lets the server flood it.
QUIC's rule is that until the client's address is validated, a server may send at most three times the bytes it has received from that address. That is one reason the client pads its first datagram to at least 1,200 bytes, which you will see at the bottom of this dive. A server under load can go further and answer with a Retry packet containing a token; the client must repeat its Initial with the token, proving it can receive packets at its address, at the cost of one extra round trip.
QUIC does not run TLS on top of the transport. TLS runs inside it, and the transport handshake and the key exchange are the same round trip.
Connection IDs and migration
Back on the train. The page has loaded and a video has started when the train pulls out of the station and your phone drops the station's Wi-Fi for cellular. Your phone now has a different IP address. To the network, every packet you send comes from somebody new.
A TCP connection is defined by its Source IP address, source port, destination IP address and destination port. TCP looks up which connection a segment belongs to by this tuple, so if any part changes, the segment matches no connection.. Change any of the four numbers and the server's kernel finds no matching connection; the old connection simply times out. The app has to notice, open a new connection, redo TCP and TLS, and restart or resume its downloads at the application level.
The same thing happens without moving at all. Home routers and carrier-grade NATs forget idle UDP mappings quickly, sometimes after well under a minute, and the next packet leaves with a new external port. This "NAT rebinding" would break a connection keyed on addresses just as surely as switching networks.
Name the connection, not the path
QUIC identifies a connection by a connection ID, an opaque string of up to 20 bytes in version 1. Each endpoint picks the IDs it wants to receive packets on, and its peer puts them in the destination connection ID field. The server's ID can be anything that helps the server find its state: a random lookup key, or an encrypted routing hint that tells a load balancer which machine owns the connection. Addresses still matter for sending replies, but they no longer decide which connection a packet belongs to.
- seq 0 · 5a1c7e93…
- seq 1 · c4d90b21…
- seq 2 · 7f08e6a5…
- 5a1c7e93… → conn #7
- c4d90b21… → conn #7
- 7f08e6a5… → conn #7
- The phone is on Wi-Fi. Every short-header packet it sends carries a destination connection ID that the server chose, here the one with sequence number 0.
- Early on, the server hands out spare IDs in NEW_CONNECTION_ID frames. Each maps to the same connection in the server's table. The phone keeps them for later.
- The phone walks out of Wi-Fi range. Its IP address is gone. TCP identifies a connection by the 4-tuple of addresses and ports, so a TCP connection would have to start over: new handshake, lost state.
- The phone sends its next packet over cellular from a new address. It switches to an unused connection ID (seq 1), so an observer cannot link the two paths by the ID. The server looks the ID up and finds connection #7.
- Before trusting the new address, the server sends PATH_CHALLENGE with 8 unpredictable bytes. Only an endpoint that really receives packets at that address can echo them back in PATH_RESPONSE. Until then, the server limits what it sends there.
- The path is validated. Streams, keys and flow control carry on untouched; the congestion controller and RTT estimate reset because this is a different network. The phone retires the old ID.
Why several IDs?
If the phone kept using the same connection ID on the new path, anyone watching both networks could link your Wi-Fi traffic to your cellular traffic by that ID. So endpoints hand each other a supply of spare IDs in NEW_CONNECTION_ID frames, each with a sequence number, and a client that moves to a new path switches to an ID it has never used before. Only the server, which keeps the mapping, knows that both IDs mean the same connection. Old IDs are retired with RETIRE_CONNECTION_ID once they are no longer needed.
This is also why the short header used for almost all packets has a destination connection ID but no source connection ID: the receiver only needs to know which connection a packet is for, and every extra stable identifier on the wire is one more thing an observer could track.
Validating the new path
An attacker could forge packets with a valid connection ID and someone else's source address, hoping to redirect a large download at a victim. So an endpoint that sees its peer arrive from a new address validates it: it sends a PATH_CHALLENGE frame with 8 unpredictable bytes, and only something that really receives packets at that address can return them in a PATH_RESPONSE. Until then it limits how much it sends there, using the same three-times rule as the handshake.
After a real network change, the endpoint also resets its congestion controller and round-trip estimate. A new path has a new bottleneck, so what it learned about Wi-Fi tells it nothing about the cellular network. If only the port changed, which usually means NAT rebinding on the same path, it may keep them.
A QUIC connection is named by IDs the endpoints choose, so it survives the addresses underneath it changing.
Loss, acks and congestion
UDP promises nothing: datagrams can be lost, duplicated or reordered, and nobody tells the sender. Everything TCP's kernel code does about that, QUIC has to do itself. RFC 9002 describes how, and it does several things differently from TCP because it could start fresh.
Packet numbers never repeat
TCP's sequence numbers count bytes of the stream. When a segment is lost, the retransmission carries the same sequence numbers as the original. So when an acknowledgement arrives, the sender cannot tell whether it acknowledges the original or the copy, and its round-trip measurement is ambiguous. TCP stacks work around this with Karn's algorithm and timestamp options.
QUIC separates two things TCP merged. Packet numbers identify transmissions: every packet gets the next number, starting at 0, and a number is never reused within a connection's number space. Stream offsets identify data. When a packet is declared lost, QUIC does not resend the packet. It looks at the frames that were in it and queues new frames for whatever still matters, which go out in a new packet with a new, higher number. An acknowledgement for packet 12 can only mean packet 12, so every RTT sample is clean.
TCP
- seq 4000 sent at 0 ms lost
- seq 4000 resent at 300 ms
- ACK 5400 arrives at 340 ms
Was that 340 ms or 40 ms of round trip? The ACK cannot say.
QUIC
- pn 7 [STREAM 4, offset 4000] sent at 0 ms lost
- pn 12 [STREAM 4, offset 4000] sent at 300 ms
- ACK 12 arrives at 340 ms
Packet 12 was sent at 300 ms: the round trip was 40 ms.
There are three packet number spaces, one each for Initial, Handshake and application data (0-RTT and 1-RTT share the last). Each is acknowledged separately, and its keys are discarded once the handshake moves past it, so loss in one cannot be confused with loss in another.
ACK frames describe ranges
A QUIC receiver acknowledges with ACK frames that list everything it has received as ranges, counting down from the largest packet number. TCP's selective acknowledgement option can describe only a few blocks, because it must fit in the 40 bytes of TCP option space; an ACK frame can describe hundreds. It also reports how long the receiver held the acknowledgement before sending it, so the sender can subtract that delay from its RTT sample.
Packet numbers the receiver has seen. Press one to toggle it.
Deciding a packet is lost
In the words of RFC 9002, §6.1, a packet is declared lost when it "is unacknowledged, in flight, and was sent prior to an acknowledged packet", and it "was sent kPacketThreshold packets before an acknowledged packet … or it was sent long enough in the past". So both thresholds only judge packets older than something that has been acknowledged. The packet threshold, kPacketThreshold, is 3. The time threshold is 9/8 of the larger of the smoothed and latest RTT. The time rule copes with reordering networks better than a fixed count of duplicate ACKs.
When nothing comes back at all, a Probe timeout: smoothed RTT + max(4 × RTT variation, 1 ms) + the peer's maximum ACK delay, doubled after each consecutive expiry. fires. Unlike TCP's retransmission timeout, it does not on its own declare anything lost or collapse the congestion window; it sends one or two probe packets to provoke an acknowledgement, which then tells the sender what really happened.
Congestion control
Loss detection decides what to resend. Congestion control decides how fast to send anything at all, so that one connection does not overrun the bottleneck link it shares with everyone else. QUIC limits the bytes in flight to a congestion window. RFC 9002 specifies a NewReno-style controller: start with a window of about ten full-size datagrams (the minimum of 10 × the max datagram size and the larger of 14,720 bytes and two datagrams), double it every round trip in slow start, halve it when loss signals congestion, then grow it by one datagram per round trip.
The specification's controller is a baseline, not a requirement. Because QUIC lives in user space, implementations swap in other algorithms: CUBIC (RFC 9438), the default in Linux TCP, is common, and BBR, which models the path's bandwidth and round-trip time instead of reacting to loss, is widely used too. Changing TCP's congestion control on a server means changing the kernel; changing QUIC's means shipping a new library version.
QUIC retransmits frames, not packets. Fresh packet numbers for every transmission make acknowledgements, RTT samples and loss detection unambiguous.
Integers that carry their own length
You are now at the bytes. Stream IDs, offsets, lengths, frame types, the numbers in ACK frames, HTTP/3 frame headers, settings: nearly every integer in QUIC and HTTP/3 is written in the same format, so it is worth learning before reading a single packet header.
A QUIC variable-length integer spends the two most significant bits of its first byte on its own length. 00 means one byte, 01 two, 10 four and 11 eight. The remaining bits, in network byte order, are the value. Values up to 63 fit in a single byte, and the largest possible value is 262 − 1.
| First two bits | Length | Bits for the value | Range | Typical use |
|---|---|---|---|---|
00 | 1 byte | 6 | 0 to 63 | Frame types, small lengths, early stream IDs |
01 | 2 bytes | 14 | 0 to 16,383 | Packet lengths, most frame lengths |
10 | 4 bytes | 30 | 0 to 1,073,741,823 | Large offsets and flow-control limits |
11 | 8 bytes | 62 | 0 to 4,611,686,018,427,387,903 | Very large offsets and limits |
Examples from RFC 9000, Appendix A.1
Decoding takes two steps that never need a loop: read the top two bits of the first byte to learn the length, then mask them off and read the rest as a plain big-endian integer. Compare that with the LEB128 integers in WebAssembly or Protocol Buffers, where every byte has a continuation bit and you only find the end by reaching it. LEB128 wastes fewer bits; QUIC's format lets a parser know immediately how many bytes to grab, which suits code that has to process millions of packets a second.
The format allows non-minimal encodings, such as 40 25 for 37. That is occasionally useful: a sender can reserve a 2-byte length field before it knows the final length and fill it in afterwards. Frame types are the exception: they must use the shortest encoding, so every frame type below 64 is a single byte.
Inside a QUIC packet
A QUIC packet is a header followed by an encrypted payload, and the payload is a sequence of frames: STREAM, ACK, CRYPTO, PADDING and the rest you have met. The packet is the unit of encryption and acknowledgement; the frame is the unit of meaning and retransmission. QUIC has two header formats. The long header is for the handshake, when the endpoints still need to exchange versions and connection IDs. The short header is for everything after, and is as small as it can be.
First byte, before header protection 0xc3
- First byte
- VersionQUIC version 1
- DCID length
- Destination connection IDRandom, chosen by the client for now
- SCID lengthThe client chose an empty ID for itself
- Token lengthNo Retry or NEW_TOKEN token
- LengthVarint: 1,182 bytes of packet number + payload
- Packet number2, in 4 bytes
The client Initial from RFC 9001, Appendix A.2, before protection. Long headers carry both connection IDs, because the client has not yet learned the ID the server wants to receive on. The Length field lets several packets share one UDP datagram.
First byte, before header protection 0x41
- First byte
- Destination connection IDNo length field: the receiver chose the ID, so it knows the length
- Packet numberLow 16 bits of the full packet number
An illustrative 1-RTT header with an 8-byte connection ID: 11 bytes in all, against TCP's 20-byte minimum header. No version, no source ID and no length: the packet runs to the end of the datagram.
Truncated packet numbers
Packet numbers can climb to 262 − 1, but the header carries only the low 1 to 4 bytes. The receiver reconstructs the full number as the candidate closest to one more than the largest packet number it has received. In the example from RFC 9000, a receiver whose largest packet so far is 0xa82f30ea reads a 2-byte 0x9b32 as 0xa82f9b32. The sender picks a length that covers more than twice the distance between the packet it is sending and the largest one the peer has acknowledged, so the guess can never land on the wrong number.
Two layers of protection
The payload is sealed with an AEAD cipher (AES-128-GCM in the Initial packets; whichever TLS cipher suite was negotiated after that). The nonce is the packet number XORed into a per-direction IV, which is one more reason packet numbers must never repeat: reusing a nonce would break the cipher. The header is authenticated as associated data, so it cannot be altered in transit, but it is not encrypted by the AEAD.
A second step, header protection, then hides the packet number and the low bits of the first byte. The sender takes a 16-byte sample of the ciphertext, starting 4 bytes after the packet number begins (as if the packet number were always 4 bytes long), encrypts it with a separate header protection key, and XORs the first 5 bytes of the result into the header: the low 4 bits of a long header's first byte (5 bits for a short header) and the packet number bytes. The receiver does the same in reverse, starting from the sample, which it can read before it knows how long the packet number is.
Why bother hiding a counter? Because anything a middlebox can see, some middlebox will eventually depend on. Visible packet numbers would let networks track a connection across migrations, measure and interfere with loss recovery, and freeze the encoding forever. Hiding them keeps the internet's options open. The spin bit is the deliberate exception: an optional bit, flipped once per round trip, so that network operators can measure latency without seeing anything else.
Compute the Initial keys yourself
Initial packets are protected with keys derived from the client's chosen destination connection ID and a fixed salt published in RFC 9001. That means anyone who sees the first packet can derive the same keys and decrypt it. This is intentional: Initial protection exists to stop middleboxes from casually reading and ossifying the handshake, not to keep secrets. Real confidentiality starts with the Handshake keys, which come from the Diffie-Hellman exchange.
- initial_secret = HKDF-Extract(initial_salt, DCID)
- client_initial_secret = HKDF-Expand-Label(initial_secret, "client in", "", 32)
- key = HKDF-Expand-Label(client_initial_secret, "quic key", "", 16)
- iv = HKDF-Expand-Label(…, "quic iv", "", 12)
- hp = HKDF-Expand-Label(…, "quic hp", "", 16)
- mask = AES-ECB(hp, sample), first 5 bytes used
c3 00000001 08 8394c8f03e515708 00 00 449e 00000002 first byte: low 4 bits only 00000001 08 8394c8f03e515708 00 00 449e QUIC encrypts its payload and then hides its own header fields, leaving almost nothing on the wire for the network to read, depend on or tamper with.
Down to the UDP datagram
At the bottom, a QUIC packet is just the payload of a UDP datagram. UDP (RFC 768, from 1980) adds four 16-bit fields, source port, destination port, length and checksum, and nothing else: no connection, no ordering, no retransmission. That emptiness is exactly why QUIC chose it. Here is the client's first datagram from the handshake, as it would leave the phone over IPv4.
- IPv4: version 4, header 20 bytes0x45
- DSCP / ECN
- Total length1,228 = 20 + 8 + 1,200
- Identification
- Flags: Don't FragmentQUIC sets DF; fragments are not allowed
- TTL 64, protocol 17 (UDP)
- IPv4 header checksum0x3811, computed over these 20 bytes
- Source 192.0.2.10
- Destination 203.0.113.5
- UDP source port 51000Ephemeral, picked by the client
- UDP destination port 443
- UDP length1,208 = 8-byte header + 1,200 bytes of QUIC
- UDP checksumZero means none in IPv4; real stacks compute it, and IPv6 requires it
- QUIC: first byte (protected)Long header, Initial; low 4 bits masked
- Version 1
- DCID length + DCID
- SCID length (empty)
- Token length (no token)
- LengthVarint 1,182: packet number + payload
- Packet number (protected)Really 2, encoded in 4 bytes, masked
- Encrypted payload begins… 1,162 bytes of frames + 16-byte tag
Why 1,200 bytes
QUIC never lets IP fragment its packets: it sets the Don't Fragment bit on IPv4, and IPv6 routers never fragment anyway. So every QUIC packet has to fit in the smallest MTU along the path, which QUIC cannot know in advance. Its answer is a floor: every path that carries QUIC must accept UDP payloads of at least 1,200 bytes. That leaves room under the IPv6 minimum MTU of 1,280 bytes for the 40-byte IPv6 header, the 8-byte UDP header and a little slack for tunnels.
The client enforces that floor on its very first datagram. Any datagram carrying a client Initial must be at least 1,200 bytes, padded with PADDING frames (each just a zero byte) if the ClientHello is smaller. That one rule does two jobs: it proves early that the path can carry full-size QUIC packets, and it gives the server a 3,600-byte budget to send its first flight before the client's address is validated, under the three-times amplification limit.
The reverse problem, packets much smaller than the MTU, is solved by coalescing. Because long headers carry a Length field, several packets can share one datagram. A server's first datagram typically holds an Initial packet with the ServerHello followed by a Handshake packet with the start of the certificate, and a client's second flight can hold Initial, Handshake and 1-RTT packets in a single datagram. Only the last packet in a datagram may have a short header, since it has no length and runs to the end.
Why not a new IP protocol?
In principle a new transport gets its own IP protocol number, the way TCP is 6 and UDP is 17. SCTP (protocol 132) did exactly that and offers multiple streams, yet it barely exists on the public internet. Home routers that rewrite addresses and ports only know how to do it for TCP and UDP, firewalls drop what they do not recognise, and operating systems would all need new kernel code. Any new transport that wants to reach real users has to look like TCP or UDP on the wire. UDP is the one that leaves the payload alone.
Ossification
Even TCP cannot really change any more. Over decades, middleboxes such as firewalls, NATs, load balancers and traffic shapers learned to parse TCP headers, track sequence numbers and sometimes rewrite options. A new TCP option or a new use of an old field may be stripped, may get the connection dropped, or may work on one network and fail on the next. This is called When a protocol can no longer change in practice because deployed equipment depends on its current details, even details the specification never promised would stay fixed., and TCP Fast Open is the cautionary tale.
QUIC's defence is to show as little as possible. RFC 8999 lists the only properties QUIC promises to keep across all future versions: the high bit of the first byte selects long or short header; a long header carries a 32-bit version and length-prefixed destination and source connection IDs; a short header carries the destination connection ID right after the first byte; and version 0 means version negotiation. Everything else, including the fixed bit, packet numbers, frame formats and the handshake, may change in a new version. Most of it is encrypted, and implementations exercise the rest so networks cannot come to depend on it: RFC 9287 lets endpoints randomise the "fixed" bit, reserved version numbers are sent to keep version negotiation working, and QUIC version 2 (RFC 9369) exists largely to make sure the version field really does get used.
| TCP + TLS | QUIC | |
|---|---|---|
| Where the transport runs | Operating system kernel | A library inside the browser or server |
| How changes ship | OS updates, years to reach most devices | The next app release |
| Visible to the network | Ports, sequence and ack numbers, flags, window, options | Ports, header form, connection IDs, version (long header), spin bit |
| Encrypted | Application data only | Payload, packet numbers, ACKs, flow control, stream data |
| CPU cost per byte | Low: decades of tuning, segmentation offload in hardware | Higher: encryption per packet, more system calls, newer offloads like UDP GSO and GRO |
Running in user space is a trade. Each browser and many servers carry their own QUIC implementation, which means they can ship a better congestion controller or a bug fix in weeks, and tune it for their own traffic. It also means that operating systems had to learn to move UDP efficiently: batching system calls, and generic segmentation and receive offload so that the kernel and network card can treat a train of same-sized UDP datagrams as one large buffer. The CPU gap with TCP has narrowed, but it has not disappeared.
Back up the shaft
Follow GET https://example.com/ one last time, top to bottom. The browser learned from Alt-Svc or an HTTPS record that the server speaks h3. It encoded the request as a QPACK field section of 18 bytes, wrapped it in a 2-byte HEADERS frame header and wrote it to stream 0. QUIC put that into a STREAM frame, placed the frame into a packet with a fresh packet number, sealed it with keys from a handshake that cost one round trip, masked the header, and handed the result to UDP. If that packet is lost, only stream 0 waits; if the phone changes networks, the connection ID carries the conversation across.
QUIC rebuilt TCP's job above UDP and encrypted almost all of it, so that HTTP could finally get independent streams and the transport could keep evolving.
End of HTTP/3 · 10 levels, Idea to Machine
Where to next
Next in Web and networking · 05 of 12
HTTP caching, down to the disk
Open a news article twice. Follow its HTML, JavaScript, logo and comments through freshness checks, validators, service workers and the back/forward cache to see which requests ever reach a server.
Practical notes
SSE vs WebSockets vs long polling
Use SSE for server-to-page text updates, WebSockets for bidirectional streams, and long polling when ordinary request handling is the simplest fit.
Check whether a site uses HTTP/3
Check client support, inspect HTTP/3 advertisements, then confirm the actual connection protocol with curl or browser DevTools.