What fields make up a UDP header?
The UDP header is a very simple control part of a UDP datagram. It contains the minimum amount of information needed to deliver data to an application.
In short: the UDP header consists of only 4 fields.
Fields of the UDP header
1. Source Port
- 16 bits
- indicates which application the data was sent from
- can be
0if the source port is not needed
2. Destination Port
- 16 bits
- indicates which application the data is intended for
- a required field
3. Length
- 16 bits
- contains the total length of the UDP datagram:
- the UDP header plus the data
- the minimum value is 8 bytes (header only)
4. Checksum
- 16 bits
- used to verify data integrity
- if the checksum does not match:
- the datagram is dropped
Important:
- in IPv4, the checksum can be optional
- in IPv6, the checksum is mandatory
Size of the UDP header
- Always 8 bytes
- does not depend on the data
- unlike TCP, there are no options or extra fields
What is important to remember
- the UDP header:
- does not contain sequence numbers
- does not contain an ACK
- does not contain windows or flags
- so UDP is:
- fast
- has minimal overhead
- has no delivery or order guarantees
Comparison with TCP (briefly)
- UDP - 8-byte header
- TCP - at least 20 bytes
A smaller header means lower latency and higher speed.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.