IPv4 Protocol – What is the Maximum Datagram Size for IPv4?

ipipv4protocol-theory

The IPv4 datagram consists of two parts:the header length and the payload. The maximum header size is 60 bytes and minimum is 20 bytes. The maximum size of the data can be 65515 bytes. So why the maximum size of the datagram is 65535 bytes? Shouldnt it be 60 bytes(maximum header size) + 65515(maximum data size)?

Best Answer

The maximum size of an IPv4 packet is 65,535 because the Total Length field is a 16-bit unsigned integer, which has a possible 65,536 values (from 0 to 65,535).

The maximum payload is 65,515 only if the header is 20. If the header is 60, then you must subtract 40 from that because the total packet size cannot exceed 65,535.


IPv6 does it differently, using a 16-bit Payload Length field, meaning that the payload, not the packet, has a maximum size of 65,535. There is even a Jumbogram option via an extension header that will allow a 32-bit unsigned integer for the payload length, giving you a payload as large as 4,294,967,295.


In the real world, you are not going to get anywhere close to the maximum packet size of either IPv4 or IPv6 because the MTU will not be anywhere near that number. You may be able to create a very large IP packet and fragment it into multiple smaller packets, but the loss of even one of those fragments will cause the reassembly to fail with the loss of the entire packet.