How the TLS Handshake Works (the Padlock Explained)

Every time you see the padlock in your browser, two strangers just agreed on a secret code in public -- without any eavesdropper figuring it out. Here is exactly how.

Build the path HTTPS travels in the lab

Free interactive lab. No signup. Runs in your browser.

Quick Summary

The Secret-Code-in-Public Analogy

Imagine two people who have never met, standing in a crowded room full of eavesdroppers. They need to share private information, but everyone can hear them. Amazingly, they can shout back and forth in front of the whole crowd and still agree on a secret code that nobody else can figure out. Once they have that shared code, they switch to it and talk freely -- fast, and completely private.

That is the magic of a TLS handshake. TLS, which stands for Transport Layer Security, is the technology that puts the "S" (and the little padlock) in HTTPS. Before your browser sends a single password or credit card number, it performs this handshake with the website's server to set up a secure channel.

The handshake gives you three guarantees. Encryption means eavesdroppers see only scrambled noise. Authentication means you can be sure you are really talking to the genuine bank.com and not an impostor -- the server proves its identity with a certificate signed by a trusted Certificate Authority (CA). And integrity means if anyone tampers with the data in transit, both sides notice immediately.

One important detail: TLS does not run on the bare network. It sits on top of TCP and only begins after the TCP three-way handshake has already established a reliable connection, usually on port 443. So a secure page load is really two handshakes back to back: first TCP, then TLS.

Where TLS Fits in a Secure Connection

Here is the journey from clicking a link to seeing the page. Notice that TCP sets up the pipe first, then TLS secures it, and only then does encrypted application data flow:

Anatomy of an HTTPS Connection (TLS 1.3) Client (Browser) Server (bank.com:443) PHASE 1 — TCP three-way handshake (the pipe) SYN → SYN-ACK → ACK PHASE 2 — TLS handshake (agree on the secret code) ClientHello + key share (ECDHE) ServerHello + Certificate + key share + Finished verify cert → client Finished PHASE 3 — Encrypted application data (symmetric key) 🔒 HTTP requests & responses, encrypted with AES-GCM / ChaCha20-Poly1305

Try It Yourself: TLS 1.3 Handshake Stepper

Step through a real TLS 1.3 handshake one message at a time. Watch which kind of cryptography is in play, and see the padlock close once the secure channel is ready.

💻 Client
Your browser
🏢 Server
bank.com : 443
Ready to begin. Press "Next" to start the handshake.
🔓 Channel not yet secured
A secure page load starts with TCP already connected. Click Next to walk through each TLS 1.3 message.
Step 0 of 6

Notice the clever trick at the heart of it: the slow, expensive asymmetric cryptography is used only briefly -- to authenticate the server and to agree on a shared secret. The moment both sides hold the same symmetric session key, they switch to it for everything else, because symmetric encryption is dramatically faster.

The TLS Handshake Step by Step

1

ClientHello: "Here's What I Support"

The client opens the conversation. It sends the highest TLS version it supports, a list of cipher suites (the encryption algorithms it can use), and -- in TLS 1.3 -- an ephemeral key share for Elliptic Curve Diffie-Hellman (ECDHE). Sending the key share this early is exactly why TLS 1.3 is so fast: it lets the secret be agreed on in a single round trip.

2

ServerHello + Certificate: "Here's Who I Am"

The server replies with the cipher it chose, its own key share, and its Certificate -- a document signed by a trusted Certificate Authority that vouches for the server's identity. It also sends a CertificateVerify signature, proving it holds the private key matching the certificate, plus a Finished message. Asymmetric crypto does the heavy lifting of authentication here.

3

Verify & Derive the Session Key

The client validates the certificate three ways: it checks the chain of trust up to a known CA, the validity dates, and that the hostname matches the site you visited. Then both sides combine their two ECDHE key shares to independently compute the same shared symmetric session key -- a secret that was never actually transmitted, only derived.

4

Finished, Then Encrypted Data

The client sends its own Finished message, now encrypted with the fresh session key. This confirms both sides computed identical keys and that nothing was tampered with along the way. From this moment on, all application data -- your HTTP requests and the server's responses -- is encrypted with fast symmetric crypto like AES-GCM or ChaCha20-Poly1305. The padlock appears.

TLS in the Real World

You rely on TLS dozens of times a day, usually without noticing. Here are three places it is doing its job:

💳

Online Banking

When you log in to your bank, the certificate proves you are really on bank.com and not a look-alike phishing site. The session key encrypts your password and balance so anyone sniffing the coffee-shop WiFi sees only scrambled bytes. The padlock is your visual cue that the handshake succeeded.

📱

App APIs & Mobile Apps

It is not just web pages. Mobile apps and microservices speak HTTPS to their APIs over the same TLS handshake. TLS 1.3's single round trip noticeably speeds up the first request, which matters when an app makes hundreds of API calls -- faster handshakes mean a snappier experience.

🔒

Free Certificates Everywhere

Services like Let's Encrypt issue free, automatically renewed certificates, which is why nearly the entire web is now HTTPS. A reverse proxy or load balancer often handles the TLS handshake at the edge ("TLS termination") so the backend servers do not each have to.

Common Mistakes & Misconceptions

TLS is widely misunderstood. Watch out for these traps:

⚠

"The Padlock Means the Site Is Safe"

The padlock only means the connection is encrypted and the certificate is valid for that hostname. A scam site can absolutely have a valid certificate. TLS proves you are talking privately to that server -- it does not prove the people running it are honest. Always check the actual domain name, not just the lock.

⚠

"SSL and TLS Are Different Things You Choose Between"

People say "SSL certificate," but SSL is the obsolete, insecure predecessor of TLS and should never be enabled. Modern connections use TLS 1.2 or TLS 1.3. If a server still allows old SSL or early TLS versions, that is a security weakness, not a feature -- TLS 1.3 deliberately dropped those outdated, breakable options.

⚠

"Asymmetric Crypto Encrypts All My Data"

A common beginner belief is that the public/private keys encrypt every byte. They do not. Asymmetric crypto is slow, so it is used only during the handshake to authenticate and agree on a key. The bulk data is encrypted with a fast symmetric key. Mixing these up makes the whole design seem mysterious when it is actually quite elegant.

Why Forward Secrecy Matters

Older TLS sometimes used the server's long-term key directly to protect the session secret. The danger: if an attacker recorded that encrypted traffic and the server's private key leaked years later, they could decrypt everything retroactively. Modern TLS fixes this with ephemeral Diffie-Hellman (ECDHE), which generates a brand-new, throwaway key pair for every single session.

Because the session key is derived from those temporary key shares -- not from the server's permanent key -- a future key leak cannot unlock yesterday's recorded sessions. This property is called forward secrecy, and in TLS 1.3 it is mandatory, not optional. It is one of the biggest reasons TLS 1.3 is considered both faster and safer than TLS 1.2, which needed two round trips and did not always guarantee it.

The bottom line: the TLS handshake is how two strangers agree on a private code in plain sight. Asymmetric crypto authenticates the server and bootstraps the secret; symmetric crypto then carries the conversation quickly. Once you see those two roles clearly, the padlock stops being magic and starts making perfect sense.

Frequently asked questions about the TLS handshake

What is a TLS handshake?

A TLS handshake is the short negotiation that happens before encrypted data flows over HTTPS. The client and server agree on a TLS version and cipher, the server proves its identity with a certificate signed by a trusted Certificate Authority, and both sides securely derive a shared symmetric session key. It runs on top of TCP after the three-way handshake, usually on port 443.

What is the difference between TLS and SSL?

TLS (Transport Layer Security) is the modern successor to SSL (Secure Sockets Layer). SSL versions are old and insecure and should never be used, but people still casually say "SSL" when they mean TLS. Today's secure connections use TLS 1.2 or, better, TLS 1.3. So an "SSL certificate" is really a TLS certificate.

How does HTTPS keep data secure?

HTTPS layers TLS on top of HTTP. TLS provides three guarantees: encryption so eavesdroppers cannot read your data, authentication so you know you are really talking to the genuine server via its certificate, and integrity so any tampering with the data in transit is detected. Together these put the "S" and the padlock in HTTPS.

Why does TLS use both asymmetric and symmetric encryption?

Asymmetric (public/private key) cryptography is great for authentication and for securely agreeing on a secret over an open channel, but it is slow. Symmetric cryptography like AES-GCM or ChaCha20-Poly1305 is very fast but needs both sides to share the same key. TLS uses asymmetric crypto during the handshake to authenticate and agree on a shared symmetric session key, then switches to fast symmetric crypto for the actual data.

What is forward secrecy?

Forward secrecy means that recording an encrypted session today is useless even if the server's long-term private key leaks tomorrow. Modern TLS achieves this with ephemeral Diffie-Hellman key exchange (ECDHE), which generates a fresh, throwaway key pair for every session. Because the session key is never derived directly from the server's permanent key, past sessions stay safe.

Build and trace the connection underneath

You just learned how TLS turns an open pipe into a private channel. The handshake itself stays in the stepper above; in the lab you build the network under it, a client, a load balancer and web servers, and trace the TCP connection that TLS would run over, end to end.

Launch the web stack lab →