Research publication Protocols & encryption
How VPN encryption works: handshakes, ciphers and forward secrecy
VPN encryption has two parts: a handshake in which the endpoints authenticate each other and agree on fresh keys, and authenticated encryption of every packet with those keys. We explain both, what forward secrecy adds, what encryption leaves visible and where it fails in practice.
Abstract
Marketing describes VPN encryption with a single phrase, usually a cipher name and a key length. The protection a tunnel actually provides comes from a sequence of mechanisms, and it is only as strong as the weakest of them. A handshake authenticates the server (and often the client) and uses an ephemeral Diffie–Hellman exchange to agree on a shared secret that an eavesdropper cannot compute. A key-derivation function turns that secret into separate keys for each direction. An authenticated-encryption algorithm — today almost always AES-GCM or ChaCha20-Poly1305 — then encrypts each packet and detects any modification, while counters and replay windows reject duplicates. Regular rekeying with fresh ephemeral keys provides forward secrecy. We describe each step with reference to TLS 1.3, IKEv2/IPsec and WireGuard, explain what encrypted traffic still reveals to observers and to the VPN provider, discuss the transition to post-quantum key exchange, and list the implementation failures that matter more than key length.
Two jobs: agreeing on keys and protecting packets
VPN encryption is the combination of a handshake, in which two endpoints authenticate each other and agree on secret keys, and a data channel, in which every packet is encrypted and integrity-protected with those keys before it crosses the network.
The two parts use different kinds of cryptography. The handshake uses public-key cryptography, which is slow but lets two parties who share no secret create one. The data channel uses symmetric cryptography, which is fast enough to process every packet at line rate. Every mainstream VPN protocol — TLS-based OpenVPN, IKEv2/IPsec and WireGuard — follows this pattern, even though the details differ [1, 2, 3].
The handshake
Key agreement with ephemeral Diffie–Hellman
In a Diffie–Hellman exchange, each side generates a temporary key pair, sends the public half and combines the other side’s public value with its own private value. Both arrive at the same shared secret; an observer who sees only the public values cannot compute it. Modern protocols use elliptic-curve versions, most often X25519 [4]. Because the key pairs are ephemeral — generated for one session and then deleted — the shared secret exists only for that session.
Authentication
Diffie–Hellman alone does not tell you who you agreed a key with. An attacker positioned between client and server could run one exchange with each and relay traffic between them. The handshake therefore binds the exchange to long-term identities. TLS 1.3, which OpenVPN can use for its control channel, does this with a certificate and a signature over the handshake transcript [1]. IKEv2 authenticates with certificates, EAP or a pre-shared key in its IKE_AUTH exchange [2]. WireGuard, following the Noise framework, mixes each side’s static Curve25519 key into the key derivation, so only the holder of the expected private key can complete the handshake [5, 6]. A client that does not verify the server’s identity properly — for example by accepting any certificate — loses this protection completely.
Key derivation
The shared secret is not used directly. A key-derivation function such as HKDF expands it, together with handshake data, into several independent keys: typically one for each direction, so that a packet sent by the client can never be confused with one sent by the server [7]. Mixing the handshake transcript into the derivation also means any tampering with the handshake produces different keys and a failed connection.
Encrypting the data channel
After the handshake, each packet is protected by an authenticated encryption with associated data (AEAD) algorithm, which encrypts the payload and computes an authentication tag over the payload and selected header fields [8]. If a single bit is changed in transit, the tag check fails and the packet is discarded. Two AEAD algorithms dominate:
- AES-GCM — the AES block cipher in Galois/Counter Mode [9, 10]. Most desktop and server processors, and many phone processors, have hardware instructions for AES, which makes it very fast where available.
- ChaCha20-Poly1305 — a stream cipher with a one-time authenticator [11]. It is fast in software, which helps on devices without AES acceleration, and it is the only data cipher WireGuard uses.
Both algorithms require a nonce — a number used once — for every packet. Reusing a nonce with the same key can reveal plaintext and, for GCM, allow forgeries [10]. Protocols therefore use per-packet counters as nonces and rekey long before a counter could wrap. The same counters let the receiver keep a replay window and reject packets it has already seen [12].
Does key length matter?
AES-128 and AES-256 are both standardised and both far beyond exhaustive search with classical computers [9]. AES-256 provides a larger margin, including against the square-root speed-up that a large quantum computer could give to brute-force search, which is why some guidance prefers it for long-term protection. In practice, a VPN is never broken by brute-forcing an AES key; it is broken by a flawed handshake, a stolen key, a leaked packet or a bug. Phrases such as “military-grade encryption” describe no particular algorithm or configuration and should be read as marketing.
Perfect forward secrecy
Perfect forward secrecy (PFS) is the property that compromising a long-term key does not compromise past sessions. It follows from ephemeral key agreement: the long-term key only authenticates the exchange, and the session secret is derived from ephemeral values that are deleted afterwards. An attacker who records encrypted traffic today and steals the server’s private key next year still cannot decrypt the recording.
Protocols differ in how much forward secrecy they provide and how often it is renewed:
- WireGuard performs a new ephemeral handshake every two minutes during use, limiting how much traffic any one set of keys protects [3].
- TLS 1.3 uses ephemeral key exchange in every full handshake; the static RSA key transport of earlier TLS versions, which had no forward secrecy, was removed [1]. NIST SP 800-52 Rev. 2 gives configuration guidance for TLS implementations [13].
- IKEv2 uses Diffie–Hellman for the IKE security association, but Child SAs rekeyed without a new key exchange derive keys from existing material; a separate “PFS” setting adds a fresh exchange to each rekey [2, 14].
- Static pre-shared keys used directly as traffic keys, as in OpenVPN’s deprecated static-key mode, provide no forward secrecy at all.
What encryption hides — and what it does not
| Observer | Hidden by the tunnel | Still visible |
|---|---|---|
| Local network, Wi-Fi operator | Destinations, DNS queries, content | VPN server address, protocol, timing and volume |
| Internet provider | Destinations, DNS queries, content | VPN server address, protocol, timing and volume |
| VPN provider | Content protected by HTTPS or other end-to-end encryption | Your real address, destinations, unencrypted content |
| Destination website | Your real IP address | VPN exit address, everything you send or sign in with |
The tunnel moves trust rather than removing it: the local network and internet provider lose visibility, and the VPN provider gains it. That is why logging practices and their verification matter as much as cryptography. Encryption also protects only traffic that enters the tunnel — a DNS query sent outside it is not protected by any cipher (see How DNS leaks happen in VPN clients: a technical taxonomy (VPNL-R-2026-001)).
The post-quantum question
A sufficiently large quantum computer would break the elliptic-curve and finite-field Diffie–Hellman exchanges used in today’s handshakes, but not symmetric ciphers with adequate key lengths. The practical risk is therefore “record now, decrypt later”: an adversary who stores encrypted VPN traffic today could decrypt it once such a computer exists, by recovering the session keys from the recorded handshake. NIST standardised ML-KEM, a lattice-based key-encapsulation mechanism, in FIPS 203 in 2024 [15]. The usual transition approach is hybrid key exchange, which combines a classical exchange with a post-quantum one so that an attacker must break both. RFC 9370 defines how IKEv2 can perform several key exchanges in one negotiation [16], and WireGuard’s optional pre-shared key can add a symmetric secret to the handshake for the same purpose [3].
Where VPN encryption fails in practice
- Authentication shortcuts: clients that skip certificate validation, accept any server key or use weak shared secrets.
- Legacy options: deprecated ciphers, static-key modes or small Diffie–Hellman groups left enabled for compatibility [17, 18].
- Key management: private keys copied across many servers, stored unprotected or never rotated.
- Implementation bugs: nonce reuse, memory-safety errors and side channels in code that handles untrusted packets.
- Traffic outside the tunnel: leaks and failed kill switches bypass encryption entirely, whatever cipher is configured.
These are the questions a security audit should answer, and they are covered by our security audit methodology. How to read the resulting report is explained in Reading a VPN security audit report: scope, authorisation and severity (VPNL-R-2026-006); how the three main protocols compare as designs is in WireGuard vs OpenVPN vs IKEv2/IPsec: a technical comparison (VPNL-R-2026-008).
Frequently asked questions
Is AES-256 better than AES-128 for a VPN?
Both are secure against all known practical attacks. AES-256 offers a larger long-term margin; the difference matters far less than handshake design, key management and leak protection.
Can my internet provider see what I do while I use a VPN?
It can see that you are connected to a VPN server, when, and how much data flows. If the tunnel works and nothing leaks, it cannot see the sites you visit or the content you exchange.
Does a VPN make HTTPS unnecessary?
No. A VPN encrypts traffic only between your device and the VPN server. HTTPS encrypts it end to end to the website, including the part after the VPN server.
How can I tell whether a VPN uses forward secrecy?
Check the protocol and its configuration: WireGuard and TLS 1.3 provide it by design, while IKEv2 rekeying and older OpenVPN set-ups depend on settings. Audit reports and published configurations are the evidence to look for.
Limitations
This publication explains mechanisms at the level of the protocol specifications. It simplifies some details — for example, the exact key schedules of TLS 1.3, IKEv2 and Noise — and makes no claim about the configuration of any particular VPN service.
References
All sources are publicly available primary documents. Numbers correspond to the bracketed citations in the text.
- 1Rescorla, E. (2018). The Transport Layer Security (TLS) Protocol Version 1.3 (RFC 8446). RFC Editor. https://www.rfc-editor.org/rfc/rfc8446
- 2Kaufman, C., Hoffman, P., Nir, Y., Eronen, P., & Kivinen, T. (2014). Internet Key Exchange Protocol Version 2 (IKEv2) (RFC 7296). RFC Editor. https://www.rfc-editor.org/rfc/rfc7296
- 3Donenfeld, J. A. (2017). WireGuard: Next Generation Kernel Network Tunnel. In Proceedings of the Network and Distributed System Security Symposium (NDSS 2017). Internet Society. https://doi.org/10.14722/ndss.2017.23160 https://www.wireguard.com/papers/wireguard.pdf
- 4Langley, A., Hamburg, M., & Turner, S. (2016). Elliptic Curves for Security (RFC 7748). RFC Editor. https://www.rfc-editor.org/rfc/rfc7748
- 5Perrin, T. (2018). The Noise Protocol Framework (Revision 34). https://noiseprotocol.org/noise.html
- 6Donenfeld, J. A. (n.d.). Protocol & Cryptography. WireGuard. https://www.wireguard.com/protocol/
- 7Krawczyk, H., & Eronen, P. (2010). HMAC-based Extract-and-Expand Key Derivation Function (HKDF) (RFC 5869). RFC Editor. https://www.rfc-editor.org/rfc/rfc5869
- 8McGrew, D. (2008). An Interface and Algorithms for Authenticated Encryption (RFC 5116). RFC Editor. https://www.rfc-editor.org/rfc/rfc5116
- 9National Institute of Standards and Technology. (2023). Advanced Encryption Standard (AES) (FIPS PUB 197 (updated 2023)). https://doi.org/10.6028/NIST.FIPS.197-upd1
- 10Dworkin, M. (2007). Recommendation for Block Cipher Modes of Operation: Galois/Counter Mode (GCM) and GMAC (NIST Special Publication 800-38D). National Institute of Standards and Technology. https://doi.org/10.6028/NIST.SP.800-38D
- 11Nir, Y., & Langley, A. (2018). ChaCha20 and Poly1305 for IETF Protocols (RFC 8439). RFC Editor. https://www.rfc-editor.org/rfc/rfc8439
- 12Kent, S. (2005). IP Encapsulating Security Payload (ESP) (RFC 4303). RFC Editor. https://www.rfc-editor.org/rfc/rfc4303
- 13McKay, K., & Cooper, D. (2019). Guidelines for the Selection, Configuration, and Use of Transport Layer Security (TLS) Implementations (NIST Special Publication 800-52 Rev. 2). National Institute of Standards and Technology. https://doi.org/10.6028/NIST.SP.800-52r2
- 14Barker, E., Dang, Q., Frankel, S., Scarfone, K., & Wouters, P. (2020). Guide to IPsec VPNs (NIST Special Publication 800-77 Rev. 1). National Institute of Standards and Technology. https://doi.org/10.6028/NIST.SP.800-77r1
- 15National Institute of Standards and Technology. (2024). Module-Lattice-Based Key-Encapsulation Mechanism Standard (FIPS PUB 203). https://doi.org/10.6028/NIST.FIPS.203
- 16Tjhai, CJ., Tomlinson, M., Bartlett, G., Fluhrer, S., Van Geest, D., Garcia-Morchon, O., & Smyslov, V. (2023). Multiple Key Exchanges in the Internet Key Exchange Protocol Version 2 (IKEv2) (RFC 9370). RFC Editor. https://www.rfc-editor.org/rfc/rfc9370
- 17Wouters, P., Migault, D., Mattsson, J., Nir, Y., & Kivinen, T. (2017). Cryptographic Algorithm Implementation Requirements and Usage Guidance for Encapsulating Security Payload (ESP) and Authentication Header (AH) (RFC 8221). RFC Editor. https://www.rfc-editor.org/rfc/rfc8221
- 18Nir, Y., Kivinen, T., Wouters, P., & Migault, D. (2017). Algorithm Implementation Requirements and Usage Guidance for the Internet Key Exchange Protocol Version 2 (IKEv2) (RFC 8247). RFC Editor. https://www.rfc-editor.org/rfc/rfc8247
Cite this publication
APA style
VPN Network Research Labs. (2026, November 17). How VPN encryption works: Handshakes, ciphers and forward secrecy (Research Publication No. VPNL-R-2026-009, Version 1.0). https://vpn.com.de/research/how-vpn-encryption-works
BibTeX
@techreport{vpnl-r-2026-009,
author = {{VPN Network Research Labs}},
title = {{How VPN encryption works: handshakes, ciphers and forward secrecy}},
institution = {VPN Network Research Labs},
type = {Research Publication},
number = {VPNL-R-2026-009},
year = {2026},
month = nov,
date = {2026-11-17},
version = {1.0},
url = {https://vpn.com.de/research/how-vpn-encryption-works},
langid = {en},
note = {Version 1.0}
}
Download citation
Cite the document ID and the version you read. Document IDs are permanent; substantive changes receive a new version number and an entry in the revision history below.
Revision history
| Version | Date | Change |
|---|---|---|
| 1.0 | Initial publication. |
Found an error? Write to support@vpn.com.de. Corrections are handled under our corrections and retractions policy and are never applied silently.
Methodology and definitions
Terms used in this publication
Test records
This publication contains no results about specific products. Product tests, audits and their evidence are published in the Report Registry and the Evidence Database.