Answers · The network and the web
Why does the TLS handshake take so many round trips before any data is sent?
In shortIt is not one key exchange. The handshake agrees a secret, proves the server's identity and checks for tampering, and modern TLS fits those into one round trip; a fresh connection still needs three before the page starts.
A fresh TLS connection takes three round trips before the first byte of a page arrives: one to open the transport connection, one for the handshake, and one for the request and response. The handshake itself is one round trip in modern TLS, not because key exchange is slow, but because its messages do three separate jobs: agree a secret, prove who is answering, and confirm that nothing in the handshake was altered.
Put the cost in one line. Let be the round trip time and the server's working time after the request arrives. The delay before the first byte is , where is the number of round trips before the request can be answered. The term that hurts is the product : a server can often produce a page in tens of milliseconds, while one crossing between continents is ms or more.
On a connection with ms and ms, a fresh connection has : transport connected at ms, handshake finished at ms, request arrives at ms, and the response starts at ms. That is ms before the first byte. Two thirds of the delay is setup, and only ms is the server doing anything with the request.
Three jobs, not one
The messages look numerous because each one has a different job. The client's first flight carries supported versions, cipher suites, and a key share for the group it guesses the server will accept. The server's reply carries its own key share and the chosen version and cipher. From those two shares both sides compute the same secret, and everything after the server's reply is encrypted. The server then sends its certificate chain, a signature over the transcript so far, and a finished value. The client validates the chain, checks the signature, and sends its own finished value before the request.
The natural mistake is to treat the whole handshake as one key exchange with extra packaging. If that were true, the certificate and signature would be redundant. A certificate is a public document, so presenting it proves only that the sender has a copy of it. The signature is what proves possession of the matching private key, and it is computed over every byte of the handshake so far, including the client's fresh key share. An attacker replaying a recorded certificate and signature into a new conversation would be signing a different transcript, and the check would fail. The finished messages then cover the whole transcript with the derived keys, so any alteration anywhere in the handshake shows up at the end.
Several messages do not mean several round trips. The server can put its key share, certificate, signature and finished value into one flight, and the client's first flight is one crossing in the other direction. The handshake costs one round trip because the client guesses the key agreement group in its first message rather than negotiating it. Older designs asked which group to use, waited for the answer, then sent a share, which added exactly one round trip. The guess is right almost always, and a wrong guess costs a retry rather than a redesign.
When the count falls
Resumption removes the identity exchange but not the crossing. After a successful handshake the server can give the client a ticket, an encrypted record of the secret to use next time. On a later visit the client sends the ticket in its first message, both sides derive keys from the remembered secret, and the certificate, signature and chain validation disappear. The handshake still costs one round trip, but with much less work. Early data removes the crossing itself: a resuming client attaches application data to its first message, encrypted under the remembered secret, before hearing anything from the server in this conversation. The page can then start coming back in one round trip instead of two.
The cost of early data is exact. The client has not yet seen a value chosen by the server for this conversation, so the first message has no freshness. An attacker who records it can send the same bytes again later, and the server cannot tell the difference. That makes early data safe for a request whose repetition is harmless, which is most page reads, and unsafe for anything that changes state or moves money. The zero round trip figure also assumes a ticket is already held; without resumption the full handshake is still one round trip. And the one round trip handshake figure assumes modern TLS with the key share guess; an older handshake that negotiates the group first pays two.
Worth keeping
- Each handshake message serves either key agreement, identity, or integrity, and none of them is a duplicate of another.
- The number of messages is not the number of round trips, because a server can pack its share, certificate, signature and finished value into one flight.
- Early data saves a round trip at the price of replayability, so it is only safe for requests with no side effects.
Where this goes next
This question is one step of How a Message Stays Private, a course that works through its subject from the beginning. The page that teaches this part of it is The Whole Handshake, and it reads the whole way through whether or not you have an account.
What an account changes is the practice: problems standing under every idea, marked with a reason rather than a tick, in a copy of the course that is yours.
Read that pageThe whole courseOther questions people ask about this
- If a website has HTTPS, can someone on the same Wi-Fi read my password?No. HTTPS encrypts the form contents and cookies, so someone on the same Wi-Fi cannot read the password itself; they can still see the site, timing and packet sizes.
- How can two computers agree on a secret key when anyone can listen?Each computer sends a scrambled number made from a private number; the shared key is made by scrambling the other computer's number with one's own private number, and a listener cannot unscramble it.
- How does a man-in-the-middle attack still work if the key exchange is secure?A key exchange proves only that you share a secret with whoever answered. An attacker on the path answers you themselves and opens a second exchange to the real server, so both halves look secure.
- Does HTTPS hide the domain name of the site I'm visiting from my ISP?Usually not: the site's name is sent in readable form twice, once when your computer looks up its address and once when the secure connection opens.
- Where should a session ID be stored so JavaScript can't read it?Store it in an HttpOnly cookie set by the server; that is the only browser storage JavaScript running on the page cannot read.
- What does it mean for an API method to be safe?A safe method is one that changes nothing on the server when it is called, so a caller may repeat it freely and a cache or a crawler may use it without anything being altered.