A checksum is an error detection mechanism.
TCP and UDP headers each include a 16-bit checksum. In each of these protocols, selected header fields are added and one's complement of the 16-bit sum of these 16-bit words becomes the checksum.
For full details on the checksum calculations for these protocols, see the respective RFCs: