The Internet checksum,
also called the IPv4 header checksum is a
checksum
A checksum is a small-sized block of data derived from another block of digital data for the purpose of detecting errors that may have been introduced during its transmission or storage. By themselves, checksums are often used to verify data ...
used in
version 4 of the
Internet Protocol
The Internet Protocol (IP) is the network layer communications protocol in the Internet protocol suite for relaying datagrams across network boundaries. Its routing function enables internetworking, and essentially establishes the Internet.
...
(IPv4) to detect corruption in the header of IPv4 packets. It is carried in the
IP packet header, and represents the 16-bit result of summation of the header words.
The
IPv6
Internet Protocol version 6 (IPv6) is the most recent version of the Internet Protocol (IP), the communications protocol that provides an identification and location system for computers on networks and routes traffic across the Internet. IPv ...
protocol does not use header checksums. Its designers considered that the whole-packet link layer checksumming provided in protocols, such as
PPP and
Ethernet
Ethernet () is a family of wired computer networking technologies commonly used in local area networks (LAN), metropolitan area networks (MAN) and wide area networks (WAN). It was commercially introduced in 1980 and first standardized in 1 ...
, combined with the use of checksums in upper layer protocols such as
TCP and
UDP, are sufficient. Thus, IPv6 routers are relieved of the task of recomputing the checksum whenever the packet changes, for instance by the lowering of the ''
Hop limit
Time to live (TTL) or hop limit is a mechanism which limits the lifespan or lifetime of data in a computer or network. TTL may be implemented as a counter or timestamp attached to or embedded in the data. Once the prescribed event count or times ...
counter'' on every hop.
The Internet checksum is mandatory to detect
errors in IPV6 UDP packets (including data payload).
The Internet checksum is used to detect
errors in ICMP packets (including data payload).
Computation
The checksum calculation is defined in RFC 791:
The checksum field is the 16-bit ones' complement
The ones' complement of a binary number is the value obtained by inverting all the bits in the binary representation of the number (swapping 0s and 1s). The name "ones' complement" (''note this is possessive of the plural "ones", not of a sin ...
of the ones' complement sum of all 16-bit words in the header. For purposes of computing the checksum, the value of the checksum field is zero.
If there is no corruption, the result of summing the entire IP header, including checksum, should be zero. At each hop, the checksum is verified. Packets with checksum mismatch are discarded. The router must adjust the checksum if it changes the IP header (such as when decrementing the TTL).
The procedure is explained in detail in RFC 1071 "Computing the Internet Checksum".
Optimisations are presented in RFC 1624 "Computation of the Internet Checksum via Incremental Update"
(with errata), to cover the case in routers which need to recompute the header checksum during packet forwarding when only a single field has changed.
Examples
Calculating the IPv4 header checksum
Take the following truncated excerpt of an IPv4 packet. The header is shown in bold and the checksum is underlined.
4500 0073 0000 4000 4011 b861 c0a8 0001
c0a8 00c7 0035 e97c 005f 279f 1e4b 8180
For ones' complement addition, each time a carry occurs, we must add a 1 to the sum.
A carry check and correction can be performed with each addition or as a post-process after all additions. If another carry is generated by the correction, another 1 is added to the sum.
To calculate the checksum, we can first calculate the sum of each 16 bit value within the header, skipping only the checksum field itself. Note that these values are in
hexadecimal notation.
4500 + 0073 + 0000 + 4000 + 4011 + c0a8 + 0001 + c0a8 + 00c7 = 2479c
The first digit is the carry count and is added to the sum:
2 + 479c = 479e
(if another carry is generated by this addition, another 1 must be added to the sum)
To obtain the checksum we take the ones' complement of this result:
b861
(as shown underlined in the original IP packet header).
Verifying the IPv4 header checksum
When verifying a checksum, the same procedure is used as above, except that the original header checksum is not omitted.
4500 + 0073 + 0000 + 4000 + 4011 + b861 + c0a8 + 0001 + c0a8 + 00c7 = 2fffd
Add the carry bits:
fffd + 2 = ffff
Taking the ones' complement (flipping every bit) yields 0000, which indicates that no error is detected.
IP header checksum does not check for the correct order of 16 bit values within the header.
See also
*
Frame check sequence
A frame check sequence (FCS) is an error-detecting code added to a frame in a communication protocol. Frames are used to send payload data from a source to a destination.
Purpose
All frames and the bits, bytes, and fields contained within ...
*
Header check sequence
References
{{reflist
External links
Header Checksum
Error detection and correction
Header Checksum
A checksum is a small-sized block of data derived from another block of digital data for the purpose of detecting errors that may have been introduced during its transmission or storage. By themselves, checksums are often used to verify data ...