zaro

What is the maximum size of a UDP packet?

Published in Network Protocols 2 mins read

The maximum theoretical size of a UDP packet is 65,535 bytes.

Understanding UDP Packet Size

User Datagram Protocol (UDP) is a connectionless protocol that sends data packets without establishing a connection first. The size of these packets is crucial for network performance. Here's a breakdown:

  • Theoretical Limit: The UDP header has a 16-bit field that defines the total length of the UDP datagram. This field size sets the limit to 65,535 bytes. This total size includes both the 8-byte UDP header and the data payload. Therefore, the maximum size of the data that can be sent is 65,527 bytes (65,535 - 8 = 65,527).
  • Reference: The field size sets a theoretical limit of 65,535 bytes (8-byte header + 65,527 bytes of data) for a UDP datagram.

Practical Considerations

While the theoretical maximum is 65,535 bytes, practical limitations often restrict the actual size of UDP packets:

  • IP Fragmentation: Sending UDP packets larger than the Maximum Transmission Unit (MTU) of a network requires fragmentation at the IP layer. Fragmentation can lead to packet loss and higher overhead.
  • Path MTU Discovery (PMTUD): To avoid fragmentation, senders ideally use Path MTU Discovery (PMTUD) to find the smallest MTU along the network path. This allows them to send packets that won't need fragmentation.
  • Common MTU: The most common MTU size on networks is around 1500 bytes. For Ethernet, the MTU is usually 1500 bytes, which translates to a practical UDP packet size of about 1472 bytes (1500 bytes - 20 bytes IP header - 8 bytes UDP header).
  • Application Needs: Applications usually have their own requirements for data transfer, which means the actual UDP packet size might be much smaller. For example, real-time audio and video may require small packets to reduce latency.

Example:

  • A UDP packet is sent with 1000 bytes of application data.
  • This UDP packet would contain the 8-byte UDP header + 1000 bytes of data = 1008 bytes.
  • The total size would be less than the maximum theoretical size of 65,535 bytes.

Summary

The maximum theoretical size for a UDP packet is 65,535 bytes, but in practice, the actual size is often limited by the network's MTU to avoid fragmentation.