March 2, 2026
How HTTPS Actually Saves You
Hi there.
By Atishay Jain
6 min read
Ever feared that someone on the internet might see your password? That someone sitting on the same cafe Wi-Fi could read your messages? Or worse, that the website you're looking at isn't even the real one?
These aren't paranoid thoughts. These are real attacks that happen every day. And the only thing standing between your sensitive data and a stranger reading it in plain text is a few hundred milliseconds of mathematics that happens before your page even loads.
Let's dive into how that works.
HTTP vs HTTPS
Your browser shows a little padlock icon next to a URL, or sometimes it warns you: "This site is not secure." That's the difference.
HTTP sends data in plain text. Whatever you type, all of it travels across the internet as readable text. Anyone who intercepts it can read it.
HTTPS is HTTP with a layer of security on top. The "S" literally stands for "Secure." Your data gets encrypted before it leaves your machine, and only the intended server can decrypt it.
What does "Verified by: Google Trust Services" mean? You will get to know this by the end of this blog.
But secure against what exactly?
The Ways You Can Get Hacked
Forget phishing emails and social engineering for now. There are two major technical ways someone can intercept your communication.
Man-in-the-Middle Attack
You walk into a cafe, connect to their free Wi-Fi, and start browsing. Every single packet of data you send and receive passes through their router. If someone malicious controls that router, they can see everything. Every request, every response, everything in between.
In fact, on an open Wi-Fi network, an attacker doesn't even need to control the router. Your device is broadcasting data over radio waves. Anyone nearby with the right tools can quietly capture that data. This is called packet sniffing, and it's a form of Man-in-the-Middle attack. Free tools like Wireshark make it surprisingly easy.
DNS Attack
When you type bank.com, your browser asks a DNS server for its IP address. Now imagine an attacker tampered with that DNS server and pointed bank.com to their own malicious server. Your browser doesn't know the difference. It happily connects to the attacker's machine thinking it's your bank.
Two different attacks. Two different problems. HTTPS solves both. Let me show you how.
Enter TLS
The security layer in HTTPS is a protocol called TLS (Transport Layer Security). I will not only tell you what TLS is and what are the various steps in that. Instead, I will try to answer the concrete question: how does it actually prevent fraudsters from stealing your data or impersonating you, to a reasonably satisfying level.
Let's start with the real hero of this story, mathematics
The Mathematical Wonder: Asymmetric Encryption
You probably know what encryption is. You take a message, scramble it using a key, and the other side uses the same key to unscramble it. This is called symmetric encryption. One key does both jobs. Simple.
But there's a problem. If the client and server need the same key, how do they agree on that key in the first place? If the client sends the key over the network, the attacker (sitting in the middle, remember?) just grabs it. Game over.
This is where asymmetric encryption comes in.
Instead of one shared key, there are two keys: a public key and a private key. The public key is meant to be shared with the world. The private key never leaves your machine. They are mathematically linked, but here's the crucial part: knowing the public key does not help you figure out the private key.
This isn't a limitation of current technology. It's a mathematical property. A typical RSA key is 2048 bits long. The public key is derived from the product of two massive prime numbers that make up the private key. Figuring out those original primes from the public key alone is a factoring problem that would take classical computers longer than the age of the universe to solve. That's the wall an attacker hits.
The Key Exchange: Diffie-Hellman
So we have public and private keys. Now what? This is where it gets beautiful.
The Diffie-Hellman key exchange lets two parties arrive at the same shared secret without ever sending that secret over the network.
Here's how. Both the client and the server generate their own private keys. They exchange public values derived from those private keys. Then, using their own private key and the other's public value, they each independently compute the same shared secret.
Read that again. Neither side ever sends the secret. Yet both end up with the same one.
The attacker, sitting in the middle, sees the public values being exchanged. But without either private key, they cannot compute the shared secret. Not in any practical amount of time. Not with all the computers on earth running together.
The attacker sees every message from the very start of the conversation, and they still can't figure out the secret. That's not clever engineering. That's mathematics.
How TLS Puts It All Together
Here's what happens when your browser connects to a server over HTTPS.
- A normal TCP connection is established. Nothing special yet.
- Your browser sends a Client Hello with a random number and a list of cryptographic methods it supports.
- The server responds with a Server Hello, picking its preferred cryptographic method and sending back its own random number. Along with this, the server sends its digital certificate, a file containing its public key and a signature from a trusted Certificate Authority. Think of it as the server's ID card.
- The client verifies this certificate. If the signature doesn't check out, your browser throws up that scary warning page and the connection is killed right here.
- Once the server's identity is confirmed, both sides perform the Diffie-Hellman exchange. Each side computes the shared secret independently. From this shared secret and those random numbers, both derive session keys. These are symmetric keys used to encrypt everything going forward. Asymmetric encryption is computationally expensive, so it's only used to safely establish the shared secret. After that, both sides switch to fast symmetric encryption.
Handshake complete. Encrypted communication begins.
How This Stops the Man-in-the-Middle
Remember the cafe attacker who can see every message? Here's why it doesn't matter.
They saw the Client Hello. They saw the Server Hello. They saw the public values exchanged during Diffie-Hellman. But none of that helps them. The shared secret was computed independently on each side using private keys that never touched the network. The session keys derived from that secret are unknown to the attacker.
Every byte of data from this point on is encrypted with keys the attacker simply does not have. They can watch all they want. They'll see nothing but gibberish.
How This Stops the DNS Attack
Now the harder one. The attacker didn't just listen, they redirected your traffic to a fake server entirely. Your browser thinks it's talking to bank.com, but it's actually talking to the attacker.
This is where the certificate saves you. Recall the "Verified by: Google Trust Services" from the image we looked at earlier.
That certificate the server sent contains a digital signature from a Certificate Authority (CA). A CA is a trusted third party, companies like DigiCert, Google Trust Services. Your browser comes pre-loaded with a list of CAs it trusts. This is important: the trust model here is not distributed. There is no democratic consensus. There are specific authorities that the industry has decided to trust, and their public keys are baked into your browser.
When the real bank.com wants an HTTPS certificate, it proves to a CA that it owns the domain. The CA then signs the certificate using the CA's own private key, typically a 4096-bit RSA key or a 256-bit elliptic curve key, locked away in hardware security modules in heavily guarded facilities.
The attacker can set up a fake server. They can redirect your DNS. But they cannot produce a certificate with a valid CA signature for bank.com. To forge that signature, they'd need the CA's private key. They only have the CA's public key, and as we discussed, you cannot reverse that math.
Your browser checks the signature, finds it invalid, and shows you that scary warning page. Connection killed. Attack failed.
Bonus: Why Can't Attackers Just Replay Messages?
An attacker captures your encrypted traffic. They can't decrypt it, sure. But what if they just send those encrypted packets to the server again, as-is? The server expects encrypted data anyway. Wouldn't it just process them?
This is called a replay attack, and TLS handles it. Each message includes a sequence number. If an attacker replays a captured message, the sequence number will be a duplicate, and the server discards it. On top of that, session keys are unique to each connection, derived in part from those random numbers exchanged during the handshake. Replay traffic from an old session, and the server won't be able to make sense of it at all.
The next time you see that little padlock in your browser, you'll know it's not just a cosmetic icon. Behind it is a handshake built on mathematical guarantees: secrets that can be computed but not intercepted, signatures that can be verified but not forged, and a trust chain that starts with authorities whose keys are already on your machine before you ever open a browser.
That's HTTPS. That's TLS. And that's why the "S" matters.