Example, You have three words in UDP packet need to send.
0110011001100000
0101010101010101
1000111100001100
UDP at the sender side performs the 1s complement of the sum of all the 16-bit
words. The sum of first two of these 16-bit words is
0110011001100000 +
0101010101010101 =
1011101110110101
Adding the third word to the above sum gives, Note that this last addition had overflow, which was wrapped around
--> 0100101011000010
The 1s complement is obtained by converting all the 0s to 1s and converting all the 1s to 0s.
Thus the 1s complement of the sum 0100101011000010
is 1011010100111101
, which becomes the checksum. At the receiver, all four 16-bit words are added,including the checksum. If no errors are introduced into the packet, then clearly the sum at the receiver will be 1111111111111111
. If one of the bits is a 0, then we know that errors have been introduced into the packet.