Course contents

Unit 7: TCP, UDP and PortsLesson 7.1.5 (5 of 23 in this unit)54 of 104 in the Network Fundamentals course

TCP checksum and urgent pointer

How the TCP checksum is calculated over the pseudo-header, header and data, why captures show bad checksums, and the legacy URG flag.

Intermediate · 8 min read

Covers Checksum, Pseudo-header, Offload and Urgent pointer.

Technical definition

TCP checksum is a 16-bit value that lets the receiver detect corruption in a segment. The sender adds up the segment, and a pseudo-header made from the IP addresses, as 16-bit words using one's-complement arithmetic, and stores the complement of the total. The receiver repeats the sum and discards the segment if it does not check out.

Why TCP needs its own checksum

An Ethernet frame ends with a CRC that catches errors on one link, and an IP header has a checksum for the header only. Neither covers the TCP data end to end. Routers and switches can also corrupt a packet in memory between links, where no CRC is checked. The TCP checksum is the end-to-end check: it protects the data, the TCP header and the addresses of both hosts.

What the checksum covers

What the TCP checksum covers
What the TCP checksum coversThe sender computes a 16-bit one's-complement sum over a pseudo-header of source IP, destination IP, protocol and TCP length, then the TCP header with the checksum field set to zero, then the data. The receiver repeats the sum and discards the segment if the result is not all ones.Pseudo-header (built from the IP header, not sent)Source IP · Destination IP · zero + protocol 6 · TCP lengthTCP header (checksum field counted as zero while summing)ports · sequence · acknowledgement · flags · window · checksum · urgent pointer · optionsTCP data (padded with one zero byte if the length is odd)Sender stores the one's complement of the sum in the Checksum field.Receiver sums everything including that field: all ones means no error found.
The pseudo-header is never sent; both ends build it from the IP header. That is how TCP catches a segment that was delivered to the wrong host, which a header-only checksum would miss.

The pseudo-header is made of the source IP, destination IP, a zero byte, the protocol number (6 for TCP) and the TCP length. It is never sent; each end builds it from the IP header it already has. Including it means a segment delivered to the wrong host, or with a rewritten address, fails the check. This is also why NAT devices must recalculate the checksum when they change an address.

How it is calculated: a worked example

  1. Split the data into 16-bit words, padding with a zero byte if the length is odd.
  2. Set the checksum field to 0.
  3. Add the words. If the sum overflows 16 bits, add the carry back in (this is one's-complement addition).
  4. Invert every bit of the result. That is the checksum.
A three-word example
A three-word exampleStep; Value; Note. Words: 0x1234, 0xABCD, 0x0F0F Pretend these are the whole segment Sum: 0x1234 + 0xABCD + 0x0F0F = 0xCD10 No carry, so nothing to fold Checksum: 0xFFFF − 0xCD10 = 0x32EF Stored in the checksum field Receiver: 0xCD10 + 0x32EF = 0xFFFF All ones: no error foundStepValueNoteWords0x1234, 0xABCD, 0x0F0FPretend these are the whole segmentSum0x1234 + 0xABCD + 0x0F0F = 0xCD10No carry, so nothing to foldChecksum0xFFFF − 0xCD10 = 0x32EFStored in the checksum fieldReceiver0xCD10 + 0x32EF = 0xFFFFAll ones: no error found

On small screens, swipe sideways or focus the diagram and use the arrow keys.

Read each row across. A different example with a carry: 0xC000 + 0x5000 = 0x11000, fold the carry to get 0x1001, and the checksum is 0xEFFE.

If one word changes in transit, the receiver's total is no longer all ones and the segment is discarded without any reply. TCP's retransmission timer (or duplicate acknowledgements) makes the sender send it again.

Limits of a 16-bit checksum

  • It is weak: swapped words, or two errors that cancel, go undetected. The link-layer CRC and application-level checks (such as TLS) cover that.
  • It guards against accidents only. Anyone who can change a segment can recompute the checksum.
  • UDP uses the same method, but IPv4 allows a UDP checksum of zero to mean "not used". TCP has no such option.

Checksum offload in a capture

Modern network cards calculate checksums in hardware. The operating system hands the card a segment with the field empty, and the card fills it in as the frame leaves. A capture taken on the sending host sees the segment before that happens, so Wireshark flags it as an incorrect checksum. That is normal. A capture taken on another machine, or on a mirror port, shows the correct value.

# Linux: show whether offload is on ethtool -k eth0 | grep checksum

rx-checksumming and tx-checksumming show on when the card does the work. Switch it off only to test a capture, not as a fix.

The urgent pointer

When the URG flag is set, the 16-bit urgent pointer field is valid. It holds an offset from the segment's sequence number to the last byte of "urgent" data, so urgent bytes can be handed to the application ahead of the normal stream. Telnet used it to carry an interrupt key press through a stuffed buffer.

In practice it is almost never used. The standards documents disagree on whether the pointer marks the last urgent byte or the byte after it, which led to interoperability trouble. RFC 6093 advises applications to avoid urgent data altogether. When you see URG in a capture it is nearly always a scan or an oddity, not real traffic.

Checksum and urgent pointer in short

  • The checksum is a 16-bit one's-complement sum over pseudo-header, header and data.
  • The pseudo-header (IP addresses, protocol, length) is built at each end and not transmitted.
  • A bad checksum means the segment is silently dropped and later retransmitted.
  • "Incorrect checksum" on locally captured outgoing packets is usually offload.
  • URG plus the urgent pointer is legacy and best avoided.

Test yourself

Predict · scenario 1

Why does the TCP checksum include a pseudo-header?

Predict · scenario 2

A receiver finds the TCP checksum wrong. What happens?

Predict · scenario 3

Wireshark on your own PC shows 'incorrect checksum' on every outgoing packet. Most likely cause?

Predict · scenario 4

Which flag makes the urgent pointer field valid?

Predict · scenario 5

A sum of 16-bit words is 0x11000. What is the folded sum?

FAQ

Why does Wireshark show 'incorrect checksum' on packets my own computer sent?
Checksum offload. The operating system leaves the field empty and the network card fills it in on the way out, after the capture point. The packets on the wire are correct. Turn on 'validate checksum' only when capturing on another machine.
Is the TCP checksum optional?
No. In IPv4 and IPv6 it is mandatory for TCP. UDP over IPv4 may set it to zero to mean 'not used'; UDP over IPv6 may not.
Does the checksum protect against attackers?
No. It catches accidental errors, not deliberate changes, because anyone altering a segment can recompute it.