UDP
UDP (RFC 768) adds very little on top of IP:
- multiplexing/demultiplexing using port numbers
- basic error detection using a checksum
UDP is said to be connectionless, meaning there is no handshake before data is sent.
Some applications are better suited for UDP for the following reasons:
| Feature | Details |
|---|---|
Application-level control |
|
No connection establishment |
|
No connection state |
|
Small packet header overhead |
|
UDP itself is not reliable, but applications can build reliability on top of it:
- by providing their own error/congestion control (e.g., QUIC)
- this is a nontrivial task
UDP header
| User Datagram Protocol (UDP) | |||||
|---|---|---|---|---|---|
| Offsets (starting positions) |
Octet/Byte | 0 | 1 | 2 | 3 |
| Octet/Byte | Bit | 0-7 | 8-15 | 16-23 | 24-31 |
| 0 | 0 | Source Port | Destination Port | ||
| 4 | 32 | Length | Checksum | ||
The UDP header has 4 fields:
- each field is 2 bytes (16 bits) → total = 8 bytes (64 bits)
- the length field:
- specifies the number of bytes in the UDP segment (header plus data)
- since the size of the data field may differ from one UDP segment to the next
UDP checksum
The checksum checks whether the UDP segment was corrupted during transmission.
-
UDP at the sender:
- performs the sum of all the 16-bit words in the segment
- if the sum is too large for 16 bits, the extra bits are added back into the result (wraparound carry)
- performs the 1s complement of the result:
- all the
0s to1s - all the
1s to0s
- all the
- puts the result in the
checksumfield of the segment
-
UDP at the receiver:
- compute the one's complement sum of all 16-bit words, including the checksum
- if no errors occurred, the sum will be
1111111111111111 -
example (simplified 8-bit illustration):
data sum 01010101 checksum (bitwise NOT) + 10101010 ---------- 11111111 -
if one of the bits is a
0, an error is detected
Why does UDP provide a checksum?
UDP includes a checksum because:
- lower link-layer protocols (e.g., Ethernet) may not provide error checking
- errors can be introduced when a segment is stored in a router's memory
Therefore, UDP provides end-to-end error detection at the transport-layer.
What UDP does when errors are found?
UDP only detects errors and does not correct them:
- some implementations simply discard the damaged segment
- others pass the damaged segment to the application with a warning