Does UDP Length Include Header and Data?

The User Datagram Protocol (UDP) Length field specifies the total size of the entire UDP datagram in bytes, which includes both the 8-byte UDP header and the encapsulated data (payload). This article breaks down the structure of the UDP Length field, how its value is calculated, its minimum and maximum limits, and how it interacts with the underlying Internet Protocol (IP) layer.

The Structure of the UDP Header

The UDP header is fixed at 8 bytes (64 bits) in size and consists of four 2-byte (16-bit) fields:

  1. Source Port (2 bytes): The port number of the sender.
  2. Destination Port (2 bytes): The port number of the receiver.
  3. Length (2 bytes): The total length of the UDP header plus the UDP data.
  4. Checksum (2 bytes): An optional (in IPv4) or mandatory (in IPv6) error-checking field covering the header, data, and a pseudo-IP header.

Calculation and Value Range

Because the Length field counts both the header and the payload, its value is computed as:

\[\text{UDP Length} = 8\text{ bytes (Header)} + \text{Payload Length (Bytes)}\]

Comparison with TCP

Unlike TCP, which uses a “Data Offset” field to define only the size of the TCP header, UDP explicitly states the combined length of the header and data. While this creates some redundancy with the “Total Length” field found in the IPv4 header, it ensures that the UDP layer can independently verify the boundary of its own datagram without relying solely on network-layer calculations.