CMD Guide
HomeSystem DesignAPI Gateway

HTTP vs HTTPS

HTTPS is just HTTP running inside a TLS tunnel: before any request bytes are sent, client and server run a handshake that (1) verifies the server's identity with a certificate signed by a trusted Certificate Authority, and (2) uses asymmetric crypto to agree on a fresh symmetric session key that encrypts everything afterward — so an attacker on the wire sees only ciphertext and cannot impersonate the server without the CA's private signing key. Plain HTTP skips all of this: every byte, including cookies and passwords, travels as readable text on TCP port 80.

The mechanism: what actually happens on the wire

HTTP is text over a bare TCP socket. Type GET /login HTTP/1.1 and the server receives exactly those bytes; anyone sniffing the network — a rogue café Wi-Fi access point, a compromised router, your ISP — reads the request and any response verbatim, and can silently rewrite them. There is no notion of "who am I talking to."

HTTPS inserts the TLS layer (formerly SSL — the term "SSL" survives only in library names) between TCP and HTTP. TLS solves three distinct problems that beginners often blur together:

The clever part is the key exchange. Symmetric encryption is fast but needs both sides to share a secret key — yet they've never met. TLS 1.3 solves this with ephemeral Diffie-Hellman: each side sends a public key share, and they independently compute the same shared secret that never travels on the wire. The certificate's job is only to sign the server's share so you know the share came from the real domain and not an attacker who spliced in their own.

A traced TLS 1.3 handshake — connecting to https://bank.example

Real message flow after the TCP connection is open. TLS 1.3 completes the handshake in one round trip (1-RTT), then application data flows encrypted.

StepDirectionMessage & real contentWhy it matters
1Client → ServerClientHello: TLS 1.3, cipher list [TLS_AES_128_GCM_SHA256, …], SNI=bank.example, and a key_share = the client's ephemeral X25519 public key g^aProposes crypto and hands over half the DH exchange up front — that's how 1-RTT is possible
2Server → ClientServerHello: chosen cipher TLS_AES_128_GCM_SHA256, server key_share g^bBoth sides now compute shared secret g^(ab). Everything after this point is encrypted.
3Server → ClientCertificate: bank.example's cert, chaining Leaf → an intermediate CA → ISRG Root X1 (intermediate names rotate every few years — check the live chain with openssl s_client)Carries the server's public key and the CA signature chain the client will verify
4Server → ClientCertificateVerify: a signature over the whole handshake transcript, made with the cert's private keyProves the server actually holds the private key for that cert — not just a copy of a public cert
5Client (local)Validate chain to a trusted root; check bank.example matches a Subject Alternative Name; check notBefore/notAfter dates; check OCSP/CRL revocationThis is the anti-MITM gate. Fail any check → browser aborts with a red warning.
6Both → Finished: MAC over the transcript using the derived keyConfirms neither side's messages were tampered with mid-handshake (downgrade protection)
7Client → ServerEncrypted: GET /login HTTP/1.1\r\nHost: bank.example\r\nCookie: session=…The actual HTTP request — now AES-GCM ciphertext, unreadable to any sniffer

Key insight for step 4: possessing the certificate file is public knowledge (the browser downloads it in step 3). Security comes from CertificateVerify, where the server signs with the matching private key. An attacker can copy bank.example's cert but cannot produce that signature, so the handshake dies at step 5/6.

diagram
diagram

Why the naive mental model is wrong

A common beginner claim: "HTTPS encrypts data with the server's public key from the certificate." That describes old RSA key transport, which TLS 1.3 removed because it lacks forward secrecy — if the server's long-term private key later leaks, an attacker who recorded past traffic could decrypt all of it. Modern TLS uses ephemeral Diffie-Hellman instead: the session key is derived from throwaway key pairs discarded after the handshake, so recorded ciphertext stays safe even if the cert's private key is stolen tomorrow. The certificate is used to sign and authenticate the exchange, not to encrypt the session.

Pitfalls a working engineer hits

When to use HTTP vs HTTPS — and the decision a senior makes

In 2026 this is barely a choice for anything internet-facing: default to HTTPS everywhere. Certs are free (Let's Encrypt), browsers only speak HTTP/2 over TLS (the spec's cleartext h2c variant exists but is unused on the public web) and HTTP/3 requires TLS 1.3 outright, browsers mark plain HTTP "Not Secure," and Google uses HTTPS as a ranking signal. The residual decision is about where you terminate TLS, not whether to use it.

Choose plain HTTP only when: it's a localhost dev loop, a health-check endpoint on a private network, or the internal hop behind a TLS-terminating gateway inside a trusted network — signals: no untrusted network segment, no credentials or PII on the wire, latency-critical east-west traffic.

Prefer HTTPS (the default) when: any byte crosses a network you don't fully control, or carries cookies, tokens, PII, or payment data — i.e. essentially all client-facing traffic.

Trade-offs vs the alternatives

Choose HTTPS whenever traffic touches an untrusted network or carries anything sensitive (the default for all public traffic); drop to plain HTTP only on trusted internal hops behind a terminating gateway where the latency saving is worth losing on-wire protection.

Takeaways


Re-authored/Deepened for this guide. Sources: RFC 8446 (TLS 1.3) and RFC 2818 (HTTP over TLS); Mozilla MDN Web Docs on HTTPS and TLS; the OpenSSL s_client documentation; Cloudflare Learning Center articles on TLS handshakes and forward secrecy; and Google's HTTPS-as-ranking-signal announcement.

🤖 Don't fully get this? Learn it with Claude

Stuck on HTTP vs HTTPS? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **HTTP vs HTTPS** (System Design) and want to truly understand it. Explain HTTP vs HTTPS from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **HTTP vs HTTPS** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **HTTP vs HTTPS** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **HTTP vs HTTPS** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes