How to calculate checksum of packet?

We want to detect “errors” in received segments.

  1. We chunk the UDP segment into 16-bit integers.

  2. Apply binary addition on every 16-bits.

    Wraparound any carries.

  3. Compute 1s complement .

    Why do this? This checksum is sent to the receiver. There, the 3 packets would be added, and we would expect to receive 1111111. A computer can efficiently check for 0 (11111), which is why we choose this. if any bits were lost along the way, one of the bits would be 0, in that case we can know it was corrupted.