↓ Skip to main content
  1. Articles/

How TLS and HTTPS Actually Work

▶ Present this article as 11 slides you can share, or browse all decks.

⚙ Try it live: Crypto & JWT Playground · also Encryption Pipeline Builder Generate key pairs, sign and verify, and run key exchanges in your browser: the building blocks a TLS handshake is made of.

Working on something like this? Ask me. Questions about your setup, or anything this article didn't cover. No account needed, private by default.

Only I read it. It isn't published unless you tick the box, and your email is never shown or added to any list. Privacy

The padlock in the address bar is so familiar that most people never ask what it means. Behind it sits TLS, Transport Layer Security, the protocol that protects almost every connection your browser, your API clients and your database drivers make. HTTPS is simply HTTP carried inside a TLS connection. This article explains what TLS actually guarantees, how a TLS 1.3 handshake works, and how certificates turn “encrypted” into “encrypted, and talking to the right server”.

What TLS Gives You
#

TLS provides three properties:

  • Confidentiality: nobody between client and server can read the traffic.
  • Integrity: nobody can change the traffic without being detected.
  • Authentication: the client knows it is talking to the server it intended, not an impostor. Optionally, the server can authenticate the client too.

The third property is the one people forget, and it is the one certificates exist for. Encryption with an unknown party is not much use: an attacker who intercepts your connection would happily encrypt everything for you and read it on their side.

The TLS 1.3 Handshake
#

Before any application data flows, client and server run a handshake. TLS 1.3 (RFC 8446) completes it in a single round trip:

sequenceDiagram
  participant C as Client
  participant S as Server
  C->>S: ClientHello
supported versions, cipher suites
key_share (client's ephemeral public key)
server_name (SNI): shop.example.com S->>C: ServerHello
chosen cipher suite
key_share (server's ephemeral public key) Note over C,S: both sides now derive the same keys S->>C: {EncryptedExtensions}
{Certificate}
{CertificateVerify}
{Finished} C->>S: {Finished}
{HTTP request} S->>C: {HTTP response} Note over C,S: { } = encrypted with keys derived from the key exchange

Step by step:

  1. ClientHello. The client lists what it supports and, crucially, already sends a key share: an ephemeral public key for a key exchange, usually X25519 elliptic curve Diffie-Hellman. Modern browsers and libraries now also offer a hybrid post-quantum key exchange, X25519MLKEM768, which combines X25519 with ML-KEM so that recorded traffic stays safe even if large quantum computers arrive later.
  2. ServerHello. The server picks a cipher suite and sends its own key share. Each side combines its private key with the other’s public key and arrives at the same shared secret, which no observer can compute. From here on, everything is encrypted.
  3. Certificate and CertificateVerify. The server sends its certificate chain and then signs a hash of the whole handshake so far with its private key. This proves it holds the private key matching the certificate, and that nobody tampered with the earlier messages.
  4. Finished. Both sides send a MAC over the handshake transcript. If anything was altered in transit, the values will not match and the connection is dropped.

Because the key pairs are ephemeral and discarded after the handshake, a full TLS 1.3 handshake always provides forward secrecy: stealing the server’s long-term private key next year does not decrypt traffic recorded today. TLS 1.2 made this optional; TLS 1.3 removed static RSA and static Diffie-Hellman key exchange, which lacked it.

TLS 1.3 also supports 0-RTT resumption, where a returning client sends data in its very first message. It saves a round trip, but that early data can be replayed by an attacker, so it should only be used for requests that are safe to repeat.

Certificates and the Chain of Trust
#

A certificate is a signed document that binds a public key to a name. The key fields:

  • Subject Alternative Name (SAN): the hostnames the certificate is valid for, such as shop.example.com or *.example.com. Clients check the SAN, not the older Common Name field.
  • Public key: the key the server proves it holds in CertificateVerify.
  • Validity period: not before, not after.
  • Issuer and signature: who vouches for this binding.

Nobody’s browser knows your server’s certificate in advance. Instead, it trusts a small set of root certificate authorities shipped with the operating system or browser, and follows a chain from your certificate up to one of them:

flowchart TB
  R["Root CA
self-signed, kept offline
Pre-installed in the trust store.
Rarely used directly."] -->|"signs"| I["Intermediate CA
Sent by the server along with
its own certificate."] I -->|"signs"| L["Leaf certificate
your server
SAN: shop.example.com
Valid for a few months at most."] classDef rt fill:#dbeafe,stroke:#3b82f6,color:#0f172a classDef lake fill:#dcfce7,stroke:#16a34a,color:#0f172a classDef gov fill:#fef3c7,stroke:#d97706,color:#0f172a class R gov class I rt class L lake

The client verifies each signature up the chain, checks that the root is in its trust store, that no certificate has expired, and that the hostname it connected to matches the leaf’s SAN. Any failure, and the connection should stop.

Certificate authorities verify control of a domain before issuing, typically through the ACME protocol: the CA asks you to place a token at a URL on the domain or in a DNS record. Every publicly trusted certificate is also recorded in public Certificate Transparency logs, so a domain owner can spot a certificate issued for their name that they never asked for.

Lifetimes are getting shorter. Under a CA/Browser Forum decision from 2025, the maximum validity of a public TLS certificate dropped to 200 days in March 2026, and falls to 100 days in 2027 and 47 days in 2029. The message is clear: renewal must be automated. Short lifetimes also limit the damage from a leaked key, which matters because revocation checking has always been unreliable in practice.

SNI: Many Sites, One IP Address
#

A single server or CDN edge often hosts thousands of domains on one IP address. Before it can send the right certificate, it needs to know which site the client wants. That is the job of Server Name Indication (SNI), the server_name field in the ClientHello.

The catch: the ClientHello is sent before encryption begins, so SNI travels in plaintext. Anyone on the network path can see which hostname you are visiting, even though they cannot see the page. Encrypted Client Hello (ECH) addresses this by encrypting the sensitive parts of the ClientHello with a key the server publishes in DNS. Major browsers support it and some CDNs have enabled it, but it is far from universal.

Mutual TLS
#

In normal TLS, only the server proves its identity. In mutual TLS (mTLS), the server also sends a CertificateRequest, and the client responds with its own certificate and a CertificateVerify signature:

sequenceDiagram
  participant C as Client
  participant S as Server
  C->>S: ClientHello
  S->>C: ServerHello, {EncryptedExtensions},
{CertificateRequest}, {Certificate},
{CertificateVerify}, {Finished} C->>S: {Certificate} (client's cert)
{CertificateVerify} (proves key)
{Finished}

mTLS is common between services in a service mesh, for API clients in banking and payments, for IoT devices, and as a way to bind OAuth tokens to a client. It is strong authentication because the private key never crosses the wire. The hard part is operational: issuing, rotating and revoking certificates for many clients. Public CAs are also phasing out client authentication on publicly trusted certificates, so mTLS normally runs on a private CA you control.

HSTS: Closing the First-Request Gap
#

Even with HTTPS configured, a user who types example.com may send their first request over plain HTTP before being redirected. An attacker on the same Wi-Fi network can intercept that request and keep the victim on HTTP. This is called SSL stripping.

HTTP Strict Transport Security tells the browser to use HTTPS only, for a set period:

Strict-Transport-Security: max-age=63072000; includeSubDomains; preload

After seeing this header once, the browser refuses plain HTTP for that domain and will not let the user click through certificate errors. The first visit is still exposed, which is why browsers maintain an HSTS preload list of domains that are HTTPS-only from the very first request. Preloading is hard to undo, so make sure every subdomain serves HTTPS before you add includeSubDomains and preload.

Common Mistakes
#

Disabling certificate verification. verify=False in Python, curl -k, InsecureSkipVerify: true in Go. It makes the error go away and turns TLS into encryption with whoever answers. Fix the trust store instead, for example by adding your internal CA.

Serving an incomplete chain. The server sends only the leaf certificate, not the intermediate. Browsers often cope by fetching or caching the intermediate, so it looks fine on your laptop, but API clients and older devices fail.

Manual renewal. Expired certificates still cause major outages. With lifetimes heading towards 47 days, renew automatically with ACME and alert well before expiry.

Terminating TLS and forgetting the rest. A load balancer decrypts traffic and forwards it in plaintext across the internal network. In a zero trust design, re-encrypt to the backend. Private connectivity helps as well, as I describe in How AWS PrivateLink and Private DNS Actually Work, but it does not replace encryption.

Keeping old protocol versions. TLS 1.0 and 1.1 are deprecated (RFC 8996). Allow TLS 1.2 with modern cipher suites for compatibility, and TLS 1.3 everywhere you can.

Careless wildcards and shared keys. One wildcard certificate and private key copied onto dozens of servers means one compromised server exposes all of them. Prefer separate certificates per service.

Mixed content. An HTTPS page that loads a script over HTTP hands that script, and therefore the page, to anyone on the network path. Browsers block most of it now, but check your own sites.

Try It Yourself
#

Look at a real handshake from your terminal:

# Show the negotiated version, cipher, key exchange and certificate chain
openssl s_client -connect example.com:443 -servername example.com -tls1_3 -showcerts </dev/null

# Watch curl's view of the handshake and certificate checks
curl -v https://example.com -o /dev/null

In the openssl output, find the subject and issuer of each certificate in the chain and check that each issuer matches the subject of the next certificate up. Then look for the negotiated group: on a recent OpenSSL build talking to a modern server, you may see the hybrid post-quantum group.

The certificates you meet in TLS use the same public key signatures as the tokens in How JWT Tokens Actually Work. Once you see that a certificate and a JWT are both “signed claims about a key or a subject”, a lot of security engineering starts to look like the same idea applied in different places.

Working on something like this? Ask me. Questions about your setup, or anything this article didn't cover. No account needed, private by default.

Only I read it. It isn't published unless you tick the box, and your email is never shown or added to any list. Privacy

Kevin Keller
Author
Kevin Keller
Personal blog: the business case for secure AI and data platforms, and the architecture blueprints to build them. Snowflake-related articles explore the art of the possible and are not official Snowflake solutions or endorsed by Snowflake unless explicitly stated. Opinions are my own. Content is meant as educational inspiration, not production guidance.
Share this article