How HTTPS keeps a connection private
HTTPS is HTTP carried over TLS, a protocol that gives two computers a private channel across a network they do not trust. The one idea to keep: before the first byte of the page is sent, browser and server agree on a secret key that nobody on the path can see.
The short version
The browser and the server exchange a few messages called the handshake. Each side sends a public piece of a key, and from the two pieces both compute the same secret without ever sending it. The server also shows a certificate and signs the conversation so far, which proves it owns the name in the address bar. From then on, every request and response is encrypted with that secret.
Step by step
- The browser sends a ClientHello: a random value, the cipher suites it supports, and its share of a fresh key.
- The server answers with a ServerHello and its own key share. Each side combines its secret with the other's share and gets the same key. Everything after this point is encrypted.
- The server sends its certificate and a signature over the handshake, made with the private key that belongs to the certificate. The browser checks the certificate against the name it asked for.
- Both sides send a Finished message, a checksum over the whole handshake, so a tampered message is caught.
- Only now does HTTP start. Headers and bodies travel encrypted in both directions.
Why it matters
This is why a shared Wi-Fi can see which server you talk to, but not the pages or the form data. It is also why an expired or mismatched certificate stops the page: step 3 failed, so the browser refuses to continue.
Sources
- RFC 9846, The Transport Layer Security (TLS) Protocol Version 1.3 — authentication, confidentiality and integrity goals (section 1); ClientHello random and key share, ServerHello key share, "everything after this phase is encrypted", Certificate, CertificateVerify signature, Finished as a MAC over the handshake, no application data before Finished (section 2)
- MDN, Transport Layer Security — HTTPS is HTTP over TLS; the certificate binds the server's key to its domain name; headers and bodies are encrypted after the handshake