⇄ Network Security

VPNs Explained: How Virtual Private Networks Work

A Virtual Private Network (VPN) creates a protected tunnel across an untrusted network so that traffic between two endpoints stays private and authenticated. VPNs matter because they let remote workers reach internal systems safely, connect branch offices over the public internet, and shield traffic from eavesdroppers on shared networks. Understanding how a VPN encapsulates and encrypts packets clarifies both its strengths and its limits.

What a VPN Is and Why It Matters

A VPN extends a private network across public infrastructure by wrapping traffic so that intermediaries see only the encrypted tunnel, not the contents. The two ends of the tunnel authenticate each other and agree on encryption keys, after which packets are protected as they traverse networks neither party controls.

Organizations use VPNs to:

  • Give remote users access to internal resources as if they were on-site.
  • Link geographically separate sites into one logical network.
  • Protect traffic on shared or hostile networks such as public Wi-Fi.

Tunneling and Encapsulation

The defining mechanism of a VPN is tunneling: taking a complete packet and placing it inside the payload of another packet. This is called encapsulation. The original packet, with its own source and destination addresses, becomes the cargo; a new outer header addresses the packet to the far tunnel endpoint.

When the encapsulated packet arrives, the receiving endpoint strips the outer header, decrypts the payload, and forwards the inner packet toward its real destination. Because the inner packet is hidden inside the outer one, private addressing and the true contents are concealed from anyone watching the path.

Encapsulation can operate at different layers. Some VPNs tunnel at the network layer, carrying IP packets; others tunnel at higher layers. The choice affects what kinds of traffic the tunnel can carry and how it interacts with routing.

How VPN Encryption Protects Traffic

Encapsulation alone hides structure but not content. A VPN adds cryptographic protection so the tunnel delivers:

  • Confidentiality through symmetric encryption of the encapsulated payload.
  • Integrity through authentication codes that detect any modification.
  • Authentication so each endpoint proves its identity, typically with certificates or pre-shared keys.

These are the same guarantees provided by TLS, and indeed some VPNs are built directly on TLS. As with any secure channel, ephemeral key exchange gives forward secrecy, so recording the tunnel and later compromising a key does not expose past sessions.

Common VPN Protocols

Several protocol families dominate, each with a different design philosophy.

IPsec

IPsec secures traffic at the network layer. It uses the Encapsulating Security Payload (ESP) to encrypt and authenticate packets and the Internet Key Exchange (IKE) protocol to negotiate keys and establish security associations. IPsec can run in tunnel mode, which encapsulates the entire original packet, or transport mode, which protects only the payload. It is a traditional backbone of site-to-site connectivity.

WireGuard

WireGuard is a streamlined protocol that uses a fixed, opinionated set of quality cryptographic primitives and a small codebase. It authenticates peers using public keys and establishes tunnels quickly with minimal negotiation, which makes it fast and comparatively simple to audit. A minimal client configuration shows how compact the model is:

[Interface]
PrivateKey = <client private key>
Address = 10.0.0.2/32

[Peer]
PublicKey = <server public key>
AllowedIPs = 10.0.0.0/24
Endpoint = vpn.example.com:51820

TLS-Based VPNs

TLS-based VPNs, such as those using OpenVPN, tunnel traffic inside a TLS session, frequently over port 443. Riding on the same port as HTTPS helps this style traverse restrictive networks that would block other protocols.

Remote Access Versus Site-to-Site

VPNs are commonly deployed in two topologies:

  1. Remote access connects an individual device to a network. Client software builds a tunnel to a gateway, and the user's traffic enters the private network through it.
  2. Site-to-site connects whole networks. Gateways at each location maintain a persistent tunnel, so hosts on either side communicate without running any VPN software themselves.

A related design choice is split tunneling, where only traffic destined for the private network goes through the tunnel while other traffic uses the local connection directly. This improves performance but widens exposure, so it is a policy decision rather than a default.

What a VPN Does and Does Not Hide

A VPN is often described as making you anonymous, which overstates its function. Accurately, a VPN:

  • Hides your traffic contents and destinations from local observers and your internet provider.
  • Replaces your source IP address, as seen by destinations, with the VPN gateway's address.

It does not, however, make you anonymous to the VPN operator, who can see the traffic entering and leaving the tunnel. It also does not protect data after it exits the tunnel, nor does it substitute for endpoint security or a zero trust approach to access. Trust simply shifts from the local network to the VPN provider.

Key Takeaways

  • A VPN builds an encrypted, authenticated tunnel across untrusted networks using encapsulation.
  • Tunneling wraps a whole packet inside another, hiding private addressing and contents from the path.
  • Encryption adds confidentiality, integrity, and endpoint authentication, mirroring TLS guarantees.
  • IPsec, WireGuard, and TLS-based VPNs represent different trade-offs in flexibility, speed, and simplicity.
  • A VPN relocates trust to the VPN operator and does not by itself provide anonymity or endpoint security.
vpnipsecwireguardtunnelingnetwork-security

Frequently asked questions

What is a VPN and how does it work?

A VPN (Virtual Private Network) creates an encrypted, authenticated tunnel across an untrusted network so that traffic between two endpoints stays private. It works by encapsulation, wrapping each original packet inside another packet addressed to the far tunnel endpoint, then encrypting the payload. Intermediaries see only the encrypted tunnel, not the contents or the private addressing inside.

What is the difference between IPsec, WireGuard, and OpenVPN?

IPsec secures traffic at the network layer using the Encapsulating Security Payload for encryption and Internet Key Exchange to negotiate keys, and it is a traditional backbone of site-to-site links. WireGuard is a streamlined protocol with a small codebase and a fixed set of quality primitives, making it fast and easier to audit. TLS-based VPNs such as OpenVPN tunnel traffic inside a TLS session, often over the HTTPS port to traverse restrictive networks.

Does a VPN make you anonymous?

No, a VPN does not make you anonymous, and describing it that way overstates its function. It hides your traffic contents and destinations from local observers and your internet provider, and replaces your source IP with the gateway's address, but the VPN operator can still see the traffic entering and leaving the tunnel. Trust simply shifts from the local network to the VPN provider.

What is the difference between remote access and site-to-site VPNs?

A remote access VPN connects an individual device to a network, with client software building a tunnel to a gateway so the user's traffic enters the private network through it. A site-to-site VPN connects whole networks, with gateways at each location maintaining a persistent tunnel so hosts communicate without running any VPN software themselves. The former serves individual users, while the latter links offices or data centers.

What is split tunneling in a VPN?

Split tunneling is a configuration where only traffic destined for the private network goes through the VPN tunnel, while other traffic uses the local internet connection directly. It improves performance and reduces load on the gateway, but it widens exposure because that other traffic bypasses the tunnel's protection and monitoring. For this reason it is a deliberate policy decision rather than a safe default.

What does a VPN not protect against?

A VPN does not protect data after it exits the tunnel, so anything beyond the far endpoint is only as safe as the systems handling it there. It is not a substitute for endpoint security, and it does not by itself provide anonymity or a zero trust approach to access. It also relocates trust to the VPN operator, who can observe the traffic entering and leaving the tunnel.

Try it hands-on

K0G is an open toolkit of browser-based security utilities — hashing, encoding, JWT, certificates, crypto and more, all running locally in your browser.

Explore the tools →