Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Blog/Networking

How does HTTPS work? What the padlock really does

The padlock is three promises, not one. Here is how certificates, a quick handshake and fast encryption keep you safe on public Wi-Fi.

Derpx0624 Oct · 4 min read
Contents
Why isn't scrambling enough?How does a server prove who it is?Who trusts the CA?What happens in the handshake?How can two strangers agree on a secret in public?Can I see this on my own laptop?What to learn nextSources
0% read · 4 min leftBack to top ↑
On this page0%
Contents
Why isn't scrambling enough?How does a server prove who it is?Who trusts the CA?What happens in the handshake?How can two strangers agree on a secret in public?Can I see this on my own laptop?What to learn nextSources

You open your bank's site on public Wi-Fi and see a small padlock. What does the padlock actually promise? Many people think it only means "scrambled". That is just one third of the story.

Here is the key idea: encryption without proof of who you are talking to is useless. HTTPS makes three promises at once: nobody can read your data, nobody can secretly change it, and you are really talking to who you think you are.

Under the hood, HTTPS is normal web traffic wrapped in TLS (Transport Layer Security). MDN describes TLS as a way for a client to talk to a server safely across an untrusted network. Let's open it up.

Why isn't scrambling enough?

Say you scramble your messages with a secret code but never check who is on the other end. Someone on the Wi-Fi pretends to be the bank. You scramble everything for them.

Encryption onlyScrambled, but sent to whoever answered. The attacker reads it all.
→
HTTPSScrambled AND the server proved who it is.

This attack is called a manipulator-in-the-middle (MITM). MDN states HTTPS defends against exactly this, where an attacker can read and change the traffic. So TLS needs three things:

  1. Encryption. Attackers cannot read the data.
  2. Integrity. Nobody can secretly change it without being caught.
  3. Authentication. The server proves its identity.

The third one is the hard one. How can a server prove anything?

How does a server prove who it is?

It uses a certificate, which works like an ID card for a website. It holds the site's public key (a lock anyone can have, while only the server owns the matching key) and the domain name, all digitally signed.

The signature comes from a Certificate Authority (CA), an organization your device already trusts. It is like a passport office: anyone can print a card, but only the office can issue a real one. (Let's Encrypt, for example, is a nonprofit CA that gives out free certificates.)

A passport office

Your browser does not know your bank. But it knows the CA, and the CA signed the bank's certificate. So the browser trusts the bank because it trusts the one who signed.

But who vouches for the CA?

Who trusts the CA?

Usually the CA that signed the site's certificate was itself signed by a bigger CA, and so on up to a root. Your device or browser already trusts the roots it ships with.

Your browser walks the chain upward. If it reaches a root it trusts and every signature checks out, the site passes. If not, you see a red warning page.

That settles identity. Now, how do the two sides start talking?

What happens in the handshake?

Before any real data moves, the browser and server do a quick handshake. According to MDN, they agree on a TLS version and on a set of algorithms (a "cipher suite"). The server proves itself, and both agree on a secret key.

Click Next and follow the handshake.

Browser
Server

Browser sends a hello and its public piece for the key

Step 1 of 4
TLS 1.3 does the full handshake in one round trip, per the RFC.

Look at the third step. The server signs the whole handshake, which ties its identity to the keys. That is what stops the attacker on the Wi-Fi.

But the secret key was never sent. How can both sides have it?

How can two strangers agree on a secret in public?

An attacker can watch every message and still not get the key.

TLS 1.3 uses Diffie-Hellman key exchange (the RFC states "over finite fields or elliptic curves"). Each side sends a public piece, then mixes it with its own private piece. Both end up with the same secret. The attacker sees the public pieces but cannot build the secret. The maths is skipped here, because the idea matters more.

Once both sides share a key, they switch to symmetric encryption, where the same key locks and unlocks. It is much cheaper than the key-pair style (asymmetric) used in the handshake.

Your page, cookies, passwords
HTTP request and response
TLS: encrypts every record with the shared key
TCP/IP: carries the scrambled bytes
HTTP is unchanged. TLS just wraps it.

MDN notes that after the handshake, all messages are encrypted, including HTTP headers and bodies. The RFC adds a catch: the length of the data is not hidden.

PhaseStyleJob
HandshakeAsymmetric / key exchangeProve identity, agree on a secret
Everything afterSymmetricFast encryption of real data

Can I see this on my own laptop?

Run this in a terminal. It shows the handshake live:

Bash
curl -v https://example.com -o /dev/null

Look for lines like "Client hello", "Server hello", "Finished", and the TLS version in use. Now look at the chain:

Bash
openssl s_client -connect example.com:443 -servername example.com

You will see a numbered list of certificates. In each pair, s: is who the certificate belongs to and i: is who signed it. Follow the i: of one into the s: of the next. That is the chain of trust in plain text.

What to learn next

  • HSTS: a header that tells browsers "always use HTTPS for this site", which blocks downgrade tricks.
  • Mixed content: why one http:// image on an HTTPS page gets blocked or upgraded.
  • Forward secrecy: why a leaked key today cannot unlock old recordings (the RFC discusses it).
  • Let's Encrypt: get a free certificate and set up HTTPS on your own project.
Key takeaways
  • The padlock is three promises: nobody reads it, nobody secretly edits it, and you know who you are talking to.
  • Encryption without authentication is useless, which is why certificates exist.
  • Trust flows down a chain from a root CA your device already knows.
  • The handshake agrees on a key in public, then fast symmetric encryption does the real work.

Sources

  • MDN: Transport Layer Security
  • RFC 8446: The Transport Layer Security (TLS) Protocol Version 1.3
ShareXLinkedInEmail
Written by Derpx06A developer who builds AI search tools and the code around them. I explain what I got wrong first, so you can skip it. Spotted a mistake? Tell me — corrections get credited.
Networking · 4 minHow does DNS work?Foundations · 3 minWhy is 0.1 + 0.2 not 0.3 in code?Foundations · 4 minHow does Git work inside? (Snapshots, not changes)
Start here
01Why is 0.1 + 0.2 not 0.3 in code?02How does Git work inside? (Snapshots, not changes)03How does your computer know the time? (And why it can be wrong)