A VPN (virtual private network) creates an encrypted tunnel between your device and a VPN server: your device wraps each outgoing packet inside an encrypted packet addressed to the server, and the server unwraps it and forwards it to its real destination. Websites see the VPN server's IP address instead of yours, and your local network and ISP see only encrypted traffic to that one server.
The same mechanism powers both kinds of VPN people use: remote-access VPNs that put a laptop "inside" an office network, and consumer VPN services that route your internet traffic through a provider's servers.
How a VPN works, step by step
- A virtual network adapter appears. The VPN software adds a network interface that behaves like a real one. WireGuard's documentation describes it as adding an interface "like
eth0orwlan0, calledwg0"; OpenVPN uses a TUN/TAP virtual interface. Your operating system gives it an address inside the VPN, such as10.0.0.2. - Routes point traffic at it. The VPN changes the routing table so that traffic for the internet (or for the office network) goes to the virtual adapter instead of straight to your router.
- Each packet is encrypted and wrapped. The VPN software takes the whole original packet, encrypts it, and puts it inside a new packet addressed to the VPN server. This is encapsulation; RFC 4301 describes IPsec tunnel mode the same way, with an outer header naming the tunnel endpoints and an inner header keeping the original source and destination.
- The wrapped packet travels over the internet. Your router and ISP handle it like any other packet. All they can read is the outer header: your IP, the VPN server's IP, the port, and the size.
- The server unwraps and forwards it. The VPN server checks the packet's authentication, decrypts it, and sends the original packet on to its destination, using the server's own IP address as the source.
- Replies come back the same way. The website answers the VPN server, which encrypts the reply and sends it back through the tunnel to your device.
What the encryption actually protects
A VPN tunnel provides more than secrecy. RFC 4301 lists the services IPsec provides as "access control, connectionless integrity, data origin authentication, detection and rejection of replays", plus confidentiality through encryption. In plain terms:
- Confidentiality: nobody on the path can read the inner packets.
- Integrity and authentication: a packet altered or injected in transit fails the check and is dropped.
- Replay protection: a captured packet can't be sent again later to repeat an action.
Before any of that, the two ends agree on keys with a handshake based on public-key cryptography, so the session keys never cross the network. WireGuard repeats its handshake "every few minutes, in order to provide rotating keys for perfect forward secrecy", meaning a key stolen later can't decrypt traffic recorded earlier.
VPN protocols compared
| WireGuard | IPsec (IKEv2 + ESP) | OpenVPN | |
|---|---|---|---|
| Transport | UDP only | ESP directly over IP, or inside UDP port 4500 to get through NAT | UDP or TCP |
| Key exchange | Noise_IK handshake, Curve25519 | IKE | TLS session on a control channel |
| Data encryption | ChaCha20-Poly1305 | Negotiated (for example AES-GCM) | Negotiated, via OpenSSL |
| Where it runs | Initially Linux kernel, now cross-platform | Built into most operating systems and network gear | User-space application on all major platforms |
WireGuard's documentation names one fixed set of algorithms (Curve25519, ChaCha20, Poly1305, BLAKE2s, HKDF) rather than a menu to negotiate, and each peer is identified by its public key. IPsec's ESP can be wrapped in UDP (RFC 3948) so it passes through home routers that do NAT. IPsec is a family of standards; NIST's Guide to IPsec VPNs (SP 800-77 Rev. 1, 2020) covers how to configure it. OpenVPN's manual describes it as "tightly integrated with the OpenSSL library". OpenVPN's ability to run over TCP helps on networks that block UDP, but UDP is the usual choice for a tunnel because the applications inside already handle their own reliability. See TCP vs UDP for the difference.
How WireGuard decides what goes through the tunnel
WireGuard calls its routing model Cryptokey Routing: each peer's public key is paired with a list of allowed IP addresses. When you send a packet, WireGuard looks up the destination in those lists to choose the peer. When a packet arrives, it checks that the decrypted source address is in the sending peer's list; "If not, drop it." A typical client config looks like this:
[Interface]
PrivateKey = <client private key>
Address = 10.0.0.2/32
DNS = 10.0.0.1
[Peer]
PublicKey = <server public key>
Endpoint = vpn.example.com:51820
AllowedIPs = 0.0.0.0/0, ::/0
AllowedIPs = 0.0.0.0/0, ::/0 sends all IPv4 and IPv6 traffic through the tunnel (a full tunnel). Replacing it with 10.0.0.0/24 sends only that network through the VPN and everything else directly (split tunnelling).
What a VPN hides, and from whom
| Who | Without a VPN | With a VPN |
|---|---|---|
| Wi-Fi owner / local network | Sites you connect to (via DNS and TLS server names), unencrypted traffic | Only that you connect to one VPN server, and how much data |
| Your ISP | Sites you connect to, timing and volume | The VPN server's IP, timing and volume |
| Websites | Your public IP address and rough location | The VPN server's IP and location |
| VPN provider | Nothing | Everything your ISP used to see |
Two things follow from that table. First, a VPN moves trust rather than removing it: the provider now sits where your ISP was. Second, it doesn't hide who you are from a site you log in to, or stop cookies and browser fingerprinting. It changes your apparent public IP address, not your identity.
HTTPS already encrypts the content of most web traffic, so on a trusted home connection a VPN mostly hides which sites you visit from the ISP. On untrusted Wi-Fi it also protects any traffic that isn't encrypted, and DNS lookups if the VPN carries them (the DNS = line above points lookups at a resolver inside the tunnel). If DNS still goes to your ISP's resolver, your lookups leak around the tunnel; see how DNS works for what those lookups reveal.
Why VPNs reduce the maximum packet size
Encapsulation adds headers to every packet. For WireGuard over IPv4 you can add up the overhead from the protocol description: a 20-byte outer IPv4 header, an 8-byte UDP header, WireGuard's 16-byte data header (type, reserved bytes, receiver index and an 8-byte counter) and a 16-byte authentication tag. That is 60 bytes per packet, or 80 bytes over IPv6 with its 40-byte header, and the inner packet is also padded to a multiple of 16 bytes before encryption.
On a link with the common 1,500-byte MTU, that leaves 1,420 bytes for the inner packet if you budget for the IPv6 case (1,500 minus 80). wg-quick picks the MTU automatically from the endpoint or default route unless you set MTU = yourself. If the VPN interface's MTU is set too high, large packets get fragmented or dropped, and the symptom is a tunnel where small requests work but big downloads or some websites hang.
If the VPN connects but nothing loads
Check DNS first: try reaching a server by IP address. If that works and names don't, the DNS setting in the VPN config is wrong. Next, lower the MTU on the VPN interface (for example to 1280) and test again; if pages now load, the original MTU was too large for the path. Finally, if the VPN is meant to reach an office network, make sure that network's range is in the routes (or AllowedIPs) and doesn't overlap the local network you're on, since two networks using the same 192.168.1.0/24 range can't both be routed.
Frequently asked questions
- Does a VPN make me anonymous?
- No. It hides your IP address from the sites you visit and hides your traffic from your local network and ISP, but the VPN provider can see the same things your ISP could. Websites can still identify you through logins, cookies and browser fingerprinting.
- Can my ISP see that I am using a VPN?
- Yes. Your ISP sees a steady encrypted connection to the VPN server's IP address, plus its timing and volume. It cannot see the websites or content inside the tunnel, but the connection itself is visible.
- Does a VPN slow down my internet?
- Usually a little. Each packet carries extra headers, the encryption takes CPU time, and your traffic takes a detour through the VPN server. A distant or overloaded server adds the most delay; a nearby server on a fast connection often costs little.
- What is split tunneling?
- Split tunneling sends only some traffic through the VPN and the rest directly. With WireGuard, it is controlled by AllowedIPs: 0.0.0.0/0 routes all IPv4 traffic through the tunnel, while a specific range such as 10.0.0.0/8 sends only office-network traffic through it.