Flamingo Raises $4.5M Seed Round

Skip to content

What is an IPsec VPN? IKE, ESP and tunnel mode explained

Best Practices
Security
IT Operations
October 14, 2026
146 views
What is an IPsec VPN? IKE, ESP and tunnel mode explained

An IPsec VPN is an encrypted tunnel built from two protocols: IKE agrees on keys and settings, ESP encrypts the packets. This guide covers tunnel vs transport mode, IKEv1 vs IKEv2, NAT traversal, the IPsec vs TLS VPN vs WireGuard trade-off, and the phase 1 and phase 2 failures behind most broken site-to-site tunnels.


Two offices need to share a file server, and the internet between them is a public road. Something has to wrap every packet so nobody along the way can read it or change it, and both ends have to agree on how. That something is usually IPsec, and this guide explains what an IPsec VPN is, how its parts fit together, and where it breaks.

TL;DR

  • Definition. An IPsec VPN is an encrypted tunnel between two networks or devices, built from the IPsec protocols that protect every IP packet crossing the internet.
  • Two halves. IKE negotiates keys and settings; ESP encrypts and authenticates the traffic itself.
  • Two modes. Tunnel mode wraps the whole packet for site-to-site links; transport mode protects only the payload between two hosts.
  • Ports. IKE uses UDP 500, NAT traversal moves everything to UDP 4500, and plain ESP is IP protocol 50.
  • Settings. NIST says use IKEv2, AES-GCM or AES with SHA-2, and DH group 14 or 19 to 21; drop IKEv1, 3DES, MD5, SHA-1 and groups 2 and 5.

IPsec in plain words

The internet moves data in small envelopes called packets. Each packet has an address label on the outside and the contents inside. By default anyone who handles the packet on its way can read the contents, copy them or swap them for something else.

IPsec is a set of rules that puts a lock on those packets. It does three jobs. It encrypts the contents so a reader in the middle sees noise. It adds a checksum built from a secret key, so any change in transit is caught at the other end. And it proves each end is who it says it is before any of that starts.

The name stands for Internet Protocol Security, and the important word is Internet Protocol. IPsec works at the IP layer, the same layer as the address label itself. That is why it can protect any traffic at all, a file share, a phone call, a database connection, without the applications knowing it is there. A TLS connection, by contrast, protects one application's conversation at a time.

An IPsec VPN is what you get when you use those rules to join two networks, or a laptop and a network, as if they shared a cable. The IETF architecture document that defines the whole family is RFC 4301 from 2005. The pieces inside it are older, but that is the version every current firewall follows.

If the lock-and-key idea is new, PowerCert's short animation walks through it before the detail below.

The two halves: IKE sets up, ESP carries

Every IPsec connection has two separate jobs, and two separate protocols do them. Mixing them up is the root of a lot of confused troubleshooting.

The first job is agreement. Both ends need the same encryption method, the same integrity method, the same keys and the same idea of which traffic belongs in the tunnel. Internet Key Exchange, IKE, handles that conversation. It runs over UDP port 500, it authenticates the peers with a pre-shared key or a certificate, and it uses a Diffie-Hellman exchange so both sides can compute the same secret key without ever sending it across the wire.

The second job is carrying the traffic. Once IKE has done its work, Encapsulating Security Payload, ESP, takes each data packet, encrypts it, adds an integrity check and sends it on. ESP is its own IP protocol, number 50, not TCP or UDP, which matters the moment a firewall or a home router sits in the path.

The result of a successful IKE negotiation is called a security association, or SA. Think of an SA as a signed agreement: these two peers, these algorithms, these keys, this traffic, for this long. IKE builds one SA for itself, the control channel, and then one or more child SAs for the data. Child SAs are one-way, so a working tunnel always has a pair, one in each direction.

The algorithm names you pick inside those agreements, AES, SHA-256, ChaCha20, come from the same toolbox every encrypted protocol draws on. Our explainer on what a cipher is covers how they work and why key length matters.

AH vs ESP: why one of them is retired

IPsec originally shipped with two ways to protect traffic. Authentication Header, AH, protocol 51, proves a packet came from the right peer and was not changed. It does not encrypt anything. ESP does both: it encrypts and it proves integrity.

AH had one trick ESP did not. It also protected parts of the outer IP header, including the addresses. That sounded useful in 1998. In practice it means any device that rewrites the address on the way, which is every NAT router on earth, breaks the AH check. A home connection, a hotel Wi-Fi, a carrier-grade NAT on a cellular link: AH fails on all of them.

NIST's guide to IPsec VPNs, SP 800-77 Revision 1 from June 2020, settles the question in one line: "AH has been obsoleted and should not be implemented or deployed." Where encryption is not wanted, the guide points to ESP with null encryption or AES-GMAC instead. So when you configure a tunnel today, the protocol choice is ESP, and the remaining decisions are about modes and algorithms.

Transport mode vs tunnel mode

ESP can wrap a packet in two ways, and the choice decides what an observer on the internet can still see.

Transport mode protects the contents and leaves the original IP header in place. The source and destination addresses stay visible. It suits a conversation between two specific hosts that can each talk IPsec themselves, such as two servers protecting a replication link, or L2TP over IPsec on an older remote-access setup.

Tunnel mode wraps the entire original packet, header and all, inside a new packet. The outer header carries the addresses of the two gateways. The inner header, with the real source and destination inside each office, is encrypted along with everything else. An observer sees two firewalls talking, nothing more.

Site-to-site VPNs use tunnel mode, because the gateways are protecting traffic for whole networks behind them, not for themselves. That also means the inner addresses on both sides have to be distinct, a point that comes back later as one of the classic failure tickets. If the address ranges themselves are unfamiliar, the guide to public vs private IP ranges covers which blocks each office is likely using.

IKEv1 vs IKEv2: phases without the jargon

IKE has two versions in service, and the documentation for each uses different words for the same steps. Here is the plain version of both.

IKEv1 works in two phases. Phase 1 builds a protected control channel between the two gateways. It either uses main mode, six messages that hide the peers' identities, or aggressive mode, three messages that are faster and leak the identity in the clear. Phase 2, also called quick mode, runs inside that channel and builds the child SAs that carry data. When a vendor screen says "phase 1 up, phase 2 down", it means the gateways trust each other but cannot agree on what to send.

IKEv2, defined in RFC 7296 in 2014, collapses most of that. Four messages in two exchanges, IKE_SA_INIT and IKE_AUTH, set up the control channel and the first child SA together. More child SAs come later with a small CREATE_CHILD_SA exchange. It also has dead peer detection, NAT traversal and support for EAP authentication built into the standard rather than bolted on as vendor extensions.

The words phase 1 and phase 2 survive in every firewall menu, even on IKEv2. Read phase 1 as "the IKE SA" and phase 2 as "the child SAs", and the menus line up with the standard.

NIST's guidance is blunt about which to use: "IKEv1 should not be used for new deployments, and existing deployments using IKEv1 should be converted to IKEv2 when possible." For a walkthrough of what each IKEv1 message carries on a Cisco box, Deploy and Defend's tutorial goes message by message.

Site-to-site vs remote access

IPsec gets used in two shapes, and they are configured very differently even when the protocol underneath is the same.

A site-to-site VPN joins two networks through their gateways. The firewall in office A and the firewall in office B form one tunnel, and every device behind either firewall can reach the other side without installing anything. Branch offices, a link to a cloud network in AWS or Azure, and connections to a supplier's network all look like this. The two gateways usually authenticate each other with certificates or a pre-shared key, and the tunnel stays up permanently.

A remote-access VPN joins one device to a network. The laptop runs a client, Windows' built-in one or a vendor app, and connects to a gateway at the office. Each user authenticates separately, ideally with a certificate or EAP plus MFA rather than a shared secret. NIST's guide is explicit that for remote access, "EAP-TLS or machine certificate authentication should be used."

Both shapes are possible on a Windows server too, with RRAS terminating IKEv2 for laptops. Our guide to running a Windows VPN server covers that build and the cases where a firewall or a Zero Trust product is the better choice.

NAT traversal and the three things to open

IPsec was designed for an internet where every device had a public address. NAT, the trick that lets a whole office share one address, arrived shortly after and broke two assumptions at once.

ESP has no port numbers. A NAT router tracks connections by address and port, so it has nothing to map an incoming ESP packet back to the right device behind it. And if the IKE exchange includes the original addresses in its checks, the rewrite makes them fail.

NAT traversal, NAT-T, fixes both. During the IKE exchange, each side sends hashes of the addresses it thinks it has. If the other side sees different ones, a NAT is in the path, and both peers switch to wrapping ESP inside UDP on port 4500, which RFC 3948 defines. UDP has ports, so the NAT router can track it like any other flow.

That gives the short list of what a firewall in front of an IPsec gateway has to allow:

TrafficWhat it carriesWhen it is used
UDP 500IKE negotiationAlways, at the start
UDP 4500IKE and ESP after NAT-T switchesWhenever a NAT sits between the peers
IP protocol 50 (ESP)Encrypted dataOnly when there is no NAT in the path

Protocol 50 is not a port. A rule that opens "port 50" opens nothing useful, which is a common reason a tunnel negotiates and then carries no data. The TCP vs UDP explainer covers why UDP is the carrier here.

UDP is also why a stateful firewall in front of the gateway needs explicit inbound rules for the peer, rather than trusting it to recognise return traffic on its own.

IPsec vs SSL/TLS VPN vs WireGuard

IPsec is not the only way to build a VPN, and for some jobs it is not the best one. The three common choices differ in where they sit, how they negotiate and how much there is to configure.

SSL VPNs, more accurately TLS VPNs, run over TCP or UDP 443, the same port as every website. They get through hotel and airport networks that block everything else, and most firewall vendors ship one with a client. The WireGuard VPN protocol, merged into the Linux kernel in version 5.6 in March 2020, takes the opposite approach to IPsec: one fixed set of modern algorithms, no negotiation, a small codebase and public keys configured like SSH keys.

IPsec (IKEv2)SSL/TLS VPNWireGuard
LayerIP, network layerUsually above transport, often TCP 443IP, over UDP
PortsUDP 500 and 4500, or ESP443, sometimes UDP tooOne UDP port of your choosing
NegotiationMany proposals, both sides must matchHandled by TLSNone; algorithms are fixed
InteroperabilityAny firewall vendor to any otherVendor client to vendor gatewayNeeds WireGuard on both ends
Native clientsWindows, macOS, iOS, AndroidUsually a vendor appApps on all platforms; kernel on Linux
Typical fitSite-to-site between different vendors, cloud VPN gatewaysRemote users on hostile networksSmall teams, homelabs, overlay networks
Main riskMisconfigured proposals; unpatched gatewaysGateway CVEs on the TLS front endKey distribution at scale

The column that settles most site-to-site decisions is interoperability. When the other end is AWS, Azure, Google Cloud or a supplier's FortiGate, IPsec is the language every one of them speaks. WireGuard is excellent between devices you control on both ends, and TLS VPNs earn their keep for laptops on networks that block UDP.

Where site-to-site tunnels break

Every IPsec tunnel failure shows up at one of two points: the IKE SA will not form, or it forms and the child SAs will not. Knowing which one narrows the cause to a short list.

SymptomWhere it failsUsual causeFirst check
No response from the peerPhase 1UDP 500 or 4500 blocked, wrong peer IPPacket capture on UDP 500 at both edges
"No proposal chosen"Phase 1 or 2Encryption, integrity, DH group or PRF differCompare the proposals side by side, line by line
Authentication failedPhase 1Pre-shared key typo, wrong certificate or IDPeer ID type and value on both ends
Phase 1 up, phase 2 downPhase 2Traffic selectors (local and remote subnets) do not mirrorEach side's local must equal the other's remote
Tunnel drops every hourRekeyPFS group or lifetime mismatchPFS on or off, same group, same lifetime on both
Up, but only one subnet worksPhase 2One SA per selector pair expected by one vendorSplit or combine selectors to match the peer
Up, no traffic either wayData pathOverlapping subnets, missing route or NAT ruleRoutes and NAT exemptions for the inner ranges
Stays "up" after the peer diedDPDDead peer detection disabled or too slowEnable DPD with a sensible interval

The selector row is the one that eats afternoons. In this February 2025 thread, an admin found hundreds of phase 2 subnets on one FortiGate tunnel producing log noise every second. The debug output showed the peer and the local side proposing different subnets, and the replies were unanimous: make each side's local the other's remote, and use supernets or a route-based tunnel rather than hundreds of selectors.

An hourly drop does not always mean a lifetime mismatch. In the thread below, a pfSense to SonicWall tunnel came up cleanly with two phase 2 entries, then lost one of them about 45 minutes later, right around the 3,600-second phase 2 lifetime. The lifetimes matched. The fix was a pfSense option that splits multiple phase 2 entries into separate SAs, because the SonicWall only accepts one traffic selector pair per SA. Replies pointed out the same mismatch appears between ASA, FortiGate and other vendors depending on how each side bundles selectors.

Overlapping subnets come last on the list and first in the time they cost. If both offices use 192.168.1.0/24, no routing table can tell which side a packet belongs to. The fix is NAT inside the tunnel on one side, or renumbering, and the lasting answer is to give every new site its own range from day one, which the small office network design checklist plans for.

The worst version of this ticket is a call with a supplier's engineer, reading proposals aloud line by line.

The settings NIST recommends in 2026

The algorithm menu on a firewall still lists options that were weak a decade ago, usually for compatibility with old peers. NIST SP 800-77 Revision 1 draws the line clearly, and it still holds: "3DES, MD5, SHA-1, and DH Groups 2 and 5 should not be used. Instead, AES-CBC with HMAC-SHA-2 or AES-GCM with either DH group 14 or an ECDH group (19, 20, or 21) should be used."

AES-GCM does encryption and integrity in one pass, and the guide notes it is often offloaded to hardware, which makes it the fast choice on most current firewalls. On authentication, NIST prefers certificates: pre-shared keys are acceptable when two vendors cannot agree on a certificate method, but "within an administrative domain, PSKs should not be used."

Here is the checklist to apply to every tunnel you own:

  1. IKE version. IKEv2 on both ends, IKEv1 only where a peer cannot do anything else, with a date to remove it.
  2. Encryption. AES-GCM with a 256-bit key, or AES-CBC with HMAC-SHA-256 or stronger. No 3DES, no DES.
  3. Integrity and PRF. SHA-256 or above. No MD5, no SHA-1.
  4. Diffie-Hellman. Group 14, or ECDH groups 19, 20 or 21, for both IKE and PFS. No groups 1, 2 or 5.
  5. Perfect forward secrecy. On, with the same group both sides, so a leaked key cannot decrypt past traffic.
  6. Authentication. Certificates between your own sites; a long random pre-shared key only for third parties that cannot do certificates.
  7. Lifetimes and DPD. Agreed values written down with the peer, and dead peer detection on.
  8. Exposure. The gateway's management interface unreachable from the internet, and only UDP 500, UDP 4500 and ESP open to the peers that need them.

Running that list across every client's firewalls is a documentation job as much as a configuration one. If laptops carry IKEv2 profiles too, a script that runs Get-VpnConnection across a client's devices with the output collected is a quick way to find the ones still set to a weak cipher, and that is the kind of fleet job OpenFrame's script runner handles.

Why the gateway needs patching before the cipher

A tunnel with perfect algorithms is still only as safe as the box at each end. VPN gateways sit on the internet by design, they hold the keys, and they sit in front of the network they protect. That makes them one of the most targeted pieces of equipment an organization owns.

The pattern repeats across vendors. On September 25, 2025, CISA issued Emergency Directive 25-03, ordering US federal agencies to inventory their Cisco ASA and Firepower devices, collect forensic data and patch two vulnerabilities, CVE-2025-20333 and CVE-2025-20362, that attackers were chaining against the VPN web services. Fortinet, Ivanti, Palo Alto Networks and SonicWall gateways all had their own entries on CISA's Known Exploited Vulnerabilities list across 2024 and 2025.

None of those bugs were in the IPsec protocol itself. They were in the software around it, the management pages and the web portals. That is the point worth keeping: the protocol choices above protect the traffic, and patching protects the box. Subscribe to each vendor's security advisories, keep management interfaces off the internet, and treat a critical firmware update on an edge device as a same-week job.

The short version

An IPsec VPN is two protocols working together: IKE agrees on keys and settings, ESP encrypts the packets. Tunnel mode wraps whole packets for site-to-site links, NAT traversal moves everything to UDP 4500 when a router rewrites addresses, and IKEv2 with AES-GCM, SHA-2 and DH group 14 or higher is the configuration NIST points to. When a tunnel breaks, ask which stage failed first, then check the proposal, the selectors and the lifetimes on both ends, in that order.

For the remote-access side of the same problem, the Windows VPN server guide is the next read.

If the tunnel is joining segmented networks, the VLAN explainer covers how those segments are built on each side.

Kristina Shkriabina

Content Marketing Lead

Ohayo! I run content, SEO, social, and community at Flamingo. Before IT, I worked as a correspondent for Ukraine's Public Broadcasting Company and have a Master's in journalism.

Related Content

Frequently Asked Questions

/blog/what-is-ipsec

Still deciding?

Ask Mingo answers from our docs and customer stories.

Loading related content and questions