How Does a VPN Work? Tunnel, Encryption and Handshake, Step by Step
What happens between pressing Connect and seeing a website: the handshake, the tunnel, how a packet is wrapped and unwrapped, DNS, and where leaks come from.
4 min readBy Swati
Reviewed by the AmazingRDP technical team

See both ends of a tunnel: run your own VPN on a Linux VPS. See Linux VPS from $6.99
A VPN, a virtual private network, makes your device behave as if it were plugged into a network somewhere else. Everything it sends is encrypted, carried to a VPN server, and released onto the internet from there. Most explanations stop at that sentence. This page follows a single web request through the process, so that terms like "tunnel", "handshake" and "leak" mean something concrete. What a VPN is good for, and what it cannot do, is the subject of the companion page understanding VPNs.
Without a VPN
- Your browser wants
example.comand asks a DNS server for its address. - Your device sends packets to that address. Each packet carries your IP address as sender.
- They pass your router, your internet provider and several networks. Each can read the destination; the content is protected only if the site uses HTTPS.
- The website answers to your address.
With a VPN: the five stages
1. The handshake
When you press Connect, your VPN app contacts the server. The two prove their identities, with keys or certificates and sometimes your user name and password, and then agree on fresh encryption keys for this session, using a method that lets both sides compute the same secret without ever sending it. Anyone recording the exchange learns nothing useful.
2. The virtual network card
The app creates a virtual network interface on your device, with an address from the VPN's private range, such as 10.8.0.2. It then changes the device's routing table so that traffic goes to this interface and not directly to your real one.
3. Wrapping
Your browser's packet for example.com arrives at the virtual interface. The VPN software encrypts the whole packet, addresses included, and puts the result inside a new packet addressed to the VPN server. This packet-inside-a-packet is the "tunnel".
| Layer | From | To | Readable by the networks in between |
|---|---|---|---|
| Outer packet | Your real address | The VPN server | Yes: they see that you talk to a VPN server, and how much |
| Inner packet (encrypted) | Your VPN address | example.com | No |
4. Unwrapping and forwarding
The VPN server decrypts the outer packet, takes out the inner one, replaces its sender address with the server's own public address, and sends it to example.com. The website sees a visitor from the VPN server.
5. The way back
The answer goes to the VPN server, which looks up which client it belongs to, encrypts it, and sends it down the tunnel. Your device decrypts it and hands it to the browser, which notices nothing of all this.
The building blocks
| Part | Job | Typical choices |
|---|---|---|
| Key exchange | Agree on session keys | Curve25519, Diffie-Hellman |
| Authentication | Prove who is who | Public keys, certificates, passwords |
| Encryption | Make packets unreadable | ChaCha20, AES-256 |
| Integrity check | Detect altered packets | Poly1305, GCM |
| Transport | Carry the outer packets | UDP (fast), TCP (passes more firewalls) |
A protocol is a fixed combination of these. WireGuard uses one modern set with no options; OpenVPN and IPsec let administrators choose. The practical differences are in WireGuard explained.
DNS, and what a "leak" is
Before any packet goes to example.com, the name must be looked up. If that look-up still goes to your internet provider's DNS server outside the tunnel, the provider learns every site you visit even though it cannot see the traffic. That is a DNS leak. A properly set-up VPN sends look-ups through the tunnel to a resolver of its own.
| Leak | Cause | Prevention |
|---|---|---|
| DNS leak | Look-ups bypass the tunnel | The VPN app's DNS setting; test on a leak-test site |
| IPv6 leak | The tunnel carries only IPv4; IPv6 traffic goes direct | A VPN that handles IPv6, or blocks it |
| Drop-out leak | The tunnel breaks and traffic continues unprotected | A "kill switch" that blocks traffic until the tunnel is back |
| WebRTC leak | A browser feature reveals local addresses | Browser setting or extension |
Full tunnel and split tunnel
- Full tunnel: all traffic goes through the VPN. The default for privacy services.
- Split tunnel: only traffic for certain networks or apps uses the VPN; the rest goes direct. Common for company VPNs, where only the office network is reached through the tunnel.
What it costs
- A little speed: encryption takes processor time, and the detour through the server adds distance. With a modern protocol and a nearby server the loss is small.
- A little size: the wrapping adds bytes to each packet, so slightly less data fits. A wrongly set packet size (MTU) is a classic cause of connections that stall.
- Trust: the VPN server sees what your provider used to see. Who runs it matters.
The same mechanism, three uses
| Use | The far end is |
|---|---|
| Privacy service | A provider's server; your traffic exits there to the internet |
| Remote access | Your company's network; you reach its internal servers |
| Site-to-site | Another office or a cloud network (see VPC); two networks are joined permanently |
VPN, proxy, remote desktop
A proxy relays the requests of single programs and does not encrypt by itself. A remote desktop does not move your traffic at all; it moves your work to another computer: RDP or VPN for privacy. Setting a VPN up on a phone is in VPN on an iPhone.
See it yourself
The clearest way to understand a tunnel is to own both ends. With a small server and the steps in setting up WireGuard, you can watch the handshake and the counters with wg show, and see your address change on a "what is my IP" page. VPN software may run on our VPS and dedicated plans: Linux VPS.
Questions
How does a VPN work?
Your device encrypts each packet and sends it inside another packet to a VPN server, which unwraps it and forwards it to the internet under its own address.
What is a VPN tunnel?
The encrypted connection between your device and the VPN server, in which whole packets travel wrapped inside other packets.
What is a DNS leak?
When website name look-ups go to your internet provider outside the tunnel, revealing which sites you visit.
Does a VPN slow down the internet?
A little, because of encryption and the detour through the server. With a modern protocol and a nearby server the loss is small.