Internet checksum of a short header — parity and checksum

exam standardone's-complement sum, then complement

Answer

3A7B

Why this example is worth doing

The RFC 1071 checksum: sum the 16-bit words with end-around carry, then complement the result. Its useful property is that summing the whole header including the checksum field yields all ones, so the receiver's check is a comparison against a constant. The page shows the verification pass as well as the computation, since that is the half usually omitted.

Try your own input in the Parity & checksum. Even and odd parity, one’s-complement sums and the Internet checksum, step by step.

How the answer is reached

Internet checksum (RFC 1071) over 10 bytes

Adjacent octets are paired into big-endian 16-bit integers and added with end-around carry.

One’s-complement addition: whenever the total exceeds 0xFFFF the carry is added back into the low 16 bits. — Internet checksum (RFC 1071) over 10 bytes
WordRunning sum+ wordEnd-around carryNew running sum
0x45000x00000x4500no0x4500
0x00730x45000x4573no0x4573
0x00000x45730x4573no0x4573
0x40000x45730x8573no0x8573
0x40110x85730xC584no0xC584

One's-complement sum0xC584RFC 1071 prints this value in its example

Checksum0x3A7Bthe complement of the sum — this is what goes in the packet

Verification0xC584 — not 0xFFFFsumming the octets *including* the checksum field must give 0xFFFF

Warning:

The transmitted checksum is the complement of the sum. RFC 1071’s worked example prints 0xDDF2, which is the sum, not the checksum (that is 0x220D). In UDP a computed value of 0x0000 is transmitted as 0xFFFF, which comes from RFC 768 rather than RFC 1071.

Source: RFC 1071, "Computing the Internet Checksum"

Compare with

Open this example in the Parity & checksum

The field arrives filled in with this example’s input.

Note:

Notation this page assumes

  • Bit strings are written most significant bit first, and bit 0 is the least significant bit.
  • A width is stated explicitly wherever it changes the answer; nothing is silently sign-extended or truncated.
  • The parity bit is appended after the data bits, and a checksum is stated with the byte order it was summed in.

Sources

  • Hamming, “Error Detecting and Error Correcting Codes” (1950)
  • Braden, Borman and Partridge, RFC 1071, “Computing the Internet Checksum” (1988)