Maximum Theoretical Size of a UDP Datagram
The maximum theoretical size of a standard IPv4 UDP datagram is 65,535 bytes in total, resulting in a maximum theoretical payload size of 65,507 bytes after subtracting the necessary headers. However, this limit depends on the underlying Internet Protocol (IP) version used, and special protocol extensions like IPv6 Jumbograms can theoretically expand this capacity to over 4 gigabytes. This article breaks down the mathematical limits of UDP datagram sizes across standard IPv4, IPv6, and practical networking environments.
The IPv4 UDP Limit (65,507 Bytes)
UDP itself defines a 16-bit Length field in its header.
A 16-bit unsigned integer can represent values from 0 to 65,535 (\(2^{16} - 1\)). This means a UDP datagram
(header plus payload) cannot exceed 65,535 bytes.
Furthermore, an IPv4 packet also uses a 16-bit
Total Length field, capping the entire packet (IPv4 header
+ UDP header + UDP data) at 65,535 bytes.
To determine the maximum theoretical payload (user data) for UDP over IPv4:
- Maximum IPv4 Total Length: 65,535 bytes
- Minimum IPv4 Header: 20 bytes (without options)
- UDP Header: 8 bytes
\[\text{Maximum Payload} = 65,535 - 20 - 8 = 65,507 \text{ bytes}\]
If the IPv4 header contains optional fields (up to 60 bytes total), the available UDP payload size decreases accordingly.
The IPv6 UDP Limit (65,487 Bytes)
In standard IPv6 networks:
- The standard IPv6
Payload Lengthfield is also 16 bits, allowing a maximum payload of 65,535 bytes. - The fixed IPv6 base header is 40 bytes (handled separately from the payload length).
- The UDP header is 8 bytes.
\[\text{Maximum Standard IPv6 Payload} = 65,535 - 8 = 65,527 \text{ bytes}\]
However, accounting for the total IP packet limitation under standard frame constraints, the theoretical UDP data limit is:
\[\text{Maximum Data} = 65,535 - 40 - 8 = 65,487 \text{ bytes}\]
IPv6 Jumbograms (Up to 4 Gigabytes)
Under RFC 2675, IPv6 supports an extension called Jumbograms.
When using Jumbograms: * The 16-bit UDP Length field is
set to 0, signaling to the operating system and network
stack that the length exceeds standard 16-bit limits. * The actual
length is stored in a 32-bit IPv6 Jumbo Payload option field. * This
allows a theoretical maximum UDP packet size of \(2^{32} - 1\) bytes (4,294,967,295 bytes or
approximately 4 GB), leaving 4,294,967,247 bytes for
the payload after subtracting the 40-byte IPv6 header and 8-byte UDP
header.
Theoretical vs. Practical Limits
While 65,507 bytes is the theoretical maximum for IPv4:
- Maximum Transmission Unit (MTU): Most standard Ethernet networks use an MTU of 1,500 bytes.
- Fragmentation: Any UDP datagram larger than the MTU minus IP/UDP headers (typically 1,472 bytes in IPv4) must be fragmented into multiple IP packets.
- Reliability: If any single fragment of a fragmented UDP packet is lost, the entire datagram is discarded by the receiver, because UDP does not support retransmission.
For reliable, unfragmented transmission over the public internet, applications generally limit UDP payload sizes to 1,472 bytes (for IPv4) or 1,280 bytes (the minimum MTU required by IPv6).