The TLS Handshake, Step by Step
Follow a TLS 1.3 handshake message by message, see how it differs from TLS 1.2, and learn how to inspect and troubleshoot it yourself.
Key takeaways
- The handshake negotiates settings, establishes shared keys and authenticates the server before application data is trusted.
- TLS 1.3 completes a full handshake in one round trip, compared with two for a typical full TLS 1.2 handshake.
- Most of the TLS 1.3 handshake after the first two messages is already encrypted, including the server's certificate.
- Session resumption makes return visits cheaper, and early data can skip the wait at the cost of replay risk.
- Handshake failures usually come from version mismatches, certificate problems, wrong server names or interference.
The TLS handshake is the short conversation that happens before any private data moves. In it, your browser and a server agree on a protocol version and cipher, create shared secret keys, and the server proves its identity with a certificate. In TLS 1.3 this takes one round trip.
Once you know the handful of messages involved, handshake errors, slow connection setup and server settings all become much easier to reason about.
Where the handshake fits
Loading a secure page happens in stages. First DNS finds the address. Then, over TCP, the three-way handshake opens a connection. Then TLS runs on top. Only after that does the browser send its HTTP request.
With HTTP/3, the transport is QUIC, which merges the transport and TLS 1.3 handshakes so that a new connection needs fewer round trips overall.
The TLS 1.3 handshake
TLS 1.3 is defined in RFC 8446. Here is a full handshake with no previous session.
Step 1: ClientHello
The browser opens with a list of what it can do: supported TLS versions, cipher suites and signature algorithms. It includes one or more key shares, which are its half of the key exchange, sent optimistically before knowing the server's choice.
Two extensions matter a lot in practice. Server Name Indication (SNI) states which hostname the browser wants, so a server hosting many sites can pick the right certificate. ALPN (Application-Layer Protocol Negotiation) lists the application protocols the browser speaks, such as h2 for HTTP/2 or http/1.1.
The message also carries random bytes that make this session's keys unique.
Step 2: ServerHello
The server picks a version and cipher suite and returns its own key share and random value. Both sides can now compute the same shared secret and derive handshake encryption keys from it. Everything after ServerHello is encrypted.
If the browser guessed wrong and sent no key share the server can use, the server replies with a HelloRetryRequest naming an acceptable group. The browser sends a new ClientHello, costing one extra round trip.
Step 3: EncryptedExtensions and Certificate
EncryptedExtensions holds settings that don't need to be visible, such as the selected ALPN protocol. Then the server sends Certificate: its own certificate plus the intermediate certificates needed to build a chain to a trusted root.
Step 4: CertificateVerify
A certificate is public, so presenting it proves nothing by itself. In CertificateVerify, the server signs a hash of the handshake so far with its private key. The browser checks that signature using the public key in the certificate. Only the holder of the private key could produce it, and because it covers this handshake, it can't be replayed from another one.
Step 5: Finished, in both directions
Each side sends Finished, a keyed checksum over the entire handshake. If an attacker altered anything, such as trimming the list of ciphers to force a weaker one, the values won't match and the connection is aborted.
The server can send its Finished in the first flight. The browser verifies everything, sends its own Finished, and can attach the HTTP request right behind it.
What the browser checks along the way
While processing the certificate, the browser asks several questions.
Certificate chains and browser certificate errors cover these checks in depth.
How TLS 1.2 differs
TLS 1.2 is still widely supported. Its full handshake has more back and forth:
- ClientHello.
- ServerHello, Certificate, ServerKeyExchange (for ephemeral key exchange) and ServerHelloDone.
- ClientKeyExchange, ChangeCipherSpec and Finished from the client.
- ChangeCipherSpec and Finished from the server.
That is two round trips before the request can go, and the certificate travels unencrypted. TLS 1.2 also permits older options, including an RSA key exchange without forward secrecy. TLS 1.3 removed those and cut the cipher suite list to a short set of authenticated encryption algorithms.
A cipher suite name shows the difference. A TLS 1.3 name such as TLS_AES_128_GCM_SHA256 names only the encryption and hash, because key exchange and signature are negotiated separately. A TLS 1.2 name such as TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 bundles all of it.
Resumption and early data
After a handshake, a TLS 1.3 server can send a session ticket. On the next visit, the browser presents it as a pre-shared key. The server can then skip sending its certificate, which saves bytes and computation. Browsers usually combine this with a fresh key exchange so forward secrecy is retained for new data.
TLS 1.3 also allows 0-RTT, or early data: the browser sends a request alongside its ClientHello using keys from the earlier session. It saves a round trip, but an attacker who captures that first flight may be able to send it again. Servers should accept early data only for requests that are safe to repeat, such as simple reads, or disable it. HTTP has a 425 Too Early status for declining such requests.
How the session keys come to be
Neither side ever sends the key that protects your data. Each combines its own temporary private value with the other side's public key share, and the mathematics gives both the same result. TLS 1.3 then runs that shared secret through a key derivation function, a standard recipe that stretches it into several separate keys.
The derivation mixes in a hash of the messages exchanged so far, so the keys are bound to this particular conversation. There are different keys for the handshake and for application data, and different ones for each direction. A long-lived connection can also update its keys without starting over.
This layering limits damage. A key used in one direction or phase doesn't hand over the earlier secrets it came from, and once the connection ends and the temporary values are erased, the server's long-term private key can't recreate them.
Hostnames in the clear
SNI has to arrive before any keys exist, so in a standard handshake the hostname is readable on the network. That is how some filters decide what to block without decrypting anything. Encrypted Client Hello addresses this by encrypting the sensitive parts of the ClientHello to a public key that the site publishes in DNS, through HTTPS records. The outer message shows only a shared, generic name belonging to the hosting provider. Support depends on the browser, the server and how the DNS lookup is made, so don't assume it is active on any given site.
What the handshake costs
The delay depends mostly on distance. Each round trip to a far-off server adds time that more bandwidth can't remove, as latency limits explain.
Hypothetical example: the numbers are made up to show the method, not a quote or an average.
These figures ignore processing time and lost packets. To reduce real-world cost, enable TLS 1.3 and resumption, keep connections alive, keep the certificate chain lean and serve from locations near users, for instance through a CDN.
Inspect a handshake yourself
OpenSSL shows what a server negotiates:
openssl s_client -connect example.com:443 -servername example.com -tls1_3 </dev/null Add -msg to list handshake messages as they pass, or -alpn h2 to offer HTTP/2. With curl, you can see timing for each phase:
curl -so /dev/null -w "connect %{time_connect}\ntls %{time_appconnect}\n" https://example.com/ The difference between the two numbers is roughly the time TLS took. In browser developer tools, the network panel's timing view shows the same phases for each new connection.
When handshakes fail
Common patterns and where to look:
- Protocol version or cipher mismatch. The client and server share nothing in common, often because one is very old.
- Wrong certificate served. The client sent no SNI, or the server has no matching virtual host and fell back to a default.
- Incomplete chain. The server omits an intermediate. Some browsers cope, while command-line tools and apps fail.
- Connection reset during ClientHello. A firewall, filter or security product may be interfering.
- Wrong port or protocol. Speaking TLS to a plain HTTP port produces confusing "wrong version number" style errors.
- Incorrect device clock. Valid certificates then appear expired or not yet valid.
Server error logs often name the alert that was sent, such as unknown ca or handshake failure, which tells you which side objected.
Common questions
Does the handshake use the certificate's key to encrypt data?
In TLS 1.3, no. The certificate key is used for signing. The data keys come from the ephemeral key exchange.
Can the client also present a certificate?
Yes. This is mutual TLS. The server sends a CertificateRequest, and the client answers with its own certificate and signature. It's common between services and in managed environments, and rare for public websites.
Is a new handshake needed for every request?
No. One connection carries many requests. With HTTP/2 and HTTP/3, many can run at the same time over it.