9

IPv4 Header


I know the IP header length is a minimum of 20 bytes and a maximum of 60 bytes. But why? Why is the IP header length limited to 60 bytes? Is there anybody here that can explain it to me? Thank you.

2

3 Answers 3

16

The Internet Protocol (IP) is defined in RFC 791. The RFC specifies the format of the IP header. In the header there is the IHL (Internet Header Length) field which is 4 bits long and specifies the header length in 32 bit words. The IHL field can hold values from 0 (Binary 0000) to 15 (Binary 1111).

So the longest Internet Header (IP header) size can be 15*32 Bits = 480 Bits = 60 Bytes. This is why the header has a maximum size of 60 Bytes.

The shortest header size is 20 bytes, where the IHL field has the value 5 (0101). This is because all the required fields in the header need 20 Bytes of space. So while in theory you could set the IHL to a value < 5 this would always be an incorrect value and thus an invalid packet header.

7
  • Thanks a lot Sebastian. This is the answer i was looking for. Now i understood exactly. So my analogy was correct also. :)
    – ebyrock
    Mar 17, 2014 at 14:43
  • But the shortest value would be 5 because its defined in RFC 791? So it can't be set to 0 (0000)?
    – ebyrock
    Mar 17, 2014 at 14:50
  • 2
    Min of 5 dwords (20 bytes) because those are the required parts of the header. There may be zero or more options, thus 20 to 60 bytes.
    – Ricky
    Mar 17, 2014 at 19:10
  • 1
    I added the explanation for the minimum size to make it complete. Mar 18, 2014 at 8:47
  • 1
    it means that it count's the header length in 32-bit increments. Jun 5, 2015 at 13:32
3

Per RFC 791 where it is defined, see page 12 where it discusses datagrams:

Total Length is the length of the datagram, measured in octets, including internet header and data. This field allows the length of a datagram to be up to 65,535 octets. Such long datagrams are impractical for most hosts and networks. All hosts must be prepared to accept datagrams of up to 576 octets (whether they arrive whole or in fragments). It is recommended that hosts only send datagrams larger than 576 octets if they have assurance that the destination is prepared to accept the larger datagrams.

The number 576 is selected to allow a reasonable sized data block to be transmitted in addition to the required header information. For example, this size allows a data block of 512 octets plus 64 header octets to fit in a datagram. The maximal internet header is 60 octets, and a typical internet header is 20 octets, allowing a margin for headers of higher level protocols."

Basically the length was defined between 20 and 60 to allow for different protocol uses and to fit in the recommended datagram size.

2
  • 1
    Thanks Mike again but i don't quite get it. In you response it says that "The maximal internet header is 60 octets" but doesn't explain why? I inserted a pic to my question. The size of the IP header is defined in the IHL (Internet Header Length) which is in 4-7 bits and that means its 4 bits long. if we set all the bits are 1 in Base2 (1111) that would be 15 in Base10. And the the Internet header length is 32 bit words. We multiply 15 x 32 = 480 bits which is equal to 60 bytes (480/8). I am not sure it is a correct analogy. :(
    – ebyrock
    Mar 17, 2014 at 14:07
  • Not trying to be short but the 'why' is: this is how it is defined. All internet protocols have definitions. These definitions are the standards which all internet traffic protocols follow. Mar 17, 2014 at 14:18
0

The initial 5 rows of the IP header are always used. So, minimum length of IP header = 5 x 4 bytes = 20 bytes. The size of the 6th row representing the Options field vary. The size of Options field can go up to 40 bytes. So, maximum length of IP header = 20 bytes + 40 bytes = 60 bytes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.