The Internet Checksum: How It's Computed and What It Catches
How the 16-bit Internet checksum used by IPv4, ICMP, UDP and TCP is computed step by step, how routers update it after changing TTL, what corruption it catches and misses, and why captures show "bad" checksums caused by offload.
kvi5hnuCode Sprout team member14 min readOn this page
The IPv4 header, ICMP, IGMP, UDP and TCP all protect their bytes with the same simple algorithm, called the Internet checksum. It's defined in RFC 1071, with the incremental-update rules in RFC 1624. It's quick to compute in software, which mattered a great deal on 1980s hardware, and it catches most random damage. It's also much weaker than the CRC an Ethernet card computes, and this article shows exactly where it fails.
The algorithm in one sentence
The checksum is the one's complement of the one's complement sum of the data, taken as 16-bit words. In steps:
- Set the checksum field to zero.
- Treat the data as a sequence of 16-bit big-endian words. If there's an odd number of bytes, pad the last one with a zero byte for the calculation only.
- Add the words. Whenever the sum overflows 16 bits, add the carry back into the low 16 bits. This is called end-around carry, and it's what makes the sum a one's complement sum.
- Invert every bit of the result (this inversion is the "one's complement" of a number). That's the checksum.
To check, the receiver adds all the words, including the checksum, the same way. If nothing changed, the result is 0xFFFF (all ones), and inverting it gives zero.
A worked example with a real header
In the lab, client (192.0.2.10) pinged server (198.51.100.10), and the IPv4 header of the echo request was captured. Its ten 16-bit words, first as captured and then with the checksum field (the sixth word) set to zero:
The 20-byte header as ten 16-bit words (checksum field shown, then replaced by 0000):
4500 003c 795c 4000 4001 d51c c000 020a c633 640a
4500 003c 795c 4000 4001 0000 c000 020a c633 640a
Adding the words one at a time:
00000 + 4500 = 04500
04500 + 003c = 0453c
0453c + 795c = 0be98
0be98 + 4000 = 0fe98
0fe98 + 4001 = 13e99
13e99 + 0000 = 13e99
13e99 + c000 = 1fe99
1fe99 + 020a = 200a3
200a3 + c633 = 2c6d6
2c6d6 + 640a = 32ae0
plain sum: 0x32ae0
fold carry: 0x2ae0 + 0x3 = 0x2ae3
one's complement sum: 0x2ae3
checksum = ~0x2ae3 = 0xd51c (value in the captured packet: 0xd51c)
The last step in binary: 0x2ae3 is 0010 1010 1110 0011, and inverting every bit gives 1101 0101 0001 1100, which is 0xd51c. The figure summarizes the four steps on this header.

The receiver's check, summing all ten words including the checksum:
receiver sums all ten words including the checksum: 0xffff -> header OK
You don't have to fold the carries after every addition. Summing everything into a wider (say 32-bit) register and folding at the end gives the same answer, because one's complement addition is commutative and associative. That's also why the result doesn't depend on the machine's byte order, as long as you're consistent: RFC 1071 points out you can sum in little-endian order and swap the bytes of the result at the end.
Why one's complement arithmetic?
One's complement addition has useful properties. Order doesn't matter, so the sum can be computed in pieces and combined, or updated when one field changes. It also treats 0x0000 and 0xFFFF as two forms of zero ("+0" and "−0"). Mathematically, the 16-bit values 0x0001 to 0xFFFF with this addition form a commutative group, with 0xFFFF as the identity element. 0x0000 must be left out, because a group can have only one identity.
One practical consequence: for any real header the computed sum can't be zero (that would need every word to be zero), so the IPv4 header checksum field never contains 0xFFFF. UDP uses this: a transmitted checksum of zero means "no checksum computed", so a UDP sender whose computed checksum is zero sends 0xFFFF instead (article 45).
Updating the checksum after changing TTL
A router decrements TTL on every packet it forwards, which changes the header, so the checksum must change too. Recomputing it from scratch is wasteful. RFC 1624 gives an incremental formula. If a 16-bit word changes from m to m', the new checksum is:
where HC is the old header checksum, HC' the new one, ~ means bitwise NOT and + is one's complement addition. Here is the same ping captured before and after the lab router, with the formula applied:
before the router: TTL 64, word 5 (TTL|Protocol) = 0x4001, checksum 0xd51c
after the router: TTL 63, word 5 (TTL|Protocol) = 0x3f01, checksum 0xd61c
RFC 1624: HC' = ~(~HC + ~m + m') = ~(0x2ae3 + 0xbffe + 0x3f01) = 0xd61c
Step by step: ~HC = ~0xd51c = 0x2ae3 and ~m = ~0x4001 = 0xbffe. Then 0x2ae3 + 0xbffe = 0xeae1, and 0xeae1 + 0x3f01 = 0x129e2, which folds to 0x29e2 + 0x1 = 0x29e3. Inverting gives 0xd61c. The formula's result matches what the router actually put in the packet. Since TTL sits in the high byte of its word, decrementing it by 1 lowers that word by 0x0100, so the checksum rises by 0x0100 at every hop (apart from carry effects). You can see the same pattern in the three-link table in article 23.
What the checksum covers in each protocol
| Protocol | Checksum covers | If it fails |
|---|---|---|
| IPv4 | The IPv4 header only | Datagram silently dropped |
| IPv6 | (no header checksum) | — |
| ICMPv4 | ICMP header and data | Message dropped |
| ICMPv6 | ICMPv6 message plus an IPv6 pseudo-header | Message dropped |
| UDP | UDP header, data and a pseudo-header (IPv4: optional, 0 = none; IPv6: mandatory) | Datagram dropped |
| TCP | TCP header, data and a pseudo-header | Segment dropped (and later retransmitted by the sender) |
The pseudo-header isn't sent. It's a set of IP fields, namely the source and destination addresses, the protocol number and the length, that the transport checksum includes in its calculation. If a router or a bit error delivered a segment to the wrong address, the receiver's computed pseudo-header differs, the checksum fails, and the segment is dropped. This strictly violates layering, because the transport layer looks at IP addresses, but it's what lets IPv6 do without a header checksum. Article 45 shows the pseudo-header for UDP in detail.
No protocol sends an error message when a checksum fails. A damaged packet might have damaged addresses, so the receiver can't be sure whom to tell. The data is simply missing, and it's up to the sender (TCP) or the application (UDP) to notice.
Watching the checksums catch corrupted packets
To see the checksums at work, the lab used netem (Linux's network emulator, which can add delay, loss or corruption to an interface) to flip one random bit in about 3% of the frames client sent, and then sent 5,000 pings to server through router r1. Each request is a 98-byte frame: a 14-byte Ethernet header, a 20-byte IPv4 header and 64 bytes of ICMP.
5000 packets transmitted, 4860 received, 2.8% packet loss, time 1664ms
rtt min/avg/max/mdev = 0.001/0.005/1.644/0.030 ms, ipg/ewma 0.332/0.004 ms
Only the first line matters here: 140 of the 5,000 requests got no reply. (The rtt line gives the minimum, average and maximum round-trip times.) The kernel's counters show where each damaged request was caught:
router r1: IpExtInCsumErrors 25 (IPv4 header checksum failed, packet dropped)
server: IcmpInCsumErrors 100 (ICMP checksum failed, packet dropped)
requests sent 5000, replies 4860, lost 140
caught by the IPv4 header checksum at the router: 25
caught by the ICMP checksum at the server: 100
dropped before IP (bit flipped in the Ethernet header): 15

The chart shows the same split. It follows the byte counts. A random bit lands in the 64 ICMP bytes about two-thirds of the time, and the ICMP checksum caught those at the server. Bits in the 20-byte IPv4 header were caught one hop earlier, by the router, which checks the header checksum before forwarding. A bit in the Ethernet header usually made the frame look addressed to another host or to an unknown protocol, so it was dropped before IP looked at it. A flip in the 6-byte source MAC address goes unnoticed, which is why the measured loss is a little below 3%. Every corrupted packet that reached a checksum was caught, because the checksum always detects a single flipped bit.
What the checksum misses
The Internet checksum is simple addition, so it is blind to changes that leave the sum the same. Computed in the lab for a 24-byte message:
data Internet checksum CRC-32
original 0x2c13 0x8a272c53
two 16-bit words swapped 0x2c13 0x0bdb66c8
block of zero bytes added 0x2c13 0x1e03188f
one bit flipped 0x2b13 0x0b024974
- Reordered 16-bit words give the same sum, because addition doesn't care about order. CRC-32 notices.
- Inserted or deleted zero words add nothing to the sum.
- Two errors that cancel out, such as one word increasing by 1 and another decreasing by 1, go undetected.
- Any single-bit error is caught, as the corruption experiment showed.
In practice, links protect frames with a strong CRC, and most corruption happens there, in transit, where the CRC catches it. Damage that the Internet checksum must catch happens inside routers, network cards and memory, where no CRC protects the data. A large study of real traffic traces, published in 2000, estimated that a small but real fraction of packets, somewhere between about one in 16 million and one in 10 billion, carry errors that the TCP checksum fails to detect. That's why applications that care about integrity add their own protection. TLS (article 83) authenticates every record cryptographically, which detects any change at all, and storage and file-transfer tools use strong hashes.
"Incorrect" checksums in your own captures
If you capture on the machine that's sending, you'll often see TCP and UDP checksums flagged as wrong. Here are the first packets of a TCP connection captured on the lab client. In tcp.flags.str, each dot is one TCP flag that is off, and a letter is a flag that is on: S is SYN (the first packet of a connection), A is ACK and P is PSH (article 58):
frame.number tcp.flags.str tcp.checksum tcp.checksum.status
1 ··········S· 0xec76 1
3 ·······A···· 0xec6e 1
4 ·······AP··· 0xec74 1
tcp.checksum.status 1 means "good" here only because current Wireshark recognizes what's going on, as its detailed view says:
Checksum: 0xec76 [correct] (matches partial checksum, not 0x2f9d, likely caused by "TCP checksum offload")
[Expert Info (Note/Checksum): Partial (pseudo header) checksum (likely caused by "TCP checksum offload")]
The operating system didn't compute the full checksum. It filled in only the pseudo-header part and left the rest to the network card, a feature called checksum offload. The capture taps the packet before the card finishes the job. After turning offload off on that interface (ethtool -K eth0 tx off), the kernel computes full checksums itself, and the captured values change:
frame.number tcp.flags.str tcp.checksum tcp.checksum.status
1 ··········S· 0xd994 1
3 ·······A···· 0xe6ae 1
4 ·······AP··· 0xa2c4 1
Offload is on by default almost everywhere:
tx-checksumming: on
tcp-segmentation-offload: on
Common questions
Is the Internet checksum a CRC?
No. It's a one's complement sum, which is cheaper but much weaker. Ethernet, Wi-Fi and most other links use a 32-bit CRC on every frame. The Internet checksum is a second, end-to-end check that also covers corruption inside routers and hosts, where no CRC applies.
Why do routers recompute the IPv4 checksum but not the TCP checksum?
A router changes only the IP header (TTL, sometimes the ECN or DSCP bits that article 25 covers), and the TCP checksum doesn't cover those fields. The TCP pseudo-header includes only the addresses, protocol and length, none of which a plain router changes. A NAT device changes addresses and ports, so it must update both the IP and the TCP or UDP checksums, and it uses the same incremental formula to do so.
Does a correct checksum prove the data wasn't changed?
No. It only shows that no accidental error the sum can detect happened. Anyone who changes a packet on purpose can simply recompute the checksum. Protection against deliberate changes needs cryptography: TLS, IPsec or an application-level signature.
If IPv6 has no header checksum, what stops a corrupted address from being used?
The transport checksum. UDP, TCP and ICMPv6 all include the source and destination addresses in their pseudo-header, and UDP's checksum is mandatory over IPv6. A packet whose address was damaged reaches the wrong host or claims the wrong sender, the pseudo-header doesn't match, and the receiver drops it.
Why does Wireshark say "validation disabled" for the IP checksum?
Wireshark doesn't check checksums by default, because with offload it would flag huge numbers of false errors. You can turn validation on in the protocol preferences, or on the command line with -o ip.check_checksum:TRUE or -o tcp.check_checksum:TRUE.
Can the checksum be computed with a 32-bit or 64-bit adder?
Yes, and fast implementations do exactly that: they add 32 or 64 bits at a time and fold the carries down to 16 bits at the end. The result is the same because one's complement addition is associative and commutative.
Summary
- The Internet checksum is the one's complement of the one's complement (end-around carry) sum of 16-bit words. The receiver's sum over everything, checksum included, must be
0xFFFF. - IPv4 checksums only its header. ICMP, UDP and TCP checksum their whole message plus a pseudo-header of IP fields. IPv6 has no header checksum.
- Routers update the IPv4 checksum incrementally after changing TTL, using RFC 1624's
~(~HC + ~m + m'). The lab capture matched the formula exactly. - A failed checksum means a silent drop, with no error message.
- The checksum catches every single-bit error but misses reordered words, added zeros and errors that cancel. Strong integrity needs CRCs on links and cryptography end to end.
- Wrong-looking checksums on packets sent by the capturing host are usually caused by checksum offload, not real errors.
Practice questions
1. Compute the one's complement sum and the checksum of the words 0x8000, 0x8000, 0x0001.
Answer
0x8000 + 0x8000 = 0x10000. Fold the carry: 0x0000 + 0x1 = 0x0001. Add 0x0001: sum 0x0002. The checksum is ~0x0002 = 0xFFFD. Check: 0x0002 + 0xFFFD = 0xFFFF.
2. A header word changes from 0x4001 to 0x3f01 and the old checksum was 0x1c46. Use RFC 1624 to find the new checksum.
Answer
~HC = 0xe3b9, ~m = 0xbffe, m' = 0x3f01. Sum: 0xe3b9 + 0xbffe = 0x1a3b7, fold to 0xa3b8; add 0x3f01: 0xe2b9. Invert: HC' = 0x1d46. As expected, decrementing TTL by one raised the checksum by 0x0100.
3. A capture taken on a laptop shows every outgoing TCP segment with a checksum Wireshark calls incorrect, while incoming segments are fine. What is the most likely explanation?
Answer
Transmit checksum offload. The laptop's network card computes the real checksum after the capture point, so the capture sees only the partial value the operating system filled in. The packets on the wire are correct.
4. An application sends a UDP message and two of its 16-bit words are swapped in a faulty router's memory. Will the receiver's UDP checksum detect it? What would?
Answer
No. Swapping words doesn't change a one's complement sum, so the checksum still matches. A stronger check would detect it: a CRC (if the damage happened on a link), or end-to-end cryptographic integrity such as TLS, DTLS (TLS for datagrams) or QUIC, or an application-level hash.
5. Why doesn't a host send an ICMP error when it receives a packet with a bad IPv4 header checksum?
Answer
Because the header is known to be damaged, the source address in it may be wrong too. An error message could go to an innocent host. The packet is just dropped, and the transport or the application deals with the loss.
6. In the corruption experiment, why were IPv4 header errors caught at the router but ICMP errors only at the server?
Answer
A router must verify the IPv4 header checksum before forwarding, since it reads and changes the header. It doesn't look at the ICMP message inside, which is end-to-end data. Only the destination host checks the ICMP checksum.
Previous: The IPv4 and IPv6 Headers, Field by Field
Next: Differentiated Services and ECN: Marking Packets for Priority and Congestion

More in TCP/IP Course
Quiz: TCP/IP Delicate Details
Twenty-five questions on the details that catch out experienced engineers: sequence numbers for SYN and FIN, TIME_WAIT versus tcp_fin_timeout, Karn's algorithm, socket buffer doubling, even and odd ephemeral ports, IPv6 checksums and fragmentation, negative DNS caching, and capture filter traps.
Quiz: TCP/IP Interview Questions
Thirty-three networking questions of the kind asked in developer, SRE and network engineering interviews: what happens when you load a URL, TCP versus UDP, handshakes, closing and TIME_WAIT, subnetting, NAT, DNS, MTU problems, congestion, TLS and QUIC, and debugging slow or failing connections.
Quiz: TCP/IP Course Final Exam (All Parts)
The final exam for the TCP/IP course: thirty questions across all fourteen parts, from packets and addressing through Ethernet, ARP, IP, DHCP, NAT, ICMP, UDP, DNS, TCP connections, reliability, congestion control, security, QUIC and troubleshooting.
Quiz: Modern Transports and Troubleshooting (TCP/IP Part 14)
Review modern transports and troubleshooting: QUIC packets, handshakes, 0-RTT, streams and connection migration, HTTP/3, Multipath TCP, SCTP multihoming, and a layered method for diagnosing real network faults.
Discussion
Sign in to ask a question or share what you learned.