Packet Path/

IPsec Invalid SPI Explained: When One End Rebuilds the Tunnel and the Other Never Notices

Every IPsec session is stamped with a number called an SPI — a security parameter index — that tells the receiving router exactly which session, keys and rules an encrypted packet belongs to. When the two ends of a tunnel disagree about the current session, one side keeps sending packets stamped with an SPI the other side deleted when it rebuilt the tunnel. The receiver looks the number up, finds nothing, drops the packet and logs %CRYPTO-4-RECVD_PKT_INV_SPI. The tunnel interface still looks up, the management session may still look alive, and no user traffic passes — which is why this fault so often appears minutes after a brief outage that everyone thought had already healed.

VPN · Intermediate · 11 min · November 24, 2026

Editorial illustration on a dark teal background: two network routers at opposite ends of a glowing encrypted VPN tunnel, one router holding a fresh set of glowing key tags while the other still sends packets stamped with an old faded key tag that bounces off a shield at the receiving router and drops away as fragments.

The short answer

What does an IPsec invalid SPI error mean? One end of a VPN tunnel is sending encrypted packets stamped with a session number — an SPI — that the receiving router no longer has. The receiver cannot match the packet to any live session, so it cannot decrypt it, and it drops the packet and logs %CRYPTO-4-RECVD_PKT_INV_SPI: decaps: rec'd IPSEC packet has invalid spi. In almost every case the two ends disagree about which session is current: one side rebuilt the tunnel (after a reboot, a bounce, or a rekey) and moved to a fresh session, while the other side is still sending on the old one. The fix is to clear the stale session for that one peer so both sides rebuild together, then remove the reason they drifted apart — usually Dead Peer Detection being off or mismatched, or lifetimes that differ wildly between the ends.

Picture two offices that shred and reissue their visitor badges every few hours. Every sealed parcel between them must carry a current badge number, and the receiving office checks the number against today's list before opening anything. Now one office's badge printer breaks, a new list is issued at that end — and nobody tells the other office. Parcels keep arriving with yesterday's badge number. The receiving office is not being difficult when it bins them: a parcel whose badge matches nothing on the list could be anything, so the rule is drop it and write it in the log. That log entry is the invalid SPI message. The offices are still connected, the phone line between them still works — the parcels are simply stamped with a session the receiver has already thrown away.

In plain EnglishIPsec: the standard way routers encrypt traffic between sites, so packets cross the public internet sealed. ESP (Encapsulating Security Payload): the part of IPsec that actually encrypts the packets; it travels as IP protocol 50. SPI (security parameter index): a 32-bit number in every ESP packet header that names the session the packet belongs to. Security association (SA): one stored session — the keys, algorithms and counters for traffic in one direction. Each direction of a tunnel has its own SA and its own SPI, chosen by the receiving end. Rekey: the scheduled replacement of a session's keys (and SPIs) when its lifetime expires. Dead Peer Detection (DPD): a keepalive between the peers that notices when the other end has died, so dead sessions get cleaned up instead of lingering.

How the receiver decides a packet is an orphan

When an ESP packet arrives, the router does not start by decrypting it. It reads three things from the outside of the packet — the destination address, the protocol (50 for ESP), and the SPI — and looks that combination up in its database of live sessions. That lookup is the whole design: the SPI is how one router can hold hundreds of tunnels and still know instantly which keys a given packet needs. If the lookup finds a session, decryption proceeds. If it finds nothing, there is no safe fallback — guessing keys is not an option — so the packet is dropped and the invalid-SPI message is logged with the destination, the protocol, the SPI value itself, and the sender's address. Every field in that log line is a clue: the SPI is the exact number to go hunting for in your own session table.

One tunnel, two ideas of the current sessionPeer A — never noticedstill holds the OLD sessionsends ESP stampedwith the old SPIbelieves tunnel is upPeer B — rebuiltrebooted or rekeyedold session deletedexpects the NEW SPIdrops old-SPI packets, logs errorESP packets, old SPIno matching session: drop

Neither router is broken. Each is correctly following its own session table — the tables simply disagree, and the receiver's drop is the only safe answer to a packet it cannot place.

The three ways the two ends drift apart

1. One peer rebooted or bounced, and the other never noticed. This is the cause behind most cases. When a router restarts, its session database is empty; when the tunnel is re-established it negotiates fresh sessions with fresh SPIs. The surviving peer, if nothing told it the other end died, keeps its old outbound session and keeps encrypting onto it. Every one of those packets arrives stamped with a number the rebuilt peer has never heard of. The brief outage ends, the link comes back, the tunnel is declared restored — and the traffic black-holes until the stale side is cleaned up.

2. Lifetimes differ wildly between the ends. Sessions expire on timers — a time lifetime, a traffic-volume lifetime, or both — and expiry triggers a rekey to a fresh session. If the two ends' lifetimes are far apart, one side expires and rebuilds sessions on a rhythm the other side does not share, and any hiccup in the rekey negotiation leaves the same one-sided state as a reboot: one end on the new session, the other still trusting the old one. Aligned lifetimes do not make rekeys disappear; they make both ends expect them at the same time.

3. Dead Peer Detection is off, or set differently at each end. DPD exists precisely for cause 1: the peers probe each other, and a peer that stops answering gets its sessions torn down, so the next packets trigger a clean, mutual rebuild instead of hitting a stale table. With DPD off, a silent death leaves the survivor's sessions in place indefinitely — the stale state has no expiry mechanism except the lifetime timers. With DPD on at one end only, cleanup happens on one side's schedule, which can itself feed the desync. The setting is cheap; the mismatch is the expensive part.

Why the tunnel still looks up

This fault fools the first check most engineers run. The management session between the peers (the IKE session that negotiates and guards the tunnel) can be alive and current while the data sessions it produced are the stale ones — they are related, but they are not the same table. Interfaces stay up, the peer answers pings, monitoring that watches the tunnel's state rather than its traffic stays green, and users report the one symptom that matters: nothing passes. The invalid-SPI log is the router telling you which layer is lying. When a site-to-site tunnel is reported down, read the log before you read the session state — the message names the fault, the peer, and the exact SPI to compare.

Checks, in order

Step 1 — read the log line properly. Note the SPI value, the destination and the source address from the message itself, and check the log history (show logging | include CRYPTO) for how often it repeats. Once, right after a known restart, and then silence: that was the rebuild clearing its throat — confirm traffic passes and move on. Repeating every few minutes: a standing mismatch; continue.

Step 2 — compare the SPI against your own table. Run show crypto ipsec sa | include spi and look for the SPI from the log among the sessions this router expects to receive on. It will not be there — that absence is the smoking gun, and it confirms the sender is encrypting onto a session you no longer hold, rather than your router dropping good traffic.

Step 3 — check the management session. show crypto isakmp sa shows whether the negotiation session to that peer is alive and current. A live management session alongside invalid-SPI drops is the classic shape of this fault: negotiation healthy, data sessions desynchronised. It also tells you a rebuild has something healthy to build on.

Step 4 — compare the two ends' settings before you clear anything. Lifetimes and DPD configuration on both peers. This takes minutes while both ends are still in front of you, and it is the difference between fixing the fault and scheduling its return — the clear in the next section will work either way, but only this step decides whether you will be back here after the next reboot.

The safe fix order

Clear one peer, not the world. The working fix is to clear the stale sessions for that peer only — clear crypto sa peer <ip> — which forces both sides to negotiate a fresh, matching set of sessions; traffic usually flows as soon as the rebuild completes. Scope the command to the one peer address. On a router terminating many tunnels, clearing all crypto sessions bounces every tunnel on the box to repair one, which turns a single-site fault into a self-inflicted outage.

Pick the moment. Clearing sessions drops the tunnel's traffic until the renegotiation finishes — normally seconds, but seconds matter on a production link carrying live work. This is a safe fix, not a free one: do it in a change window, or at least with the business warned, rather than the instant you spot the log line during peak traffic. The exception is a tunnel that is already passing nothing — then there is nothing left to lose and the clear is the fastest path back.

Then remove the cause. Turn DPD on at both ends with matching settings, so a dead peer's sessions are cleaned up automatically next time. Align the session lifetimes on both peers. Verify afterwards the way a sceptic would: the invalid-SPI messages stop, show crypto ipsec sa shows encapsulating and decapsulating packet counters both rising, and a real user flow — not just a ping to the peer address — crosses the tunnel.

What not to do

Do not reboot your router to clear the state: it works, the way demolishing a house fixes a stuck door, and it exports the outage to everything else the box carries. Do not clear sessions repeatedly as a standing remedy — if the message returns after a clean rebuild, the desync has a live cause (settings from step 4, or a peer that keeps bouncing) and repetition is masking it. And do not assume a quiet log after the fix means the settings are right: verify DPD and lifetimes match on both ends while you still have both ends open, because the next reboot is exactly when a mismatch you left behind will present this same fault again. For the exact log string itself — what each field means and the short-form checks — the companion decoder entry is %CRYPTO-4-RECVD_PKT_INV_SPI. For link-layer encryption between directly connected devices — a different mechanism from tunnel IPsec, with its own overhead cost — see MACsec Explained.

Try it yourself

When two tunnel ends may have drifted in configuration as well as in state, run both ends' configs through the free Network Config Verifier and compare what it flags on each side — mismatched settings are far easier to spot side by side than from memory in the middle of an incident.

Fact-check sources: the invalid-SPI message format, meaning and platform line, the stale-session causes (one peer rebooted or bounced while the other's session stayed stale; DPD off or mismatched; lifetimes differing wildly), the check order (show crypto isakmp sa; show crypto ipsec sa | include spi to compare expected SPIs against the logged SPI; show logging | include CRYPTO for frequency) and the fix (clear crypto sa peer, DPD on both ends with matching settings, align lifetimes) — Cisco IPsec troubleshooting documentation, as carried in this site's Error Decoder entry for %CRYPTO-4-RECVD_PKT_INV_SPI. SPI as a 32-bit value in the ESP header, looked up with the destination address and protocol to select the security association, ESP as IP protocol 50 — RFC 4303 (ESP) and RFC 4301 (IPsec architecture).

Related guides

Key takeaways

Keep reading