L3 · NetworksNetworking 101 · part 6 of 7

How a VPN Actually Works

A VPN puts each of your packets inside an encrypted envelope and gives it a new return address. Here's the tunnel, the encryption, and what a VPN does and doesn't protect.

Takumi Yamada
· 5 min read · 3 references
vpnnetworkingencryptionprivacywireguard

VPNs are often advertised as a way to become anonymous online.

That's not what a VPN does. A VPN (Virtual Private Network) does two well-understood things. It every , so the networks between you and the VPN can't read them. And it replaces your return address, so the websites you visit see the server's IP (Internet Protocol) address instead of yours.

Once those two things are clear, you can tell what a VPN protects and what it can't.

The problem: your packets are postcards

Normally, when you load a website, your packets travel like postcards. Anyone who handles a postcard can read the address on it. In the same way, every network on the path can read the outside of your packets: your Wi-Fi, the café's , your (Internet Service Provider), and every network after that.

ONE PACKETyour IPfromexample.comtoCONTENTreadable without TLSYOUCAFÉ WI-FIISPINTERNETexample.comevery one of these can read your IP and the destination,and the content too when it isn't encrypted
The path without a VPN. The highlighted boxes are the ones that can read the packet on the way.

(Hypertext Transfer Protocol Secure) already encrypts the content of a page. But the information around it, the metadata, is still visible. Your ISP still sees the name of every website you connect to, through (Domain Name System) lookups and through the site name sent at the start of the (Transport Layer Security) . And every website you visit sees your , which shows your rough location and which ISP account you use.

The trick: a tunnel

A VPN puts each of your packets inside another packet. This is called encapsulation. The inner packet is encrypted, and the outer packet is addressed to a VPN server.

WITHOUT A VPNyou → example.comIP headerDATAWITH A VPNyou → vpn-servernew IP headeryou → example.comIP headerDATAwhat your ISP seesencrypted, so it can't read this
The original packet, header and all, becomes the encrypted cargo of a new one.

The VPN server decrypts the inner packet, replaces your address with its own, and sends the packet on to the real destination. Replies come back to the server, which encrypts them and sends them back to you through the same tunnel.

That diagram shows what each party can see.

Your ISP and the café Wi-Fi now see only an encrypted stream going to one VPN server. They see no website names and no destinations.

The website sees the VPN server's IP address, not yours. As far as it knows, you are in whichever city that server is in.

The VPN provider sees everything your ISP used to see. You haven't removed the party you have to trust. You have chosen a different one.

That last point is the most important thing to understand about VPN services. A VPN moves your trust from your ISP to your VPN provider. Whether that's an improvement depends entirely on the provider.

ENCRYPTED TUNNELYOUCAFÉ WI-FIISPVPN SERVERexample.comsee one encrypted streamto one VPN serversees what your ISPused to seesees the server'saddress, not yours
The same path with the tunnel up. The solid box is where the trust went.

What is inside the tunnel

Modern VPN do three jobs.

JobWhat it meansTypical tool
Key exchangeYou and the server agree on a secret key without ever sending itDiffie-Hellman
EncryptionEach packet is scrambled with that keyChaCha20 or AES-256
AuthenticationEach packet carries a tamper-proof sealPoly1305 or GCM tags

Key exchange is the clever part. Each side has a private key, which it never shares, and a public key made from it, which it can send openly. Each side combines its own private key with the other side's public key, and both end up with the same secret. Someone watching sees only the public keys, and can't work out the secret from them.

YOUprivate key aVPN SERVERprivate key byour public key, Athe server's public key, BSESSION KEYmade from a and BSESSION KEYmade from b and A=the same key, and it was never sentSomeone watching the network sees A and B. The session key cannot be worked out from those two.
Key exchange. Both sides arrive at the same session key, and the key itself never crosses the network.

WireGuard, the protocol most modern VPNs use, is known for being small. It's about 4,000 lines of code inside the Linux , compared with hundreds of thousands of lines for OpenVPN. Less code means fewer places for security bugs, and code that experts can actually check.

Its design is plain. Each side has a key pair, much like with (Secure Shell), and each side knows the other's public key in advance. Only a peer that holds the matching private key can complete the handshake, and setting up the connection takes one round trip.

WireGuard handshake (simplified):

you  ── handshake initiation (your ephemeral pubkey) ──►  server
you  ◄── handshake response (server ephemeral pubkey) ──  server
        both sides now derive the same session key
you  ══ encrypted packets, rekeyed every 2 minutes ══►  server

WireGuard makes new session keys every two minutes. This gives you forward secrecy: even if someone records your traffic today and steals a long-term key next year, the old sessions stay unreadable. Each session key was thrown away after use, and the stolen key can't rebuild them.

TODAYtraffic is recordedsession key 1session key 2session key 3each key is used fortwo minutes, thenthrown awayNEXT YEARa key is stolenSTOLEN KEYthe long-term onecannot rebuild session keys 1 to 3,so the recording stays unreadable
Forward secrecy. The keys that encrypted the old traffic no longer exist anywhere.

What a VPN doesn't do

Advertisements usually leave this part out.

It doesn't make you anonymous. If you are logged into your Google account through the tunnel, Google still knows exactly who you are. , logins and browser fingerprinting, which identifies a browser by its settings, all identify you whatever your IP address is.

ONE REQUESTthrough the tunnelWHAT THE SITE RECEIVESfrom 198.51.100.9the VPN server's addresscookie: logged in as [email protected]your login, unchangedthe VPN changed thisthe site knows who you are from this
The VPN changes the address on your requests. It does not change what is inside them.

It doesn't make a bad website safe. If a site is harmful or unencrypted, the VPN delivers the same harmful content, just through an encrypted tunnel.

It doesn't hide that you are using a VPN. Your stream to the VPN server is visible, and the IP addresses of VPN servers are well known. That's exactly how streaming services block VPNs.

DNS can leak. If your computer sends its DNS lookups outside the tunnel, your ISP still sees every website name you look up. Good VPN apps force DNS through the tunnel, and it's worth checking that yours does.

ENCRYPTED TUNNELYOUISPVPN SERVERDNS queries, sent outside the tunnelthe traffic is hidden,and the ISP still seesevery domain you look up
A DNS leak. The lookups take the ordinary path while everything else goes through the tunnel.

The kill switch matters. If the tunnel drops and your traffic quietly goes back to the normal connection, you are exposed without knowing it. A kill switch blocks all traffic while the tunnel is down.

NO KILL SWITCHthe tunnel is downYOUISPA SITEsent in the clear,with no warningKILL SWITCHthe tunnel is downYOUISPA SITEblocked until thetunnel is back
What happens to your traffic while the tunnel is down.

The Bottom Line

I keep a VPN indicator on my desktop's status bar. It's a small Go program that checks the connection every few seconds and shows the country and city of the server. I built it because of that fallback problem.

The dangerous case isn't the VPN being off. It's the VPN being off without you noticing. Showing the tunnel's state on screen all the time makes that failure visible.

A VPN encrypts your packets, replaces your address with the server's address, and moves your trust from your ISP to the VPN provider. Those three facts are enough to judge most claims about VPNs.

Check yourself

3 questions · nothing is saved
  1. 1.With a VPN on, who can now see the websites you visit, the way your ISP could before?
  2. 2.WireGuard makes new session keys every two minutes. What does that give you?
  3. 3.Your VPN tunnel drops and your traffic quietly goes back to the normal connection. What stops that?

References & Primary Sources

Official specifications, standards, and documentation cited in this post.

  1. [1]

    Jason A. Donenfeld's formal paper detailing Noise framework cryptography and cryptokey routing

    PAPERwireguard.com
  2. [2]

    Kernel documentation on virtual layer-2/layer-3 packet capture and transmission in userspace

    DOCSdocs.kernel.org
  3. [3]

    Foundational IETF standards for cryptographic protection of IP communications

    RFCrfc-editor.org

Who wrote this

Author profile and background

Takumi Yamada

Takumi Yamada

· Backend Engineer

Backend engineer building services, databases, Linux tooling, and NEGEN SYSTEMS. Writing about low-level mechanics, distributed systems, and real-world security.

End of post
NEGEN SYSTEMS
Receipt · post 7 of 31
Written
Dec 8, 2025
Length
1,021 words · 5 min
Built
…
Served by
…
Delivered
…
Over the wire
…
Go's share
…
Next in Networking 101 · part 7 of 7

Eduroam on Linux: Why One Wi-Fi Network Is So Hard to Join

Eduroam isn't a Wi-Fi password, it's a personal login that works across thousands of universities. Here's how it works, why Linux has trouble with it, and the settings that work.

6 min read