UDP Maximum Datagram Size and Fragmentation
What you'll learn: How UDP's theoretical size limit differs from practical constraints, and what happens when datagrams exceed network limits.
The Theoretical Maximum
UDP's 16-bit length field in its header allows for a theoretical maximum datagram size of 65,535 bytes (including the 8-byte UDP header). This means the actual data payload could be up to 65,527 bytes. However, this is just what the protocol allows on paper.
Practical Reality: MTU Constraints
In practice, you almost never see UDP datagrams this large. Why? Because they must travel through IP networks, and each network link has a Maximum Transmission Unit (MTU)—the largest packet size it can handle in one piece. Ethernet's standard MTU is 1,500 bytes, meaning your UDP datagram plus IP header (typically 20 bytes) can't exceed this without problems.
Think of it like shipping packages: UDP can theoretically label a box as "65,535 pounds," but if every truck on the route has a 1,500-pound limit, that box won't make it intact.
IP Fragmentation
When a UDP datagram exceeds the path MTU, IP fragmentation occurs. The IP layer breaks the datagram into smaller fragments that fit within the MTU, each becoming a separate IP packet. The receiving end must reassemble all fragments before delivering to UDP.
The catch: If even one fragment is lost, the entire original datagram is discarded. UDP provides no retransmission mechanism, so that data is simply gone. This makes large UDP datagrams risky in unreliable networks.
Key Takeaway: While UDP theoretically supports 65,535-byte datagrams, practical MTU limits (typically 1,500 bytes) and the fragility of IP fragmentation mean smaller datagrams are safer and more reliable for UDP applications.