What is HTTP/2?
HTTP/2 keeps everything you know about HTTP, such as methods, status codes and headers, but changes how they travel. Instead of text lines, each message is cut into small binary frames, and many requests share one connection at the same time, each on its own numbered stream.
A modern page loads dozens of files. HTTP/1.1 had to ask for them one at a time per connection. HTTP/2 sends them all together and compresses repeated headers, so pages load with fewer connections and less waiting. Browsers use it only over HTTPS.
Think of it like this. HTTP/1.1 is a single checkout lane where each customer must finish before the next starts. HTTP/2 is one cashier serving several customers at once, scanning a few items for each in turn. But they still share one conveyor belt: if something falls off the belt, everyone waits until it is put back.
Step by step
Normal
4 stepsLoading one page over HTTP/2: TLS picks h2, settings are swapped, then a request becomes frames on stream 1.
Normal
4 stepsLoading one page over HTTP/2: TLS picks h2, settings are swapped, then a request becomes frames on stream 1.
- 1
TLS picks h2
Version agreed in the handshake
The browser lists h2 and http/1.1 in the ALPN extension of its Client Hello. The server answers h2, so HTTP/2 starts with no extra round trip.
- 2
Preface and settings
Both sides state their limits
The browser sends a fixed 24-byte preface, then a SETTINGS frame. The server sends its own SETTINGS and acknowledges. These are like house rules for the connection.
- 3
Request as frames
HEADERS on stream 1
The request is no longer text lines. Its headers are compressed with HPACK and put in a binary HEADERS frame on stream 1.
- 4
Response as frames
HEADERS then DATA on stream 1
The server answers on the same stream with a HEADERS frame (status 200) and DATA frames for the body. END_STREAM marks the last one.
Many at once
4 stepsThe page needs a stylesheet, a script and a picture. All three go out at once and come back mixed together.
Many at once
4 stepsThe page needs a stylesheet, a script and a picture. All three go out at once and come back mixed together.
- 1
Three requests
Streams 3, 5 and 7 open together
With HTTP/1.1 the browser would wait for each answer or open up to six connections. With HTTP/2 it sends all three requests back to back on one connection.
- 2
Tiny repeat headers
HPACK remembers
Most headers are the same as in the first request. HPACK sends them as small index numbers, so the second and third requests are only a few dozen bytes.
- 3
Answers interleaved
Frames from different streams take turns
The server slices each file into DATA frames and mixes them. A big picture no longer holds up a small stylesheet.
- 4
Each stream ends
END_STREAM per file
Each response ends on its own. The browser puts the frames of each stream back together using the stream ID.
One packet lost
4 stepsHTTP/2's weak spot: one lost TCP segment stalls every stream, even ones whose data already arrived.
One packet lost
4 stepsHTTP/2's weak spot: one lost TCP segment stalls every stream, even ones whose data already arrived.
- 1
Three streams flowing
Frames for streams 3, 5 and 7
The server sends frames for three files in a row of TCP segments, as in the last scenario.
- 2
A segment is lost
Only stream 5's frame is missing
Busy Wi-Fi drops the segment holding a DATA frame of the script. The segments after it, with stylesheet and picture data, arrive fine.
- 3
Everyone waits
TCP holds the bytes back
TCP must hand over bytes in order, so it keeps the later segments in a buffer. HTTP/2 cannot see them, so streams 3 and 7 stall too. This is TCP head-of-line blocking.
- 4
Resent and released
One round trip later
Duplicate ACKs tell the server a gap exists. It resends the missing segment and all three streams move again. HTTP/3 on QUIC removes this stall.
Myths and mix-ups
- HTTP/2 changes what requests mean; it only changes how they are packed and sent.
- HTTP/2 needs one connection per file; it carries many files over a single connection.
- Server push is a key HTTP/2 speed feature; major browsers have removed support for it.
- Merging files into bundles is still essential; with HTTP/2 many small files cost far less than before.
- HTTP/2 fixed head-of-line blocking completely; it fixed it for HTTP but not for TCP underneath.
Try it yourself
Run these on your own computer to see HTTP/2 at work.
Ask for HTTP/2
curl -sI --http2 https://example.com/ | head -1The first line shows HTTP/2 when the server supports it.
Watch the frames
curl -v --http2 https://example.com/ -o /dev/nullLook for ALPN: server accepted h2 and the stream number of your request.
In the browser
F12, Network tab, right-click a column header, tick ProtocolThe new column shows h2 next to every file loaded over HTTP/2.
HTTP/2 at a glance
- Layer
- Application (7)
- Port
- 443 (inside TLS)
- Transport
- TCP
- Format
- Binary frames with a 9-byte header
- Header compression
- HPACK (RFC 7541)
- Version chosen by
- TLS ALPN token h2
- Published
- 2015, updated in 2022
Defined inRFC 9113RFC 7541RFC 9110RFC 7301
Header fields
What HTTP/2 puts in its messages, with example values from the stories above.
HTTP/2 WINDOW_UPDATE
- Length
4- Type
WINDOW_UPDATE (0x8)- Flags
0x00- Stream ID
0Stream 0 is the connection itself, used for settings and control.- Window increment
15663105Flow control: how many more bytes the server may send before waiting.
HTTP/2 SETTINGS
- Length
0- Type
SETTINGS (0x4)- Flags
0x01 (ACK)- Stream ID
0Stream 0 is the connection itself, used for settings and control.
HTTP/2 HEADERS
- Length
54- Type
HEADERS (0x1)- Flags
0x25 (END_STREAM, END_HEADERS, PRIORITY)- Stream ID
1Each request gets its own stream number. Browsers use odd numbers: 1, 3, 5 and so on.- Header block
HPACK compressed, 54 bytesThe same headers in HTTP/1.1 text would take several hundred bytes.
Test yourself
How does a browser and server agree to use HTTP/2?
Questions people ask
What is the difference between HTTP/1.1 and HTTP/2?
HTTP/1.1 sends one text request at a time per connection. HTTP/2 sends binary frames, runs many requests at once on one connection and compresses headers.
Does HTTP/2 require HTTPS?
The standard allows plain HTTP/2, but browsers only use it over HTTPS. In practice HTTP/2 on the web means HTTPS on port 443.
How do I check if a website uses HTTP/2?
Run curl -sI --http2 on the address, or open the browser's Network tab and turn on the Protocol column. You will see h2.
Is HTTP/2 faster than HTTP/1.1?
Usually, for pages with many files, because it avoids queues and extra connections. On very lossy networks it can stall, which is what HTTP/3 improves.
What happened to HTTP/2 server push?
It let a server send files before the browser asked. It rarely helped and was hard to use well, so major browsers removed it. Early hints (status 103) are the usual replacement.