UDP Checksum – Can It Be Inconclusive for Error Detection?

checksumlayer4tcpudp

If I am receiving data through UDP, with a checksum that checks out to show no data loss, is there a possibility that the checksum missed some errors. My data transmitted is split into 24-bits chunks by the protocol that uses the checksum. Similarly, if errors are detected through the checksum, does that fully guarantee that the error actually occured?

Best Answer

If you mean the optional (for IPv4, but required for IPv6) UDP checksum, then that creates a 16-bit checksum that conceptually matches multiple combinations of datagrams that are larger than 16-bits. There is no guarantee that a UDP datagram that matches the checksum is error-free, but the odds of an error are very small. Many errors that would match the checksum would prevent the datagram from reaching its destination.

If the checksum indicates an error, then something is wrong somewhere, and it is almost always corruption in the datagram. Other possibilities include an incorrect or buggy checksum algorithm on the part of the sender or receiver.

If you mean a checksum in the application data, that further protects the data, but that is off-topic here.

There are also the possibilities that bits get flipped in RAM or on a disk drive. It does happen, but not very often.

See RFC 768, User Datagram Protocol:

Checksum is the 16-bit one's complement of the one's complement sum of a pseudo header of information from the IP header, the UDP header, and the data, padded with zero octets at the end (if necessary) to make a multiple of two octets.

The pseudo header conceptually prefixed to the UDP header contains the source address, the destination address, the protocol, and the UDP length. This information gives protection against misrouted datagrams. This checksum procedure is the same as is used in TCP.

              0      7 8     15 16    23 24    31 
             +--------+--------+--------+--------+
             |          source address           |
             +--------+--------+--------+--------+
             |        destination address        |
             +--------+--------+--------+--------+
             |  zero  |protocol|   UDP length    |
             +--------+--------+--------+--------+

If the computed checksum is zero, it is transmitted as all ones (the equivalent in one's complement arithmetic). An all zero transmitted checksum value means that the transmitter generated no checksum (for debugging or for higher level protocols that don't care).