How VPN Traffic, Tunnels and Encryption Work
On this page
Summary: A virtual private network (VPN) is a protected tunnel between your device and a VPN server. Software on your device, the VPN client, captures outgoing traffic and wraps each original packet inside a new packet addressed to the VPN server. That wrapping is the tunnel, and the client typically encrypts the contents as well. The server unwraps each packet and forwards it onward. In a typical consumer VPN, source-address translation also makes the outgoing traffic appear to come from the VPN server rather than your device. The tunnel ends at that server.
What changes is who can see your traffic, not whether anyone can. Your ISP can see the VPN connection and its timing and traffic volume, but generally not the encrypted inner destination or content. The operator running the server is placed in a position to see the traffic it forwards. A VPN is therefore not anonymity. Tunnelling and encryption are separate operations, and “VPN” names a family of mechanisms rather than one protocol, so the details below are labelled by the protocol or platform they come from.
VPN Advisors is an independent, affiliate-supported website explaining how VPNs work, what they protect, and how to evaluate VPN services. This article follows traffic through a VPN tunnel, from routing and encryption on your device to forwarding at the VPN server. For the broader introduction to VPN types, protocols, and protection features, see our VPN Fundamentals guide.
The Parts of a VPN Connection and What They Connect To
Six parts appear in almost every explanation of a VPN. They are grouped by role, rather than by strict packet order.
- VPN client (or app). The software on your device that sets up and runs the tunnel. The app is the software you install. A protocol is a specific design for how the client and server set up and protect the tunnel.
- Virtual (TUN) interface and routing table. The virtual interface is a network connection that exists in software, and the routing table is the device’s list of rules for where each packet goes. Both are named here and explained in the packet journey below.
- VPN server (or gateway). The machine at the far end of the tunnel. It receives wrapped packets and forwards what is inside.
- VPN provider (or operator). Whoever runs the server. The operator is not a neutral pipe, and later sections show why that matters.
- Tunnel. The original packets wrapped inside new packets addressed to the VPN server. The tunnel is developed in detail below.
- Destination server. The website or service your traffic is ultimately meant for.
Client, server and provider are three different things, and this article keeps them separate. The client is software on your device, the server is a machine, and the provider is the party running it.
The same mechanism serves two different purposes, and the difference is where the tunnel leads. A corporate remote-access VPN lets off-site users tunnel into a protected network, which is how CISA describes remote-access VPN servers in an enterprise context. The gateway in that case is operated for the organisation, and whoever runs the corporate network is the operator. A consumer VPN service works differently. The FTC’s consumer guidance describes data from a phone going through a consumer VPN app being routed through servers elsewhere, so traffic to websites can appear to come from a server run by the VPN provider. In that case the gateway is the provider’s server, and the service typically connects users to internet destinations rather than primarily to an organisation’s internal resources.
Following One Packet Through a VPN
A packet is a small unit of data sent across a network. Following a single one, such as a request your browser sends toward a website, shows how the parts above work together.
The table below gives the sequence as an illustration of the typical pattern. The subsections after it explain each step and attribute protocol-specific details to their protocol. The last column lists only what the networks along the path carry. The full account of who sees what comes later.
| Step | What happens | Who can observe at this step |
|---|---|---|
| Initial setup, before protected traffic starts (not repeated per packet; keys may be refreshed later) | The client and the VPN server authenticate each other and agree on shared keys. | The exchange runs between the device and the VPN server. |
| 1. Capture | The browser produces a packet. Routing rules send it to the virtual interface, where the VPN client reads it. | The packet is still inside the device. |
| 2. Protect | The client protects the original (inner) packet, typically by encrypting it and adding integrity protection. | The packet is still inside the device. |
| 3. Wrap | The client places the protected packet inside a new outer packet addressed to the VPN server. | The outer packet carries the VPN server’s address. |
| 4. Transit | The outer packet crosses the local network and the ISP to reach the server. | Networks along the path carry the outer packet addressed to the VPN server. |
| 5. Unwrap | The server removes the outer header, then decrypts and verifies the inner packet. | This happens on the VPN server. |
| 6. Forward | For internet access in a typical consumer VPN, the server forwards the packet and translates its source address to the VPN’s public IP. | The destination receives a packet carrying the VPN server’s address. |
The full journey, including the return path and the points where routing or address translation changes what observers see, is examined in How VPN Traffic Is Routed Through a VPN.
The setup row comes first because initial key establishment precedes protected data; keys may be refreshed later, but not for every packet. The rest of the table describes what happens to a packet during the data phase. The sequence is a general pattern, and the exact steps differ by protocol, as the sections below make clear.
How Traffic Enters the Tunnel: Virtual Interface and Routing
On a routing-based VPN, a connected VPN shows up on the device as one more network interface alongside the regular connections. An interface is a point where packets enter or leave the device. The VPN’s interface is virtual, created by software rather than by hardware. The device’s regular connection to its network is the physical interface.
Which interface handles a given packet is decided by the routing table. When its rules send a packet to the virtual interface instead of out through the regular connection, the VPN software reads the packet there. It then protects the packet and sends it on to the gateway. The VPN does not capture everything on its own. Packets reach the virtual interface because routing sends them there.
Two platform examples show the pattern. On Android, a VPN app’s VpnService creates a local TUN interface. The app reads outgoing IP packets from it, encrypts them and sends them to the VPN gateway. It also writes decrypted incoming packets back to the interface. On Linux, WireGuard’s design paper describes it as a secure network tunnel operating at layer 3, implemented as a kernel virtual network interface. These are examples of the same model on two platforms, not a claim that every operating system works identically.
The consequence is that routing decides what enters the tunnel. If a routing rule changes, a packet that used to go to the virtual interface may go out the regular connection instead, and it is no longer tunnelled. The later section on traffic escaping the tunnel builds on this. The next step is what lets the client protect the packets it reads: the two ends must first agree on keys.
Before Data Flows: Authentication and Key Setup
Protecting packets requires keys that both ends share, and each end must be sure who the other is. So before any user traffic is protected, the client and the gateway run a setup phase, often called a handshake. It has two jobs: authenticating the parties and agreeing on keys.
IPsec shows how this works. IPsec is a framework of open standards for private communications over IP networks, and it is usually configured using IKE (Internet Key Exchange). In IPsec, IKE performs mutual authentication, meaning each side proves its identity to the other. It also establishes Security Associations. A Security Association is the agreed record of the shared secrets and the algorithms that both sides will use to protect the traffic. This initial exchange happens before protected traffic starts. New keys can be negotiated later without repeating setup for every packet.
IKE is one design for this phase, and it belongs to IPsec. OpenVPN sets up its keys through a TLS session, and WireGuard uses a Noise_IK handshake. The comparison section below differentiates them. Once the setup phase has produced shared keys, the client can wrap and protect packets, which is the next step.
What the Tunnel Is: An Inner Packet Inside an Outer Packet
For an encrypting tunnel, picture a letter placed inside an envelope addressed to the VPN server. The letter is your original data, and the contents are protected. The envelope shows the VPN server’s address, because that is where it has to be delivered. Anyone handling the envelope along the way can see where it is going, but not read what is inside.
Here are the exact terms for that picture. The tunnel is your original data packets wrapped inside new packets addressed to the VPN server. It is a wrapping of packets, not a private line.
Inner packet (the original)
- The packet your device produced, with its real destination and content.
- This is what the VPN protects.
Outer packet and header (the wrapper)
- A new packet, with a new header addressed to the tunnel endpoint, the VPN server.
- It is not covered by protection in IPsec ESP tunnel mode.
In IPsec ESP tunnel mode, protection covers the tunnelled packet only, not the outer header. ESP is the IPsec component that protects traffic, and its tunnel mode applies protection to whole tunnelled IP packets. When confidentiality is selected, tunnel mode allows the inner IP headers to be encrypted. That conceals the ultimate source and destination. The IPsec specification calls this partial traffic-flow confidentiality.
The outer header explains why the connection stays visible. Because it is unprotected and carries the tunnel endpoint’s address, networks along the path, such as your ISP, can see that your device is exchanging traffic with the VPN server. With confidentiality enabled, they lose sight of the inner destination and the content. Other VPN protocols arrange their packets differently in detail, but the idea carries over conceptually. The ISP still sees the VPN server connection and the timing and size of outer packets, but not the encrypted inner destination or content.
For a closer explanation of encapsulation and why a tunnel is not necessarily encrypted, see VPN Tunnel: What It Is and How It Works.
Tunnelling and encryption are different operations. IP-in-IP, for example, is a tunnelling protocol that encapsulates IP packets inside other IP packets without encrypting them. In IPsec, integrity-only ESP must be offered as a negotiable option, although ESP typically uses both confidentiality and integrity. FTC consumer guidance describes encryption between a phone and the VPN server as something some VPN apps also do. Tunnelling typically comes with encryption, but encryption is a service that gets configured. The word “tunnel” does not by itself mean “encrypted”.
In short, the endpoint is visible, and the inner destination and content are hidden when confidentiality is applied.
Protection Applied to the Inner Packet: Encryption and Integrity
The keys agreed during setup are what protect the data phase. In IPsec, ESP is used to provide five services:
- Confidentiality. Others cannot read the inner packet.
- Data-origin authentication. The receiver can confirm the packet came from the other party.
- Connectionless integrity. Tampering with a packet can be detected.
- Anti-replay. A recorded packet that is sent again can be recognised and rejected.
The distinction between key establishment, encryption, and packet integrity is explored further in VPN Encryption: How It Works and Protects Traffic.
- Limited traffic-flow confidentiality. Some information about the pattern of the traffic is concealed.
Secrecy is only one item on that list. Protection also covers tamper resistance, sender checking and replay resistance.
These are the services the ESP specification provides. Which of them are in use depends on how the connection is configured, and integrity-only ESP is the option already described above. Protection settings are one variable. Which traffic enters the tunnel at all is a separate variable, decided by routing, and the later section on coverage develops it. A connection can be well protected for the traffic that reaches the tunnel while other traffic never reaches it.
At the VPN Server: Unwrapping, Forwarding and the Address Websites See
For more on the server's role as a tunnel endpoint, traffic forwarder, and possible point of observation, see What Is a VPN Server and What Does It Do?.
When the outer packet reaches the gateway, the gateway has to undo the wrapping. IPsec’s specification (RFC 4301) gives a worked example. The arriving packet’s outer header shows the tunnel endpoint as source. The packet is mapped to its Security Association, the outer header is removed, and the packet is decrypted and integrity-checked. That order is the IPsec example, not a processing order that every VPN follows.
The gateway then forwards the inner packet toward its destination. In a typical consumer VPN, the gateway also translates the packet’s source address for internet access, so the website sees the VPN server’s public IP address rather than the user’s. This applies to consumer-style VPNs that route internet traffic through a provider’s server. Forwarding alone does not change the source address.
The VPN’s encryption ends at the server. Whether the next leg, from the server to the destination, is encrypted depends on the destination protocol. If the site uses HTTPS, that protection runs between your device and the website, including across the VPN server.
The return path can be followed conceptually. Replies come back to the gateway, and the gateway sends them into the tunnel toward the client. The client unwraps them and hands them to the application. Protocol-specific reverse handling is left out here.
VPN Is Not One Protocol: Three Example Designs
Different VPNs share a pattern. A client protects and wraps packets for a gateway, which unwraps and forwards them. They differ in how they set up keys, which transport they use and how they identify the other side. The table compares three designs at the level of setup and transport.
| Protocol | Handshake and authentication setup | Transport |
|---|---|---|
| IPsec | IKE performs mutual authentication and establishes Security Associations. IPsec is usually configured using IKE. | ESP over IP; ESP may also be encapsulated in UDP for NAT traversal. |
| OpenVPN (TLS mode) | A TLS session on a control channel exchanges the keys that protect the data channel. | TCP or UDP. The control and data channels share a single port. |
| WireGuard | A Noise_IK handshake with a single round trip. | UDP, for all packets |
OpenVPN describes itself as a TLS-based VPN. In TLS mode it sets up a control channel and a data channel, both carried over one TCP or UDP port. The TLS session on the control channel is where the keys for the data channel are exchanged.
WireGuard ties identity and routing together. Peers are identified by public key, and a cryptokey routing table maps each peer’s public key to a set of allowed IP addresses. A decrypted packet whose source address is not among the allowed addresses for the peer that sent it is dropped. This identity model is specific to WireGuard. Its design paper describes an implementation as a kernel virtual network interface for Linux, which is the same virtual-interface model described earlier.
The table shows differences in setup, transport and identity. It is not a measure of speed, security or how widely each design is used. The shared wrap-and-forward pattern is common to all three, and each design sets up its keys differently: IKE, a TLS session on a control channel, or a Noise_IK handshake. So “VPN” names a family of designs, and a statement about how one of them works does not automatically describe the others.
How a VPN Changes Who Can See Your Traffic
The packet journey leads to two facts. First, in the IPsec ESP tunnel-mode example, the outer header remains visible and carries the VPN server’s address. Second, the gateway removes the tunnel encryption before forwarding traffic, but any separate HTTPS encryption remains in place. Visibility therefore shifts from some parties to others rather than disappearing. The three subsections below take the observers in turn, then the operator’s position, and then the question of anonymity.
Who Sees What: Wi-Fi Network, ISP, VPN Operator and Website
Read the table by comparing the two columns for each party. The “without VPN” column describes baseline visibility of traffic that is not otherwise end-to-end encrypted. The “with VPN” column describes an encrypting VPN, and the cells use “typically” because the details depend on configuration.
| Party | Sees without VPN | Sees with VPN |
|---|---|---|
| Local Wi-Fi observer | On an unsecured public network, can see traffic that is not otherwise end-to-end encrypted. | Cannot read encrypted tunnel contents; still sees the VPN connection and traffic patterns. |
| ISP | Typically can see the content and destination of traffic that is not otherwise end-to-end encrypted. | Sees the VPN server connection and traffic timing and volume, but not the encrypted inner destination or content. |
| VPN operator | No VPN operator is in the path. | Can see the traffic the server forwards, apart from content that is separately end-to-end encrypted. For a corporate VPN, that is whoever runs the corporate network. |
| Destination website | Sees the user’s own IP address. | Sees the VPN server’s address, and may be able to tell that a VPN is in use. |
The ISP row has two halves that belong together. With an encrypting VPN, the ISP can still see that you’re connected to a VPN server, but typically not the content of your traffic or its inner destination. The reason is the outer header from the tunnel explanation above. It is addressed to the VPN server and left unprotected, so it shows the connection. The inner packet carries the real destination and content, so those are what the ISP loses sight of. EFF’s guidance likewise describes a VPN as hiding outgoing traffic from the ISP and the local network owner, such as a coffee shop or hotel. The hiding in that guidance is of content and inner destination. The connection to the VPN server stays visible.
The public Wi-Fi case shows the local-observer row in practice. FTC consumer guidance from 2018 notes that on an unsecured public Wi-Fi network, other users can see your traffic. With a VPN app that encrypts the data, anyone monitoring the Wi-Fi connection cannot read the tunneled contents, even if the site itself does not use encryption. This describes encrypting VPN apps and local-network observers. It says nothing about the VPN operator or the destination site, which have their own rows.
The rows describe what each party can observe from its position. What a particular provider keeps, how HTTPS behaves inside the tunnel, and whether a user is anonymous are separate questions the table cannot answer.
Why the VPN Operator Becomes a New Observer
The mechanism that hides content from the ISP is the same one that puts the operator in a position to see it. The gateway decrypts the inner packet and forwards it, as described above. So whoever runs that gateway can inspect the forwarded traffic, subject to any separate encryption such as HTTPS.
The FTC states this trust shift in its 2018 guidance for consumers. A VPN app typically obscures the content of traffic from the ISP or the public Wi-Fi provider, and it shifts trust from those networks to the VPN app provider. The FTC also notes that using a VPN app gives the app permission to intercept internet traffic. EFF’s guidance points the same way: whoever runs a commercial VPN service can see your traffic, and with a corporate VPN, whoever runs the corporate network can.
The scope of that position depends on configuration. Under the per-app and split setups covered in the next part of the article, only the traffic that enters the tunnel reaches the operator. Content that is separately end-to-end encrypted stays protected, because the VPN’s own encryption ends at the server.
For a focused explanation of when sites see a VPN exit address and which identifiers remain visible, see Does a VPN Hide Your IP Address? How It Works.
Visibility is a capability that follows from where the operator sits. What an operator retains, or does with the traffic it can see, is not determined by how a VPN works and cannot be checked from the mechanism. Using a VPN is a trust decision. The operator takes the position the local network and ISP held before.
IP Address Substitution and Anonymity Are Different Things
Websites see the VPN server’s address instead of yours. That is the network-address change on the destination side, and a VPN does not make you anonymous.
Sites you visit may be able to tell that you are using a VPN. They can also still use identifying information you give them directly, such as an account sign-in, to track you. The operator, as described above, is in a position to see the traffic it forwards.
What changes is the address websites see. Who you are, and what you share with the sites you use, does not change.
Why Traffic Can Still Travel Outside the Tunnel
Everything so far describes what happens to traffic that enters the tunnel. A tunnel hides only the traffic that reaches it, and whether traffic reaches it is a routing outcome. Each way traffic escapes is a break in the chain described earlier, from routing to the virtual interface, then protection, then the gateway. This part covers three kinds of break in turn: a configuration choice, an unintended gap in how a client handles certain traffic, and a deliberate attack on routing.
Routing Decides Coverage: Full, Split and Per-App Tunnelling
The default route and any per-app rules decide which traffic enters the tunnel. This follows from the routing model above. Coverage is a configuration, separate from the protection settings described earlier. The same encryption can be applied to all of a device’s traffic or to only some of it.
Android shows the per-app case. If a VPN app’s allowed-app list includes one or more apps, only those apps use the VPN. When the list is empty, all apps use it. A disallowed list is also available. With a per-app setup, apps outside the list use the regular connection, and the VPN operator is not in their path.
For the wider distinction between traffic protected inside the tunnel and traffic excluded or leaked outside it, see What Traffic Does a VPN Protect?.
Microsoft’s enterprise documentation describes the same routing choice with its own names. A forced tunnel puts 100% of traffic into the VPN tunnel. A selective tunnel uses the tunnel only for corporate-network services, while the default route goes direct. These are Microsoft’s terms for enterprise deployments, and Android’s lists are Android-specific.
So not all device traffic necessarily enters the tunnel, and the extent of coverage depends on the routing configuration in force.
DNS and IPv6 Leaks
Some traffic can leave the tunnel without any configuration choice, when a client does not handle it. DNS queries are the lookups that turn site names into addresses. They can leak outside the tunnel when the device keeps using a resolver reached outside it, which can expose visited domain names to the local network or ISP. IPv6 traffic, which uses the newer version of IP addressing, can likewise travel outside the tunnel when a client does not handle it.
A 2015 study of 14 popular commercial VPN services by Perta et al. (PoPETs 2015) found that most suffered from IPv6 traffic leakage. Its authors also developed DNS hijacking attacks able to capture traffic transparently. These findings describe the services studied in 2015.
A leak of this kind is a gap in how a particular client handles a type of traffic. It is not a defect of tunnelling itself.
Route Manipulation: TunnelVision as a Dated Example
A tunnel depends on the host’s routing table, as the first part of the packet journey showed. TunnelVision (CVE-2024-3661), disclosed on May 6, 2024 by Leviathan Security Group, is an example of an attacker exploiting that dependence.
DHCP is the process by which a local network supplies settings to a device that connects. In the TunnelVision technique, an adversarial DHCP server on the local network uses DHCP option 121, the classless route option. It routes the user’s traffic through the physical interface to an attacker-chosen gateway instead of through the established VPN tunnel. The technique is conditional on three things: an attacker on the local network, a routing-based VPN client, and a host that honours option 121.
The researchers state that TunnelVision does not activate kill switches, and that at the time of disclosure a full fix did not exist for every major operating system. A kill switch that reacts to the tunnel dropping has nothing to react to here. The tunnel stays up while traffic is rerouted around it. That statement describes the situation at disclosure in 2024, and this example does not give the status of any particular operating system today.
TunnelVision is a conditional example of how a tunnel depends on routing. It shows that rerouting while the tunnel stays up can send traffic outside it.
FAQ
What exactly can a VPN provider see?
A VPN provider can see the traffic that passes through its servers, apart from whatever is separately end-to-end encrypted, such as HTTPS. The VPN’s own encryption ends at the server, so the operator’s view is of forwarded traffic and not of content that stays encrypted end to end. That describes what the operator is positioned to see, not what any provider keeps.
What is a kill switch, and does it stop every leak?
No. A kill switch is an optional, feature-dependent setting that blocks traffic outside the tunnel, typically when the tunnel drops, and it does not stop every leak. Android’s always-on VPN (Android 7.0 / API 24 or higher) is one OS-level example. It can start the VPN at boot, and the user or an IT admin can enable “Block connections without VPN” so the system blocks traffic that does not use the VPN. The TunnelVision researchers reported that rerouting while the tunnel stays up did not trigger kill switches. Features and behaviour vary by implementation.
What do the terms split tunnelling, per-app VPN and selective tunnel refer to?
They are platform- or vendor-labelled routing configurations in which only part of a device’s traffic enters the VPN, and they are labels rather than universal standard terms. “Per-app VPN” matches Android’s allowed-app lists. “Selective tunnel” is Microsoft’s name for an enterprise model that sends only corporate-network services through the tunnel, in contrast with Microsoft’s forced tunnel, which sends all traffic through it.
How is a VPN different from Tor?
With a VPN, one provider is positioned to see the traffic it forwards. Tor instead distributes knowledge across relays, so no single relay normally knows both the user’s origin and final destination; an exit relay can still see the destination and any unencrypted outgoing traffic.