IPsec ESP Transport vs Tunnel Mode, and NAT-T, Packet by Packet

This walkthrough uses five captures from the late Nick Russo's free packet-capture library. They are in the IPsec and MACsec archive, ipsec_macsec_pcap.zip, under ipsec_macsec_pcap/direct_encap/: espnull_direct_transport.pcapng, espnull_direct_tunnel.pcapng, espnull_direct_transport_natt.pcapng, espnull_direct_tunnel_natt.pcapng, and espaes_direct_tunnel.pcapng. The archive is preserved by the Internet Archive, with the rest of the library listed on his job aid page. We decoded the captures with VisualEther, which turns a Wireshark PCAP into a sequence diagram with a plain-English caption on every message.

IPsec protects IP packets between two devices, most often two VPN gateways. Its data-carrying protocol, ESP (Encapsulating Security Payload), normally encrypts everything after its own header, so a capture of a working VPN shows little more than addresses and a counter.

These captures are different. Four of them use ESP-NULL: ESP with integrity protection but no encryption (RFC 2410). Every packet is still authenticated, yet Wireshark can show what ESP carries. That makes the differences between IPsec's modes visible, field by field:

  1. Transport mode: ESP protects a router's own ping.
  2. Tunnel mode: ESP carries a whole packet from one network to another, inside a second IP header.
  3. Transport mode through a NAT: IKE detects the NAT and moves everything to UDP port 4500.
  4. Tunnel mode through a NAT: the most deeply nested packet, four layers.
  5. Tunnel mode with AES: the same packet as capture 2, encrypted, for contrast.

Each capture is six frames: an IKEv2 exchange that sets up the keys, then one ping and its reply. Each is drawn as an annotated sequence diagram, in three forms: an interactive viewer, an HTML page, and a printable PDF. In the viewer and the HTML page, clicking any message opens its full Wireshark field tree.

💡 Read the walkthrough and a diagram side by side: open the interactive diagram in a split-screen window, or open the HTML version in a new tab and snap the two windows side by side. Each section below links its own diagram.

IPsec in one minute

IPsec has two jobs, done by two protocols:

The agreement IKE produces is a security association (SA): a one-way set of keys and algorithms. Data needs two, one for each direction, and each is named by a 32-bit SPI (Security Parameter Index) that the receiving side picks. Every ESP packet starts with the SPI, so the receiver knows which keys to use.

ESP works in two modes. Transport mode protects the payload of a packet and keeps its original IP header. Tunnel mode protects the entire original packet and puts a new IP header, between the two gateways, in front of it.

The captures come from one lab. R2 and R4 are the IPsec peers in captures 1, 2, and 5, with R3 routing between them. R6 sits behind R3, which translates R6's private address for the outside. All captures were taken on R3's links: between R2 and R3, or between R6 and R3.

flowchart LR accTitle: IPsec lab topology accDescr: R1 at 10.1.2.1 connects to R2 at 10.2.3.2, which connects to R3. R3 connects to R4 at 10.3.4.4, which connects to R5 at 10.4.5.5. R6 at 192.168.0.6, with loopback 10.6.6.6, connects to R3, which translates R6 to 10.3.4.6. R1["R1 10.1.2.1"] --- R2["R2 10.2.3.2"] R2 --- R3["R3 router and NAT"] R3 --- R4["R4 10.3.4.4"] R4 --- R5["R5 10.4.5.5"] R6["R6 192.168.0.6 seen outside as 10.3.4.6"] --- R3
The lab topology. R1 and R5 are the hosts behind the tunnel in capture 2. In captures 3 and 4, R3 translates R6's 192.168.0.6 to 10.3.4.6.

What happens before the first ESP packet?

IKEv2 runs two exchanges, four messages in all, and every capture starts with them. The first pair, IKE_SA_INIT, agrees on algorithms and runs a Diffie-Hellman exchange. The second, IKE_AUTH, is already encrypted. It authenticates the peers and sets up the first pair of ESP SAs, called a Child SA.

sequenceDiagram accTitle: IKEv2 exchange followed by an ESP ping accDescr: R2 sends IKE_SA_INIT with its proposal, key exchange, nonce, and NAT detection hashes. R4 answers with IKE_SA_INIT. R2 sends an encrypted IKE_AUTH request and R4 answers, creating the Child SA. R2 then sends an ESP packet carrying a ping, and R4 replies with an ESP packet on the other SA. participant A as R2 participant B as R4 A->>B: [1] IKE_SA_INIT (proposal, key exchange, nonce, NAT detection) B->>A: [2] IKE_SA_INIT (accepts, key exchange, nonce) A->>B: [3] IKE_AUTH (encrypted) B->>A: [4] IKE_AUTH (encrypted, Child SA up) A->>B: [5] ESP, SPI 0xa434fb0b, ping B->>A: [6] ESP, SPI 0xd2cb426b, reply
The setup every capture starts with, shown for capture 1. Frame numbers are in brackets.

All five captures propose the same suite for the IKE SA: AES-CBC with a 256-bit key, HMAC-SHA2-384 for the PRF (pseudo-random function) and for integrity, and Diffie-Hellman group 20, a 384-bit elliptic curve. The responder accepts it, and the whole negotiation takes 15 to 44 ms.

IKE_AUTH carries one Encrypted and Authenticated payload, so a capture can't show the identities, the Child SA's algorithms, its traffic selectors, or the mode requested. The ESP packets that follow show the result instead. For the IKEv2 messages themselves, see our IKEv2 IPsec VPN sequence diagram.

The first message also carries two notifies, NAT_DETECTION_SOURCE_IP and NAT_DETECTION_DESTINATION_IP. They matter in captures 3 and 4.

Capture 1: transport mode

R2 pings R4, and the two routers protect the ping themselves. The routers are both the IPsec peers and the endpoints of the traffic, which is when transport mode applies.

What does an ESP packet look like?

Frame 5 is the ping. Its IP header is the ping's own, from 10.2.3.2 to 10.3.4.4, except that the protocol field says ESP (50). Then come the ESP fields:

PartFieldFrame 5Purpose
HeaderSPI0xa434fb0bWhich SA, so which keys, the receiver should use
HeaderSequence Number1Counts packets on the SA, so the receiver can reject replays
PayloadICMP echo requestThe protected data, readable here because the cipher is NULL
TrailerPadding01 02Aligns the trailer to a 4-byte boundary
TrailerPad Length2How many padding bytes to strip
TrailerNext HeaderICMP (1)What the payload is
ICV12 bytesIntegrity Check Value over the header, payload, and trailer

The Next Header field is in the trailer, after the payload, so with real encryption it is hidden too. Here it says ICMP: the payload is the ping message itself, with no second IP header. That is transport mode.

The 100-byte ping becomes a 124-byte packet: 8 bytes of ESP header, 4 of padding and trailer, and 12 of ICV.

Why does the reply have a different SPI?

Because it travels on the other SA of the pair. R4's reply in frame 6 carries SPI 0xd2cb426b, the SPI R2 chose for traffic it receives, and its sequence number is 1 again, because each SA keeps its own counter.

Capture 2: tunnel mode

Now R2 and R4 act as VPN gateways. R1, behind R2, pings R5, behind R4. Neither host runs IPsec; the gateways protect the traffic on their behalf.

sequenceDiagram accTitle: A ping through an IPsec tunnel accDescr: R1 sends a ping to R5. R2 wraps it in ESP with an outer IP header from 10.2.3.2 to 10.3.4.4 and sends it to R4. R4 removes the outer header and delivers the ping to R5. The reply returns the same way on the other SA. participant H1 as R1 10.1.2.1 participant G1 as R2 gateway participant G2 as R4 gateway participant H2 as R5 10.4.5.5 H1->>G1: ping to 10.4.5.5 G1->>G2: [5] ESP, outer 10.2.3.2 to 10.3.4.4, inner ping G2->>H2: ping H2->>G2: reply G2->>G1: [6] ESP, outer 10.3.4.4 to 10.2.3.2, inner reply G1->>H1: reply
The ping in capture 2. The gateways add and remove the outer header. Frame numbers are in brackets.

What is the difference between transport and tunnel mode?

Tunnel mode adds a second IP header. Frame 5 has an outer header from 10.2.3.2 to 10.3.4.4, gateway to gateway, then ESP, then the original packet from 10.1.2.1 to 10.4.5.5, intact. ESP's Next Header is IPIP (4), meaning the payload is a whole IP packet. In capture 1 it was ICMP (1).

Here is frame 5's full decode. Open the layers in order: outer IP, ESP with its trailer fields, inner IP, and ICMP.

🔒 [00005] Frame 5 ESP SPI 0x4c6ba1dc 2020-04-19T23:50:58.318863Z 🔐 R2 (tunnel gateway) → 🔐 R4 (tunnel gateway)
frame : Frame 5: Packet, 158 bytes on wire (1264 bits), 158 bytes captured (1264 bits) on interface -, id 0
Section number : 1
Interface id : 0 (-)
Interface name : -
Encapsulation type : Ethernet (1)
Arrival Time : Apr 20, 2020 05:20:58.318863000 India Standard Time
UTC Arrival Time : Apr 19, 2020 23:50:58.318863000 UTC
Epoch Arrival Time : 1587340258.318863000
Time shift for this packet : 0.000000000 seconds
Time delta from previous captured frame : 1.972183000 seconds
Time delta from previous displayed frame : 1.972183000 seconds
Time since reference or first frame : 2.000176000 seconds
Frame Number : 5
Frame Length : 158 bytes (1264 bits)
Capture Length : 158 bytes (1264 bits)
Frame is marked : False
Frame is ignored : False
Protocols in frame : eth:ethertype:ip:esp:ip:icmp:data
Character encoding : ASCII (0)
eth : Ethernet II, Src: aa:bb:cc:00:02:10, Dst: aa:bb:cc:00:03:10
Destination : aa:bb:cc:00:03:10
Destination (resolved) : aa:bb:cc:00:03:10
Destination OUI : aa:bb:cc
.... ..1. .... .... .... .... = LG bit : Locally administered address (this is NOT the factory default)
.... ...0 .... .... .... .... = IG bit : Individual address (unicast)
Address : aa:bb:cc:00:03:10
Address (resolved) : aa:bb:cc:00:03:10
Address OUI : aa:bb:cc
.... ..1. .... .... .... .... = LG bit : Locally administered address (this is NOT the factory default)
.... ...0 .... .... .... .... = IG bit : Individual address (unicast)
Source : aa:bb:cc:00:02:10
Source (resolved) : aa:bb:cc:00:02:10
Source OUI : aa:bb:cc
.... ..1. .... .... .... .... = LG bit : Locally administered address (this is NOT the factory default)
.... ...0 .... .... .... .... = IG bit : Individual address (unicast)
Address : aa:bb:cc:00:02:10
Address (resolved) : aa:bb:cc:00:02:10
Address OUI : aa:bb:cc
.... ..1. .... .... .... .... = LG bit : Locally administered address (this is NOT the factory default)
.... ...0 .... .... .... .... = IG bit : Individual address (unicast)
Type : IPv4 (0x0800)
Stream index : 0
ip : Internet Protocol Version 4, Src: 10.2.3.2, Dst: 10.3.4.4
0100 .... = Version : 4
.... 0101 = Header Length : 20 bytes (5)
Differentiated Services Field : 0x00 (DSCP: CS0, ECN: Not-ECT)
0000 00.. = Differentiated Services Codepoint : Default (0)
.... ..00 = Explicit Congestion Notification : Not ECN-Capable Transport (0)
Total Length : 144
Identification : 0x00d8 (216)
000. .... = Flags : 0x0
0... .... = Reserved bit : Not set
.0.. .... = Don't fragment : Not set
..0. .... = More fragments : Not set
...0 0000 0000 0000 = Fragment Offset : 0
Time to Live : 255
Protocol : Encap Security Payload (50)
Header Checksum : 0x9f59 [validation disabled]
Header checksum status : Unverified
Source Address : 10.2.3.2
Source or Destination Address : 10.2.3.2
Source Host : 10.2.3.2
Source or Destination Host : 10.2.3.2
Destination Address : 10.3.4.4
Source or Destination Address : 10.3.4.4
Destination Host : 10.3.4.4
Source or Destination Host : 10.3.4.4
Stream index : 0
esp : Encapsulating Security Payload
ESP SPI : 0x4c6ba1dc (1282122204)
ESP Sequence : 1
Pad : 0102
ESP Pad Length : 2
Next header : IPIP (0x04)
ESP ICV : da4662abe3c03998e91d958a [unchecked]
Good : False
Bad : False
ip : Internet Protocol Version 4, Src: 10.1.2.1, Dst: 10.4.5.5
0100 .... = Version : 4
.... 0101 = Header Length : 20 bytes (5)
Differentiated Services Field : 0x00 (DSCP: CS0, ECN: Not-ECT)
0000 00.. = Differentiated Services Codepoint : Default (0)
.... ..00 = Explicit Congestion Notification : Not ECN-Capable Transport (0)
Total Length : 100
Identification : 0x002a (42)
000. .... = Flags : 0x0
0... .... = Reserved bit : Not set
.0.. .... = Don't fragment : Not set
..0. .... = More fragments : Not set
...0 0000 0000 0000 = Fragment Offset : 0
Time to Live : 254
Protocol : ICMP (1)
Header Checksum : 0xa164 [validation disabled]
Header checksum status : Unverified
Source Address : 10.1.2.1
Source or Destination Address : 10.1.2.1
Source Host : 10.1.2.1
Source or Destination Host : 10.1.2.1
Destination Address : 10.4.5.5
Source or Destination Address : 10.4.5.5
Destination Host : 10.4.5.5
Source or Destination Host : 10.4.5.5
Stream index : 1
icmp : Internet Control Message Protocol
Type : Echo (ping) request (8)
Code : 0
Checksum : 0x2619 [correct]
Checksum Status : Good
Identifier (BE) : 9 (0x0009)
Identifier (LE) : 2304 (0x0900)
Sequence Number (BE) : 1 (0x0001)
Sequence Number (LE) : 256 (0x0100)
ICMP Data : 00000000002857ffabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd
data
Data : 00000000002857ffabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd
Length : 72
Rendered from a Wireshark PCAP by VisualEther.
Transport mode (capture 1)Tunnel mode (capture 2)
ProtectsThe payload of the packetThe whole original packet
IP headersOne, the originalTwo: a new outer one, and the original inside ESP
Next HeaderThe payload protocol, here ICMP (1)IPIP (4)
Who the peers areThe traffic's own endpointsGateways for whole networks
Size of the 100-byte ping124 bytes144 bytes

Routers between the gateways see only the outer header. With encryption, as in capture 5, an observer can't even tell which hosts are talking. Site-to-site VPNs use tunnel mode for this reason, and because the inner addresses can be private ranges that the network between the gateways can't route.

The TTLs show who routed what. The inner request has TTL 254: R1 sent it with 255, and R2 decremented it when routing it into the tunnel. The outer header has TTL 255, set by R2 itself.

Why is there a 2-second gap after IKE?

The ping arrives 2 seconds after IKE_AUTH, and it is sequence number 1, not 0. Cisco's ping starts at 0 and waits 2 seconds for each reply, so the likely story is that echo 0 reached R2 with no tunnel up, started the IKE negotiation, and was dropped. The capture, taken between R2 and R3, can't show the dropped echo, so this is a reading of the evidence rather than proof.

Capture 3: transport mode through a NAT

R6 has a private address, 192.168.0.6. R3 translates it to 10.3.4.6 for the outside, so R4 believes it is talking to 10.3.4.6. The capture was taken on R6's side of the NAT, so every frame shows the private address.

sequenceDiagram accTitle: IPsec transport mode through a NAT accDescr: R6 sends IKE_SA_INIT on UDP port 500 with NAT detection hashes. R4 answers, and the hashes show a NAT. R6 sends IKE_AUTH on UDP port 4500 and R4 answers on 4500. R6 then sends its ping as ESP inside UDP port 4500, and R4 replies the same way. participant A as R6 (behind NAT) participant B as R4 A->>B: [1] IKE_SA_INIT, UDP 500, NAT detection hashes B->>A: [2] IKE_SA_INIT, UDP 500, hashes reveal the NAT A->>B: [3] IKE_AUTH, UDP 4500, Non-ESP Marker B->>A: [4] IKE_AUTH, UDP 4500 A->>B: [5] UDP 4500, ESP, ping B->>A: [6] UDP 4500, ESP, reply
Capture 3 at a glance. After the NAT is detected, IKE and ESP move to UDP port 4500. Frame numbers are in brackets.

How does IKEv2 detect a NAT?

With the two NAT detection notifies in IKE_SA_INIT. Each holds a SHA-1 hash of the IKE SPIs, an IP address, and a port (RFC 7296 section 2.23). NAT_DETECTION_SOURCE_IP hashes the address and port the sender thinks it is sending from, and NAT_DETECTION_DESTINATION_IP the ones it is sending to. The receiver hashes the addresses it actually sees and compares.

The hashes can't be reversed, but the candidate addresses are few, so we hashed them to see what each side put in:

FrameSenderSource hash coversDestination hash covers
1R6192.168.0.6, port 50010.3.4.4, port 500
2R410.3.4.4, port 50010.3.4.6, port 500

R4's destination hash shows it addressed its reply to 10.3.4.6. That hash is our only source for the translated address; it appears in no frame. Each side now finds a mismatch:

In capture 1, by contrast, every hash matches the real addresses, and IKE stays on port 500.

Why does IPsec switch to UDP port 4500?

Because ESP has no ports, and a NAT needs them. A NAT that shares one public address among many hosts tells their traffic apart by port number. ESP is a bare IP protocol, so many NATs drop it or can track only one host's. NAT traversal (NAT-T) gives ESP a UDP header the NAT can translate (RFC 3948).

Once a NAT is detected, the initiator moves IKE to UDP port 4500 (RFC 7296 section 2.23), as frame 3 shows. Port 4500 now carries both IKE and ESP, so each IKE message starts with a 4-byte Non-ESP Marker of all zeros. An ESP SPI is never zero, so the receiver can tell the two apart (RFC 3948 section 2.2).

Frame 5 shows the result: IP, then UDP 4500 to 4500, then the ESP header, then the ping, still in transport mode. The UDP checksum is zero, as RFC 3948 section 2.1 recommends; ESP's ICV already protects the contents. The UDP header adds 8 bytes, making the packet 132 bytes.

What breaks in transport mode behind a NAT?

TCP and UDP checksums include the source and destination IP addresses, and the NAT changed them. In transport mode the original header is the only header, so after decryption the receiver must correct those checksums using the original addresses, which IKEv2 exchanges in the traffic selectors (RFC 3948 section 3.1.2, RFC 7296 section 2.23.1). An ICMP checksum doesn't cover the addresses, so this ping needs no correction.

Capture 4: tunnel mode through a NAT

This time R4, outside the NAT, starts the negotiation, sending to R6's public address 10.3.4.6. That works only because R3 has a static translation for R6. With dynamic NAT, no mapping would exist until R6 sent something first.

The NAT detection plays out as in capture 3, from the other side. R4's destination hash covers 10.3.4.6, which tells R6 it is behind a NAT. R6's source hash covers 192.168.0.6, which tells R4 the same about its peer. IKE_AUTH moves to port 4500.

What does a tunnel-mode packet look like through a NAT?

R5, behind R4, pings 10.6.6.6, a loopback address on R6. Frame 5 is the most deeply nested packet in these captures:

  1. Outer IP, 10.3.4.4 to 192.168.0.6. R4 sent it to 10.3.4.6; R3 rewrote the destination.
  2. UDP, port 4500 to 4500, checksum zero.
  3. ESP, SPI 0xe09b01d1, Next Header IPIP (4).
  4. Inner IP, 10.4.5.5 to 10.6.6.6, carrying the ICMP echo request.

The 100-byte ping becomes 152 bytes: 20 for the outer IP header, 8 for UDP, 8 for the ESP header, 4 for padding and trailer, and 12 for the ICV.

The NAT rewrites only the outer header. The inner packet, and its checksums, arrive untouched, so tunnel mode needs none of the checksum correction that capture 3 does.

The reply in frame 6 comes from 10.6.6.6 with an inner TTL of 255. R6 owns that address, so it builds the reply and puts it straight into the tunnel, without routing it first.

Capture 5: the same tunnel, encrypted with AES

The same gateways, R2 and R4, and the same IKE exchange as capture 2. This time the Child SA encrypts.

What can you see in an encrypted ESP packet?

Only the outer IP header, the SPI, and the sequence number. Compare this decode of frame 5 with the one from capture 2 above:

🔒 [00005] Frame 5 ESP SPI 0x6db74143 2020-04-19T23:59:52.26517Z 🔐 R2 (tunnel gateway) → 🔐 R4 (tunnel gateway)
frame : Frame 5: Packet, 182 bytes on wire (1456 bits), 182 bytes captured (1456 bits) on interface -, id 0
Section number : 1
Interface id : 0 (-)
Interface name : -
Encapsulation type : Ethernet (1)
Arrival Time : Apr 20, 2020 05:29:52.265170000 India Standard Time
UTC Arrival Time : Apr 19, 2020 23:59:52.265170000 UTC
Epoch Arrival Time : 1587340792.265170000
Time shift for this packet : 0.000000000 seconds
Time delta from previous captured frame : 1.978864000 seconds
Time delta from previous displayed frame : 1.978864000 seconds
Time since reference or first frame : 2.003622000 seconds
Frame Number : 5
Frame Length : 182 bytes (1456 bits)
Capture Length : 182 bytes (1456 bits)
Frame is marked : False
Frame is ignored : False
Protocols in frame : eth:ethertype:ip:esp
Character encoding : ASCII (0)
eth : Ethernet II, Src: aa:bb:cc:00:02:10, Dst: aa:bb:cc:00:03:10
Destination : aa:bb:cc:00:03:10
Destination (resolved) : aa:bb:cc:00:03:10
Destination OUI : aa:bb:cc
.... ..1. .... .... .... .... = LG bit : Locally administered address (this is NOT the factory default)
.... ...0 .... .... .... .... = IG bit : Individual address (unicast)
Address : aa:bb:cc:00:03:10
Address (resolved) : aa:bb:cc:00:03:10
Address OUI : aa:bb:cc
.... ..1. .... .... .... .... = LG bit : Locally administered address (this is NOT the factory default)
.... ...0 .... .... .... .... = IG bit : Individual address (unicast)
Source : aa:bb:cc:00:02:10
Source (resolved) : aa:bb:cc:00:02:10
Source OUI : aa:bb:cc
.... ..1. .... .... .... .... = LG bit : Locally administered address (this is NOT the factory default)
.... ...0 .... .... .... .... = IG bit : Individual address (unicast)
Address : aa:bb:cc:00:02:10
Address (resolved) : aa:bb:cc:00:02:10
Address OUI : aa:bb:cc
.... ..1. .... .... .... .... = LG bit : Locally administered address (this is NOT the factory default)
.... ...0 .... .... .... .... = IG bit : Individual address (unicast)
Type : IPv4 (0x0800)
Stream index : 0
ip : Internet Protocol Version 4, Src: 10.2.3.2, Dst: 10.3.4.4
0100 .... = Version : 4
.... 0101 = Header Length : 20 bytes (5)
Differentiated Services Field : 0x00 (DSCP: CS0, ECN: Not-ECT)
0000 00.. = Differentiated Services Codepoint : Default (0)
.... ..00 = Explicit Congestion Notification : Not ECN-Capable Transport (0)
Total Length : 168
Identification : 0x00e9 (233)
000. .... = Flags : 0x0
0... .... = Reserved bit : Not set
.0.. .... = Don't fragment : Not set
..0. .... = More fragments : Not set
...0 0000 0000 0000 = Fragment Offset : 0
Time to Live : 255
Protocol : Encap Security Payload (50)
Header Checksum : 0x9f30 [validation disabled]
Header checksum status : Unverified
Source Address : 10.2.3.2
Source or Destination Address : 10.2.3.2
Source Host : 10.2.3.2
Source or Destination Host : 10.2.3.2
Destination Address : 10.3.4.4
Source or Destination Address : 10.3.4.4
Destination Host : 10.3.4.4
Source or Destination Host : 10.3.4.4
Stream index : 0
esp : Encapsulating Security Payload
ESP SPI : 0x6db74143 (1840726339)
ESP Sequence : 1
Rendered from a Wireshark PCAP by VisualEther.

Wireshark stops after ESP Sequence. The inner IP header, the ICMP message, the padding, and even the Next Header field are ciphertext. An observer can't tell whether this is tunnel or transport mode, or what protocol is inside.

The size still gives the cipher away. The packet is 168 bytes, 24 more than the 144 bytes in capture 2. That fits AES in CBC mode exactly:

The Child SA's algorithms were negotiated inside the encrypted IKE_AUTH, so AES-CBC with a 12-byte ICV is an inference from the sizes, not something the capture states.

Comparing the five captures

CaptureModeOuter layersNext HeaderIP packet for a 100-byte pingOverhead
1TransportIPICMP (1)124 bytes24
2TunnelIPIPIP (4)144 bytes44
3Transport, NAT-TIP, UDP 4500ICMP (1)132 bytes32
4Tunnel, NAT-TIP, UDP 4500IPIP (4)152 bytes52
5Tunnel, AESIPEncrypted168 bytes68

Every capture shares the same 24 bytes of ESP-NULL overhead: an 8-byte header, 4 bytes of padding and trailer, and a 12-byte ICV. Tunnel mode adds 20 for the outer IP header, NAT-T adds 8 for UDP, and AES-CBC adds 24 for the IV and block padding. On a link with a 1500-byte MTU, that overhead is why VPN tunnels often lower the TCP MSS (maximum segment size) or the tunnel MTU.

Why use ESP-NULL at all?

RFC 2410 defines NULL encryption so that ESP can provide integrity and replay protection without confidentiality. Each packet is still authenticated by its ICV and counted by its sequence number. It suits traffic that must not be tampered with but needn't be secret, or networks where monitoring tools must see inside the packets.

A receiver knows an SA uses NULL encryption because IKE said so. Wireshark doesn't have the IKE keys, so it can't know, and by default it shows ESP-NULL packets as opaque, just like AES. Its esp.enable_null_encryption_decode_heuristic preference tells it to try reading the payload as clear text. Turn it on only for captures you know use ESP-NULL. These four decode cleanly with it: valid Next Header values, padding bytes counting 01 02 as RFC 4303 specifies, and correct ICMP checksums.

Frequently asked questions

What is the difference between IPsec transport mode and tunnel mode? Transport mode keeps the original IP header and protects only what follows it. Tunnel mode protects the whole original packet and adds a new outer IP header between the two gateways. In a capture, ESP's Next Header shows the difference: the payload protocol (ICMP here) for transport mode, IPIP (4) for tunnel mode.

Which ports does IPsec use? IKE uses UDP port 500, and UDP port 4500 once a NAT is detected. ESP itself is IP protocol 50 with no ports, unless NAT-T wraps it in UDP port 4500.

What is NAT-T in IPsec? NAT traversal: when IKE detects a NAT between the peers, both IKE and ESP move to UDP port 4500, so the NAT has ports to translate. Captures 3 and 4 show it.

How does IKEv2 know there is a NAT? Each side sends hashes of the addresses and ports it thinks it is using. If the hash doesn't match what the other side sees, an address was translated on the way.

Is ESP-NULL secure? It protects integrity, not confidentiality. Packets can't be altered or replayed undetected, but anyone on the path can read them, as these captures show.

Takeaways

  1. IKE sets up the keys; ESP carries the data. IKEv2 needs four messages, and the last two are already encrypted.
  2. Next Header tells transport from tunnel mode. ICMP (or TCP, UDP) means transport mode; IPIP (4) means a whole packet is inside.
  3. Each direction is a separate SA with its own SPI and its own sequence counter.
  4. NAT detection works by hashing addresses. A mismatch moves IKE and ESP to UDP port 4500, with a Non-ESP Marker to tell IKE from ESP.
  5. Tunnel mode passes through NAT more cleanly, because the NAT never touches the inner packet's checksums.
  6. Encrypted ESP still leaks sizes. The 24 extra bytes in capture 5 point to AES-CBC, even though the cipher was negotiated in secret.