Skip to content
Visual explainer 2h to learn 4 steps

HTTP/2 & HTTP/3

Explain how multiplexing, header compression and QUIC improve on HTTP/1.1.

By Invicly Tech, , in Computer Networking. About 11 minutes to read.

Topic 28 of 51

In short

HTTP/2 keeps HTTP semantics but sends binary frames, multiplexing many requests over one TCP connection with compressed headers. A lost TCP packet still stalls all streams, so HTTP/3 moves to QUIC over UDP, where each stream recovers independently. Browsers negotiate the version automatically.

Explained simply

HTTP/2 and HTTP/3 do not change what HTTP means. GET is still GET, 404 is still 404, and headers work the same way. What changes is how the messages are packed and carried across the network, which makes pages load faster, especially when a page needs dozens of files.

HTTP/1.1 is like a single-lane road: one car (request) at a time per connection. HTTP/2 turns one connection into a multi-lane road: many requests travel at once as small numbered pieces called frames, and the other side puts them back together. This is called multiplexing.

There is still a catch. HTTP/2 runs on TCP, and TCP delivers bytes strictly in order. If one packet is lost, everything behind it waits, even data for other requests. HTTP/3 fixes this by running on QUIC, a newer transport built on UDP, where each request has its own lane and a loss in one does not hold up the others.

You rarely choose the version yourself. Browsers and servers agree on it automatically during connection setup. Your job as an engineer is to enable the newer versions on your servers or CDN and know how to check which one is actually used.

Press Play on a diagram to walk through it one step at a time.

CompareHTTP versions
HTTP/1.1
  • Text protocol over TCP
  • One request at a time per connection
  • Browsers open about 6 connections
  • Uncompressed headers
HTTP/2
  • Binary frames over TCP
  • Many streams on one connection
  • HPACK header compression
  • TCP head-of-line blocking remains
HTTP/3
  • Runs over QUIC on UDP
  • Independent streams
  • QPACK header compression
  • Faster setup, survives network changes
LayersProtocol stacks side by side (HTTP/3 vs HTTP/2)
  1. 1
    HTTP semantics

    Same methods, status codes and headers

  2. 2
    HTTP/3 framing or HTTP/2 framing

    QPACK on HTTP/3, HPACK on HTTP/2

  3. 3
    QUIC streams or TLS 1.3

    QUIC includes TLS 1.3 inside itself

  4. 4
    UDP or TCP

    HTTP/3 uses UDP, HTTP/2 uses TCP

  5. 5
    IP

    Identical for both

In depth

Frames and streams in HTTP/2

Everything in HTTP/2 is a frame with a 9-byte header: a 24-bit length, an 8-bit type, 8 bits of flags, and a 31-bit stream ID. A stream is one request and its response. Client-started streams use odd numbers (1, 3, 5...), and stream 0 is reserved for connection-wide control. A request becomes a HEADERS frame (plus CONTINUATION frames if headers are large) and optional DATA frames.

Other frame types do housekeeping. SETTINGS exchanges limits, such as the maximum number of concurrent streams. WINDOW_UPDATE drives flow control, so a fast sender cannot flood a slow reader; the initial window is 65,535 bytes. PING checks the connection is alive. RST_STREAM cancels one stream without closing the connection. GOAWAY tells the peer to stop opening new streams, which lets servers shut down gracefully.

Headers change form too. The request line becomes pseudo-headers: :method, :scheme, :authority (replacing Host) and :path, and the response uses :status. All header names are lowercase.

  • HEADERS and DATA carry requests and responses
  • SETTINGS and WINDOW_UPDATE control limits and flow
  • RST_STREAM cancels one stream; GOAWAY winds down the connection

Header compression: HPACK and QPACK

Requests to the same site repeat nearly the same headers every time: user-agent, cookies, accept headers. In HTTP/1.1 they are resent as plain text on every request, often hundreds of bytes. HPACK, used by HTTP/2, compresses them in three ways: a static table of 61 common header fields, a dynamic table that both sides build as headers are seen, so a repeated header becomes a tiny index number, and Huffman coding for new strings.

The dynamic table depends on order: both sides must process headers in exactly the same sequence. That is fine on TCP, which is strictly ordered, but QUIC streams arrive independently. So HTTP/3 uses QPACK, which sends table updates on separate one-way encoder and decoder streams and lets the encoder choose whether a header may wait for a table update. This keeps compression without bringing back head-of-line blocking.

Why QUIC, and what it brings

QUIC (RFC 9000) runs over UDP, usually on port 443, and puts reliability, congestion control and encryption into the transport itself. TLS 1.3 is built in, so connection setup and encryption happen together in one round trip, instead of a TCP handshake followed by a TLS handshake. On a repeat visit, 0-RTT lets the client send its first request immediately.

Each QUIC stream is delivered on its own, so a lost packet only delays the streams whose data was in it. QUIC also identifies connections by connection IDs instead of the IP address and port pair. When a phone moves from Wi-Fi to mobile data and its IP changes, the connection can survive instead of starting over.

The costs: UDP is blocked or throttled on some corporate networks, so clients must fall back to HTTP/2 over TCP. QUIC runs in user space and encrypts almost all its headers, which uses more CPU and gives middleboxes less to inspect.

CompareConnection setup before the first request
HTTP/2 over TCP + TLS 1.3
  • TCP handshake: 1 round trip
  • TLS 1.3 handshake: 1 round trip
  • Request sent after 2 round trips
  • Loss stalls all streams
HTTP/3 over QUIC
  • QUIC and TLS together: 1 round trip
  • 0-RTT possible on repeat visits
  • Loss stalls only affected streams
  • Survives IP changes

How the version gets chosen

For HTTP/2, the choice happens inside the TLS handshake using ALPN (Application-Layer Protocol Negotiation). The client lists what it speaks, such as h2 and http/1.1, and the server picks one. Browsers only use HTTP/2 over TLS; plain-text HTTP/2 (h2c) exists but is used only between servers.

HTTP/3 cannot be negotiated inside a TCP connection, because it does not use TCP. So the server advertises it. It sends a header like Alt-Svc: h3=":443"; ma=86400 over HTTP/2 or HTTP/1.1, meaning: HTTP/3 is available on UDP port 443, remember this for a day. The browser tries QUIC on later connections. An HTTPS DNS record can advertise h3 even before the first connection. If QUIC fails, the browser quietly uses TCP instead, which is why the first visit to a site is often HTTP/2 and later ones HTTP/3.

SequenceUpgrading from HTTP/2 to HTTP/3
Browser
Server
  1. 1TLS ClientHello, ALPN: h2, http/1.1
    Browser to Server: TLS ClientHello, ALPN: h2, http/1.1
  2. 2ServerHello, ALPN chosen: h2
    Server to Browser: ServerHello, ALPN chosen: h2
  3. 3HTTP/2 GET /
    Browser to Server: HTTP/2 GET /
  4. 4200 OK, Alt-Svc: h3=":443"
    Server to Browser: 200 OK, Alt-Svc: h3=":443"
  5. 5Next visit: QUIC Initial on UDP 443
    Browser to Server: Next visit: QUIC Initial on UDP 443
  6. 6HTTP/3 responses over QUIC
    Server to Browser: HTTP/3 responses over QUIC

What changes for you in practice

Some old performance habits now hurt. Domain sharding splits traffic across connections and defeats multiplexing and header compression. Huge bundles mean a tiny code change invalidates the whole cached file. Moderate bundling is still fine, but you no longer need to squeeze everything into one file.

Server push, an HTTP/2 feature that let servers send files before they were asked for, was rarely a win and browsers such as Chrome have removed support; use preload links or 103 Early Hints instead. Priorities changed too: the original HTTP/2 priority tree was replaced by the simpler Priority header (RFC 9218).

Multiplexing also changed the threat picture. In 2023, the Rapid Reset attack (CVE-2023-44487) abused opening and instantly cancelling streams with RST_STREAM to overload servers. Keep your web server and proxies patched and set sensible limits on concurrent streams.

Learn it in 4 short steps

About 30m each. Track them with a timer in your plan.

  1. 1
    Explain binary framing and streams~30m
  2. 2
    Explain HPACK and QPACK compression~30m
  3. 3
    Explain why HTTP/3 uses QUIC~30m
  4. 4
    Check the protocol version with curl~30m

Key points

  • Methods, status codes and headers are the same across versions.
  • HTTP/2 is negotiated during the TLS handshake via ALPN (h2).
  • HTTP/3 is advertised with the Alt-Svc header, then used on later connections.
  • Bundling and domain sharding hacks matter less with HTTP/2 and later.

Key terms

Tap a card to flip it. 0/4 known

Examples

bash
curl -sI --http2 https://www.cloudflare.com | head -1     # HTTP/2 200
curl -sI https://www.cloudflare.com | grep -i alt-svc       # h3 advertised
curl -w '%{http_version}\n' -so /dev/null https://example.com

Checking which version a site uses

You enabled HTTP/3 on your CDN and want proof. Step 1: check the version curl negotiates by default over TLS. Step 2: look for the Alt-Svc header that advertises h3. Step 3: force HTTP/3 with --http3 (your curl must be built with HTTP/3 support; curl -V lists HTTP3 under Features if so). In the browser, open developer tools, Network tab, and turn on the Protocol column: you will see h2 or h3 per request.

bash
curl -so /dev/null -w '%{http_version}\n' https://www.cloudflare.com
# 2
curl -sI https://www.cloudflare.com | grep -i alt-svc
# alt-svc: h3=":443"; ma=86400
curl -V | grep -o HTTP3
curl --http3 -so /dev/null -w '%{http_version}\n' https://www.cloudflare.com
# 3

Enabling HTTP/2 and HTTP/3 in nginx

Recent nginx versions (1.25.1 and later) use a separate http2 on directive and support QUIC with listen ... quic. Step 1: listen on TCP 443 for HTTP/1.1 and HTTP/2, and on UDP 443 for HTTP/3. Step 2: advertise HTTP/3 with Alt-Svc. Step 3: open UDP 443 in every firewall in the path, which is the step people forget. Then repeat the curl checks above.

nginx
server {
    listen 443 ssl;
    listen 443 quic reuseport;
    http2 on;
    server_name example.com;
    ssl_certificate     /etc/ssl/example.com/fullchain.pem;
    ssl_certificate_key /etc/ssl/example.com/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    add_header Alt-Svc 'h3=":443"; ma=86400' always;
}

Quick reference

  • ALPN values: h2 for HTTP/2, http/1.1 for HTTP/1.1, h3 for HTTP/3 over QUIC
  • HTTP/3 needs UDP 443 open; without it clients fall back to TCP
  • curl -w '%{http_version}' prints the version used; --http3 forces HTTP/3
  • HTTP/2 pseudo-headers: :method, :scheme, :authority, :path, and :status
  • Alt-Svc: h3=":443"; ma=86400 advertises HTTP/3 for a day
  • Skip domain sharding and server push with HTTP/2 and later; use preload or 103 Early Hints
  • Client-initiated HTTP/2 streams have odd IDs; stream 0 is the connection itself

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1Why can HTTP/2 still suffer head-of-line blocking?

Question 2

2Why does HTTP/3 use QPACK instead of HPACK?

Question 3

3How does a browser first learn that a server supports HTTP/3?

Question 4

4Which feature lets a QUIC connection survive a phone switching from Wi-Fi to mobile data?

0/4 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Open three big websites in your browser and record which HTTP version each request uses.

  2. Exercise 2medium

    Use openssl to see which application protocol a server picks with ALPN when you offer h2 and http/1.1.

  3. Exercise 3hard

    Compare connection setup time for HTTP/1.1, HTTP/2 and HTTP/3 to the same far-away site, and explain the difference.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Do I need to change my application code for HTTP/2 or HTTP/3?
Usually not. The web server, load balancer or CDN handles the protocol, and your app sees the same requests. You may remove old hacks like domain sharding.
Is HTTP/3 always faster?
It helps most on lossy or high-latency networks such as mobile. On a clean, fast network the difference is small, and where UDP is blocked clients fall back to HTTP/2.
Why does curl show HTTP/2 even though the site supports HTTP/3?
curl does not use Alt-Svc information by default, and many builds lack HTTP/3 support. Use --http3 with a build that lists HTTP3 in curl -V.

Go deeper

ShareXLinkedInWhatsApp