askvity

What is MTU in UDP?

Published in Networking Protocols 3 mins read

The Maximum Transmission Unit (MTU) in the context of UDP (User Datagram Protocol) is the largest size, in bytes, of a UDP datagram (including the UDP header and data) that can be transmitted over a network connection without fragmentation.

Understanding MTU and UDP

  • MTU's Role: MTU limits the size of a single packet that can be sent without being broken down into smaller pieces (fragmented). Fragmentation increases overhead and can lead to performance issues.
  • UDP's Characteristics: UDP is a connectionless protocol, meaning it doesn't establish a dedicated connection before sending data. This makes it faster but also less reliable than TCP. Therefore, avoiding fragmentation in UDP is particularly important.

Why MTU Matters for UDP

  1. Fragmentation Avoidance: The main reason to be aware of MTU in UDP is to avoid IP fragmentation. When a UDP datagram exceeds the MTU of a network path, the IP layer needs to fragment the packet.

  2. Performance Implications: Fragmentation negatively impacts network performance:

    • Increased Overhead: Each fragment has its own IP header, adding overhead.
    • Increased Latency: The receiving host must reassemble the fragments, increasing latency.
    • Reliability Issues: If any fragment is lost, the entire original datagram is lost, requiring retransmission of all fragments if the application is designed to handle loss.
  3. Path MTU Discovery (PMTUD): PMTUD is a technique used to determine the smallest MTU along the network path between two hosts. This helps avoid fragmentation. However, PMTUD can be blocked by firewalls or misconfigured network devices, making it unreliable in some cases.

Common MTU Values

Network Type MTU (Bytes)
Ethernet 1500
PPPoE 1492
VPNs Varies (often lower)

The standard MTU for Ethernet is 1500 bytes. When using UDP, it's generally best to keep your UDP datagrams smaller than this to avoid fragmentation on typical networks. PPPoE connections have a slightly lower MTU (1492 bytes) due to the overhead of the PPPoE protocol. Virtual Private Networks (VPNs) may further reduce the MTU due to encryption and tunneling overhead.

Practical Considerations

  • Application Design: When designing applications that use UDP, carefully consider the MTU. Avoid sending UDP datagrams that are larger than the smallest MTU likely to be encountered on the network.
  • UDP Header Size: Remember to account for the UDP header size (8 bytes) and any IP header size (typically 20 bytes). Therefore, to avoid fragmentation on a standard Ethernet network, the data portion of a UDP packet should typically be less than 1472 bytes (1500 - 20 - 8 = 1472).
  • Jumbo Frames: Some networks support jumbo frames, which have a larger MTU (e.g., 9000 bytes). If you control the entire network path and it supports jumbo frames, you can use larger UDP datagrams. However, using jumbo frames on a network that doesn't support them will lead to connectivity problems.

Example

If you want to send data via UDP over a standard Ethernet network (MTU = 1500), your maximum UDP payload size should be:

1500 (MTU) - 20 (IP Header) - 8 (UDP Header) = 1472 bytes.

Related Articles