What is a man-in-the-middle attack?
Picture passing a note to your friend across the classroom. You fold it up, hand it to the person sitting between you two, and trust them to just pass it along. Except this time, that person secretly unfolds it, reads it, maybe even scribbles something different before refolding it and passing it on. Your friend gets a note that looks totally normal. Neither of you ever finds out anyone touched it.
That go-between is exactly what security people call a man-in-the-middle, or MITM for short. A man-in-the-middle attack is when an attacker secretly positions themselves between two devices that think they're talking directly to each other — say, your phone and a website — so that all of your "private" traffic actually flows through the attacker first.
Simple definition: a man-in-the-middle attack happens when an attacker secretly intercepts and relays communication between two parties who believe they're talking straight to each other — reading it, and sometimes changing it, while both sides remain unaware anything is wrong.
The scary part isn't that the message gets read. It's that everything still looks completely normal on both ends. You typed a message, it arrived. The website sent a response, you got it. There's no popup, no error, no obvious sign that a third party was ever involved — unless the connection is protected in a way that makes eavesdropping and tampering pointless, which is exactly what you'll see later in this tutorial.
The classic setup: fake public Wi-Fi
Here's the most common real-world version of this attack. You're at a coffee shop or an airport, your phone is low on data, and you open the Wi-Fi list looking for something free. One network name jumps out because it sounds official:
That inviting network name didn't come from the coffee shop or the airport at all. An attacker set it up from a laptop sitting a few tables away, deliberately naming it something that sounds trustworthy so people connect without thinking twice. The moment you join it, every request your phone sends — every app, every website, every login — has to pass through that attacker's laptop first before it continues on to the real internet.
Once an attacker is sitting in that position, in the middle of your connection, they can do two different things depending on how the traffic is protected:
- Read it. If your traffic isn't encrypted, they can simply watch it go by — usernames, passwords, messages, whatever you send — in plain, readable text.
- Alter it. They can also change what's flowing through, before letting it continue on to its destination, like editing a payment amount or swapping a link for a malicious one.
Notice what didn't have to happen: the attacker never hacked into your phone, and never broke into the website. They just got themselves into the middle of a connection that trusted them by default. That's the whole trick — position, not brute force.
Try it yourself: send a message through the attacker
Type a short message below (or pick a preset), choose whether the connection uses HTTPS, and click Send. Watch what the attacker in the middle actually sees — and whether they can do anything with it.
Pick a connection type and click Send to watch the message travel.
Look closely at what changed between the two modes: the attacker's position never moved. Your traffic still physically passed through their laptop either way — that part of the attack always works on a network they control. What changed was whether that position was actually useful to them.
Why HTTPS defeats this (mostly)
HTTPS encrypts the connection between your device and the website, scrambling the data into something unreadable to anyone except your device and the website itself. The attacker's traffic still physically flows through their laptop — remember, that part doesn't change — but all they can see is scrambled noise. They can't read it, and if they try to change it, the scrambled data breaks in an obvious way that gets rejected instead of quietly passing through.
Want the full explanation of how that encryption actually works, what the padlock icon means, and how your browser knows it's really talking to the real website? That's covered in What Is HTTPS and SSL? — this tutorial builds on that one instead of repeating it.
This is also exactly why your browser sometimes shows a scary warning page, or refuses to load a site at all, when HTTPS isn't set up correctly. That warning isn't just being cautious for no reason — it exists specifically to stop a man-in-the-middle attack from working. If your browser can't confirm the connection is properly encrypted and verified, it assumes someone could be sitting in the middle and stops you before you type in a password.
What HTTPS does NOT protect against
HTTPS is powerful, but it isn't a force field. A few things it still doesn't hide or prevent:
Which site you visited
An attacker on the same network can usually still see that your device connected to, say, a certain bank or social media site — just not the contents of what you did there. The destination is visible; the conversation is not.
A convincing fake page
HTTPS only proves the connection to whatever site loaded is encrypted — it says nothing about whether that site is the real one. A fake login page that looks identical to the real thing can still have a valid padlock of its own.
A warning you click through
If your browser shows a warning about an expired or self-signed certificate and you click "continue anyway," you've just told your browser to ignore the exact check that was designed to catch a man-in-the-middle attack.
How to protect yourself
Be careful on public Wi-Fi
Avoid entering passwords, payment info, or other sensitive details on public networks when you can help it — you don't know who else is on that network.
Check for the padlock
Before typing a password or payment info, glance at the address bar for the padlock and "https" — it's a quick check that takes a second.
Use a VPN on untrusted networks
A VPN wraps your traffic in its own layer of encryption before it ever reaches an untrusted network. See What Is a VPN? for how that works.
Keep software updated
Bugs in how devices verify certificates get discovered and patched over time. An out-of-date device may be trusting checks it shouldn't.
Never click through a cert warning
A certificate warning means your browser couldn't verify who it's really talking to. Clicking "continue anyway" without understanding why removes the exact protection built to catch this attack.
Check your understanding
An attacker is sitting on the same public Wi-Fi network as you, and all your traffic passes through their laptop. You log into a website that uses HTTPS. Why still can't they read your password?
Your answer:
Sample answer: HTTPS encrypts the connection between your device and the website, so even though your traffic still physically flows through the attacker's laptop, what actually arrives there is scrambled, unreadable data — not your real password. The attacker's position in the middle didn't change, but encryption made that position useless for reading the contents. Only your device and the real website can turn that scrambled data back into your actual password.
Quick quiz
1. What actually happens during a man-in-the-middle attack?
2. In the fake public Wi-Fi scenario, why is a network named "Free_Airport_WiFi" risky?
3. Even with HTTPS turned on, what can an attacker on your network still usually see?
Keep learning about cybersecurity
You've now seen how an attacker can quietly sit between two sides of a conversation without either one noticing — and how encryption takes that position away from them. Next, learn about a completely different kind of risk: vulnerabilities nobody has patched yet because nobody even knows they exist.
Part of the Cybersecurity Basics tutorial series.