How do I calculate IP-header length?

Amit Singh Tomar picture Amit Singh Tomar · Jul 26, 2012 · Viewed 26.8k times · Source

I want to calculate IP-header length with following statement:

Header Length is a four-bit field that tells, as the name implies, the length of the IP header in 32-bit words

Now I'm getting difficulties in calculating IP header length (minimum and maximum), with four-bit field.

Answer

cnicutar picture cnicutar · Jul 26, 2012
  • The minimum length of an IPv4 header of a valid datagram is 20 bytes, when the value reads 5 and there are no options
  • Since the field is 4 bits wide, the maximum value it can store is 15, thus the maximum length of the header is 60 bytes.

Internet Header Length is the length of the internet header in 32 bit words, and thus points to the beginning of the data. Note that the minimum value for a correct header is 5.

Which means whatever value is stored in the IHL, it should be multiplied with 32 to get the total number of bits, or with 4 to get the total number of bytes.