Privacy

What Is IPsec? How It Encrypts Your Traffic and When to Use It

IPsec is the quiet workhorse behind most business VPNs. Here is how it encrypts every packet, how its modes differ, and how to set it up safely.

Cysoro Security TeamPublished · 9 min read
AB✓ESP encrypts every packetIKEv2 agrees the keys PRIVACY IPsecexplained Encrypted packets, end to end.
Quick answer

IPsec, short for Internet Protocol Security, is a set of open IETF standards that encrypts and authenticates IP packets at the network layer. It protects all traffic between two endpoints, whatever application produced it. Most IPsec VPNs use IKEv2 to agree keys and ESP to encrypt packets, usually in tunnel mode between networks or a device and a gateway.

Key takeaways

  • IPsec works at the network layer, so it protects every application on a device or network at once.
  • IKEv2 sets up the connection and agrees the keys; ESP then encrypts and checks each packet.
  • Tunnel mode hides the whole original packet and suits site-to-site VPNs; transport mode protects only the payload between two hosts.

Every email, file transfer and video call you send travels as IP packets across networks you do not control. IPsec is the standard that locks those packets down before they leave, so a stranger on the path sees scrambled data instead of your traffic.

What is IPsec?

IPsec, short for Internet Protocol Security, is a suite of open standards that encrypts and authenticates IP packets at the network layer. It protects all traffic between two endpoints, whatever application produced it.

That layer matters. Because IPsec sits at layer 3 of the network stack, your browser, email client and backup software need no changes. The protection applies to everything crossing the link, not just one app. NIST describes IPsec as a widely used network layer security control for protecting communications over public networks, and notes that IKE is most commonly used to establish IPsec-based VPNs.

The architecture in use today is described in RFC 4301, published by the IETF in 2005. The first IPsec specifications appeared in 1995, and the suite was designed alongside IPv6. Today it is built into routers, firewalls, cloud platforms and the operating systems on your laptop and phone.

IPsec is not one protocol. It is a framework with three main parts: ESP, which protects packets; AH, an older integrity-only option; and IKE, which sets up the connection. Most modern deployments use ESP and IKEv2, and rarely touch AH.

How does IPsec work?

IPsec works in two stages. First, IKE authenticates both sides and agrees on encryption keys. Then ESP encrypts each packet, adds an integrity check and a sequence number, and sends it on its way.

The sequence is simpler than the diagrams suggest. A policy on your device or gateway decides which traffic must be protected. When matching traffic appears, the two sides authenticate each other, agree on algorithms and keys, and create a security association. That association is the shared agreement covering which algorithms, keys and traffic apply, and for how long.

Once the association exists, ESP takes over. Each packet is encrypted, given an integrity check so tampering is detected, and given a sequence number that stops an attacker replaying old packets. Keys are renewed on a schedule, without dropping the connection.

When the tunnel closes, the associations are torn down. Nothing about the protected applications changes: they still send ordinary IP packets, and IPsec handles the security underneath them.

How an IPsec connection is set up 1Triggerpolicy says thistraffic is protected 2AuthenticateIKEv2 checksboth identities 3Agree keysalgorithms andsecurity association 4EncryptESP encrypts andchecks each packet 5Renew keyskeys rotate beforethey expire IKE sets the connection up; ESP carries the traffic.
The five steps of an IPsec connection. Illustration by Cysoro.

What are ESP, AH and IKE?

ESP, AH and IKE are the three building blocks of IPsec. ESP protects the data, AH only checks it, and IKE arranges the keys and settings they use.

ESP (Encapsulating Security Payload) is the workhorse. It encrypts the packet contents and adds an integrity check, so the receiver can tell if anything was changed in transit. Practically every IPsec VPN uses ESP, and RFC 4301 makes it mandatory to implement.

AH (Authentication Header) proves a packet came from the right peer and was not altered, but it does not encrypt anything. It also breaks when traffic passes through NAT, because NAT rewrites addresses that AH protects. That is why modern VPNs rarely use it.

IKE (Internet Key Exchange) is the negotiation protocol. IKEv2, defined in RFC 7296, authenticates the peers with certificates, a pre-shared key or a username and password through EAP, then agrees the algorithms and keys. IKEv1 is deprecated and should not be used on new setups.

ProtocolWhat it doesEncrypts?Used today?
ESPEncrypts and checks packetsYesYes, in almost every IPsec VPN
AHChecks origin and integrity onlyNoRarely, breaks behind NAT
IKEv2Authenticates peers, agrees keysSets up encryptionYes, the current standard
IKEv1Older key exchangeSets up encryptionNo, deprecated

What is the difference between tunnel mode and transport mode?

Tunnel mode wraps the whole original packet inside a new encrypted packet with a new outer header. Transport mode encrypts only the payload and leaves the original IP header visible.

In tunnel mode, anyone watching the link sees only the two gateways talking to each other. They cannot tell which machines behind them are communicating. That is why almost every IPsec VPN uses tunnel mode: office to office, office to cloud, and remote workers to the company network.

In transport mode, the original header stays readable, so the endpoints are visible but the contents are still secret. It suits two hosts protecting their own traffic directly, for example two servers in a data centre. The older L2TP/IPsec combination also runs IPsec in transport mode, with L2TP doing the tunnelling.

Tunnel mode costs a little more bandwidth because of the extra header. For most business links that cost is small compared with the privacy gain of hiding the internal addresses.

Tunnel mode vs transport mode Tunnel modeNew IP header + ESP header + original packet, all encrypted insideBest for: site-to-site VPNs, remote access, cloud links Transport modeOriginal IP header stays visible + ESP header + encrypted payloadBest for: host-to-host traffic, such as two servers
Tunnel mode hides the original packet; transport mode hides only its contents. Illustration by Cysoro.

Where is IPsec used?

You meet IPsec most often in business networking: site-to-site VPNs between offices, links to cloud networks, and the work VPN on a company laptop. It is also the protocol behind many built-in VPN clients.

Site-to-site. Two gateways, usually firewalls or routers, keep a permanent tunnel between two networks. Staff in a branch office reach the file server at headquarters as if it were on the same network, and nobody runs VPN software. Cloud connections work the same way: AWS Site-to-Site VPN is IPsec, with two tunnels ending in different Availability Zones.

Remote access. One device connects to a gateway. Windows, macOS, iOS, ChromeOS and Android all have an IKEv2/IPsec client built in, so a company can often skip installing an app. On phones launched with Android 12 or later, IKEv2/IPsec is the only type left in the built-in VPN client.

Consumer VPN apps. Here IPsec appears as IKEv2/IPsec, and it is losing ground to WireGuard. Most apps now default to WireGuard or a protocol built on it, though IKEv2 remains a solid option when it is offered. If you work from cafés and hotels, our guide to how to secure your Wi-Fi covers the wider habits that matter alongside a VPN.

What ports and protocols does IPsec use?

IKE uses UDP port 500. Behind NAT, IPsec switches to UDP port 4500 and wraps ESP inside UDP. Without NAT, ESP travels as IP protocol 50, and AH as protocol 51.

That detail explains a common frustration: a VPN that connects at home but not at a hotel. If a firewall blocks UDP 500, UDP 4500 or ESP, the tunnel fails. Some business gateways can run IPsec over TCP port 443 to get through strict networks, since that port looks like ordinary HTTPS traffic.

For algorithms, current IETF guidance makes AES-GCM mandatory to implement for ESP and recommends ChaCha20-Poly1305. It says 3DES should no longer be used and rules out DES. Older gateways may still offer 3DES and SHA-1 for compatibility, but an audit will flag them.

Check your own setup against that list. If you see IKEv1, 3DES, MD5 or SHA-1 in a gateway config, treat it as a finding to fix, not a harmless legacy option.

IPsec vs SSL VPN, WireGuard and OpenVPN: what is the difference?

All four do the same basic job: encrypt traffic between two points. They differ in where they run, how easy they are to block, and how much there is to configure.

ProtocolTypical usePortsGetting past blocks
IPsec (IKEv2)Office links, cloud, company VPNsUDP 500 and 4500, or ESP 50Easy to spot; some gateways use TCP 443
SSL/TLS VPNRemote access to company networksTCP 443Looks like HTTPS, gets through most networks
WireGuardConsumer VPN appsOne UDP port, set by the serverEasy to block; providers add disguise
OpenVPNOlder VPN apps, self-hosted serversUDP 1194, or TCP 443TCP 443 helps, but inspection can spot it

IPsec can negotiate dozens of algorithm combinations, which helps when connecting equipment from different vendors and hurts when someone leaves an old option switched on. WireGuard does one thing with a fixed set of modern algorithms and very little to configure, but it is not an IETF standard and is not built into firewalls the way IPsec is.

SSL VPNs were long the easier choice for remote workers because they run over TCP 443. That line is blurring: Fortinet replaced its SSL VPN tunnel mode with IPsec in 2025, and its IPsec can run over TCP 443. Either option is only as safe as the gateway running it.

Is IPsec secure?

Set up properly, with IKEv2, certificates and AES-GCM, the protocol itself has held up well. The problems come from old settings, weak keys, unpatched software and the gateways that run it.

Weak pre-shared keys are the classic failure. Researchers showed in 2018 that IKE with a weak pre-shared key can be cracked offline by an attacker who sits in the middle of a single connection attempt. A shared key that looks like a Wi-Fi password is the weak spot, not the encryption. Use certificates or EAP authentication instead where you can.

Software bugs are the second risk. IPsec code is large and runs on internet-facing machines before anyone has logged in. In April 2026 Microsoft patched a flaw in the Windows IKE service rated 9.8 out of 10, and CISA added it to its list of actively exploited flaws. Patch gateways as soon as the vendor releases a fix.

Third, the gateways themselves have become a favourite way in for attackers. Verizon's breach reports have found edge devices and VPNs increasingly targeted. A strong cipher does not help much when the appliance holding the keys has not been patched in months.

Do not use IKEv1 or 3DESUse IKEv2, certificates or EAP, AES-GCM, and no 3DES or DES. Retire L2TP/IPsec where you have a choice: Microsoft deprecated L2TP on Windows Server, and Android 12 and later no longer offer it.

How do you set up IPsec safely?

Start with the checklist, not the config screen. Decide who connects, which networks they reach, and how you will authenticate them, before you touch a firewall.

  1. Use IKEv2 only. Disable IKEv1 on every gateway and client.
  2. Prefer certificates. Use machine or user certificates, or EAP with strong credentials, instead of a shared pre-shared key.
  3. Pick modern algorithms. AES-GCM for encryption, SHA-256 or stronger for integrity, and a strong Diffie-Hellman group.
  4. Limit the tunnel. Only the networks a user or site needs should be reachable through it.
  5. Patch on a schedule. Put VPN gateways on the same urgent patch cycle as internet-facing servers.
  6. Log and watch. Alert on failed authentications, unusual source countries and tunnels that appear outside working hours.
  7. Test the failure case. Check what happens when a certificate expires or a key rotates, before it happens in production.

For a small business, the simplest safe path is often the VPN feature already in your firewall, configured with IKEv2 and certificates, rather than a separate product. Our small business cybersecurity checklist puts VPN patching alongside backups, updates and device security.

The bottom line

IPsec is not flashy, and that is the point. It has quietly carried business traffic for decades because it is standard, built into nearly everything, and strong when configured with modern settings.

If you run a network, use IKEv2 with certificates and AES-GCM, keep the gateway patched, and retire the legacy options. You can check the public side of your own setup in seconds with the free SSL checker.

It also helps to know what address the internet sees when your tunnel is up, which you can check with what is my IP.

Frequently asked questions

What is IPsec in simple terms?

IPsec is a set of rules that locks down internet traffic at the packet level. It scrambles the contents of each packet and proves it came from the right sender, so anyone watching the network in between sees only unreadable data.

Is IPsec a VPN?

Not on its own. IPsec is the set of protocols that secures the traffic, while a VPN is the private connection built with it. An IPsec VPN is a VPN that uses IPsec to build its encrypted tunnel.

What is the difference between IPsec tunnel mode and transport mode?

Tunnel mode wraps the whole original packet, headers included, inside a new encrypted packet. Transport mode encrypts only the payload and keeps the original IP header visible. Tunnel mode suits networks and remote access; transport mode suits two hosts talking directly.

What ports does IPsec use?

IKE uses UDP port 500. When either side sits behind NAT, IPsec moves to UDP port 4500 and wraps ESP inside UDP. Without NAT, ESP travels as its own IP protocol, number 50. A firewall must allow these for the tunnel to connect.

Is IPsec secure?

Yes, when it is set up properly with IKEv2, certificates or strong authentication, and modern algorithms such as AES-GCM. Most real failures come from old settings, weak pre-shared keys, unpatched gateways, or IKEv1, not from the encryption itself.

What is IKEv2 in IPsec?

IKEv2 is the key exchange protocol that sets up an IPsec connection. It authenticates both sides, agrees on encryption and integrity algorithms, and creates the security associations that ESP then uses to protect the actual traffic.

Is IPsec better than WireGuard or OpenVPN?

For connecting offices, cloud networks and firewalls, IPsec is the standard because it is built into almost all network gear. For a personal VPN app, WireGuard is usually simpler and faster. The right choice depends on what you are connecting, not on which protocol is newest.

Do I need IPsec at home?

Most home users do not need to configure IPsec themselves. You meet it when you connect to a work VPN, link a home router to an office network, or use a VPN app that lists IKEv2/IPsec as a protocol option.

Sources

  1. NIST — SP 800-77 Rev. 1, Guide to IPsec VPNs
  2. Privacy Affairs — What Is an IPsec VPN?
  3. Rapid7 — What Is IPsec? How It Works, Modes, and Uses
  4. IETF — RFC 4301, Security Architecture for the Internet Protocol
  5. IETF — RFC 7296, Internet Key Exchange Protocol Version 2 (IKEv2)
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against NIST SP 800-77 Rev. 1, RFC 4301 and RFC 7296, and current vendor and explainer coverage of IKEv2 and ESP.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free