The maximum length of a Datagram Packet is 65,536 or 65,535?

All we need is an easy explanation of the problem, so here it is.

I found both answers on the internet.

I think it should be 2 bytes = 2^16 = 65,536, but on Wikipedia it is written that it is 65,535 :

The field size sets a theoretical limit of 65,535 bytes (8-byte header + 65,527 bytes of data) for a UDP datagram.

Why is 1 byte missing?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

Reddy’s hit the nail on the head:

The maximum IP packet size is 65,535 bytes (216-1), including all headers and usually requiring fragmentation. Assuming standard headers, IPv4 uses 20 bytes and UDP 8 bytes. The resulting maximum UDP payload size over IPv4 is 65,507 bytes. The maximum UDP datagram includes the UDP header and is 65,515 bytes. For completeness, UDP over IPv6 is 20 bytes less.

If you tried to leverage the theoretical maximum UDP datagram length of 65,535 bytes you couldn’t use IP to transport it with.

65,535 is the maximum value you can store in 16 bits – the largest number is binary 1111 1111 1111 1111 = decimal 65,535. There are 65,536 different values, including 0000 0000 0000 0000.

Method 2

The length field is 16 bit and can thus represent sizes between 0 and 65535. Wikipedia and others are right .

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply