Encapsulating Security Payload (ESP): How IPsec Protects Network Traffic
Encapsulating Security Payload (ESP) is the IPsec protocol that helps secure data as it travels across IP networks. Commonly used in VPNs, ESP can encrypt packet contents, verify their integrity, authenticate their origin, and help block replay attacks. In plain terms, ESP wraps sensitive network traffic in a protected packet so that attackers who intercept it cannot easily read or alter the information. NIST describes ESP as IPsec’s core security protocol, capable of providing integrity protection and optional encryption for packet data and headers.
What is Encapsulating Security Payload?
Encapsulating Security Payload is part of the Internet Protocol Security (IPsec) suite. It operates at the network layer, protecting IP packets regardless of the application that produced them.
ESP is especially important for:
- Site-to-site VPNs connecting offices or cloud networks
- Remote-access VPNs for employees and contractors
- Private links between servers, gateways, or data centers
- Protecting traffic sent over untrusted networks
Depending on the security association and configuration, ESP can provide confidentiality through encryption, data integrity, origin authentication, and anti-replay protection. The related IPsec standard defines the packet structure and the security services ESP can apply.
How ESP works
Before data is sent, the communicating devices establish an IPsec security association. This agreement identifies details such as the encryption algorithm, authentication method, keys, and anti-replay settings.
Encapsulating Security Payload then protects traffic in four broad steps:
- Identify the security context. The ESP header includes a Security Parameters Index (SPI), which tells the receiving device which security association to use.
- Protect the payload. ESP encrypts the selected portion of the packet when confidentiality is enabled. Without the correct key, intercepted data should be unreadable.
- Add integrity protection. An authentication value – or, in modern deployments, authenticated encryption – helps the receiver detect unauthorized changes.
- Check for replayed packets. Sequence numbers allow the receiving device to recognize and reject packets that an attacker has captured and resent.
The receiver validates the packet, checks its replay status, decrypts it when necessary, and forwards the original traffic.

ESP packet components
An Encapsulating Security Payload-protected packet generally contains these elements:
| Component | Purpose |
|---|---|
| ESP header | Identifies the security association and carries the sequence number. |
| Payload data | The traffic being protected, such as a TCP segment or an entire original IP packet. |
| ESP trailer | Includes padding and information about the encapsulated protocol. |
| Authentication data | Verifies packet integrity and authenticity when used. |
Padding can also meet encryption-alignment requirements and make the exact length of the original payload less obvious.
ESP transport mode vs. tunnel mode
ESP supports two modes, and choosing the right one affects what is protected.
Transport mode
In transport mode, ESP protects the payload of the original IP packet, while the original outer IP header remains visible for routing. This mode is useful for host-to-host protection. However, because the original IP header is not encrypted, some metadata – such as source and destination IP addresses – can still be exposed.
Tunnel mode
In tunnel mode, ESP encapsulates the entire original IP packet inside a new packet. The original packet, including its IP header, is protected, while a new outer IP header enables routing between VPN endpoints. Tunnel mode is the common choice for site-to-site and remote-access VPNs because it better protects internal addressing and network structure.
Key security benefits of Encapsulating Security Payload
ESP provides several important protections for network traffic:
- Confidentiality: Encryption prevents unauthorized parties from reading protected data.
- Integrity: Tampered packets can be detected and discarded.
- Data-origin authentication: The receiving device can verify that traffic came from an authenticated peer.
- Anti-replay protection: Sequence numbers help stop attackers from resending captured packets.
- Network-layer security: ESP protects many kinds of IP-based traffic without requiring individual applications to implement their own VPN logic.
ESP vs. Authentication Header (AH)
Authentication Header (AH) is another IPsec protocol, but it does not encrypt traffic. AH focuses on integrity and authentication, while ESP is normally preferred when confidentiality is required. For most VPN use cases, ESP is the practical choice because it can combine encryption with integrity and authentication. It also works more smoothly with network address translation when NAT Traversal is used, whereas AH’s coverage of IP-header fields can conflict with address translation.
Encapsulating Security Payload implementation best practices
A secure ESP deployment depends on more than enabling IPsec. Follow these practices:
- Use modern authenticated-encryption suites, such as AES-GCM, where supported.
- Use strong, centrally managed key-exchange policies through IKE.
- Enable anti-replay protection.
- Prefer tunnel mode for gateway-to-gateway and remote-access VPNs.
- Rotate keys and review security association lifetimes.
- Limit VPN access with least-privilege network rules.
- Monitor IPsec logs for failed negotiations, unusual rekeying activity, and repeated authentication errors.
- Keep VPN gateways and cryptographic libraries updated.
Avoid relying on encryption alone. A well-designed ESP deployment also needs secure identity validation, safe key management, access controls, and monitoring.
Conclusion
Encapsulating Security Payload is a foundational IPsec technology for protecting network traffic. By encrypting packet contents, verifying integrity, authenticating peers, and resisting replay attacks, ESP helps organizations create secure connections across public and untrusted networks. For most VPN deployments, using ESP in tunnel mode with modern authenticated encryption and disciplined key management provides a strong foundation for protecting data in transit.