IP Header and Function of Each Field
Are you curious to know IP header in detail? Then, you are are at right place.
In this lesson we will learn format of IP header and function of each field. This lesson is also important from interview point of view. Without wasting more time let’s start.
IP Header: Explanation
Version: This field tells the IP version – IPv4 or IPv6.
Header Length: This field tells the header length. Most of time, you will see header length is 5. Here, 5 is representing total number of rows in header. If this value is 6, options field is also present in the header, but this will be very rare.
Type of Service (TOS): This is 8 bits field. This TOS field is used to prioritize the traffic. For example, In a company there is an important meeting is going on, so we don’t want any interruption in the meeting, so in this case we set higher priority by using TOS.
Total Length: Total length represents the length of header and data both.
Total length = header + data
Identification Field: When a packet is large, normally packet is divided into parts before sending, these parts is known as fragment. To collect these fragments at receiver side, an identification field is added. Fragments that belong to same packet have same identification value.
Flags: This field has 3 bits; combination of these 3 bits represent 3 different actions. Mainly different combinations of flags tell packet is fragmented or not.
Mainly, packets are fragmented when size is greater than 1500bytes (header+data).
Because Maximum Transmission Unit (MTU) = 1500 bytes.
Fragment Offset : This field is used to indicate the position of the fragments in the packet. It tells the sequence number in which fragments are arranged to reassemble the original packet.
Fragment offset value is very useful in recollecting the fragments at receiver side, because many times fragments are appeared in random manner.
Time to Live: By default, TTL value is 64. A user can set it manually up to 255.
TTL value is used to avoid layer 3 infinite loops, when TTL = 0 (zero), packet is dropped.
TTL value is decremented as it traverses the router in the path. For example- let suppose initial TTL value is 64. To reach to a destination, there are 4 routers in the path, so TTL value is decremented by 1 every time, as it will pass the router, and in last TTL value will be 60. You can also calculate Hop counts by using TTL value.
Hop counts = Initial TTL- final TTL
Protocol Number: This field represents the protocol number.
Header Checksum: This is responsible for checking errors, it only checks the header error, if any error is present in the header, it drops the packet.
Source IP address: This field represents the IP address of sender. This is 32 bits field.
Destination IP address: This field represents the IP address of destination. This is also 32 bits field.
Note: Source IP and destination IP address field never change, these remain same, doesn’t matter where you check.
What is the size of IP header?
It is very simple to calculate. Just look at the IP header once, now notice each row is 32 bits in length and there are total 5 rows. So, 5×32 = 160 bits.
As, we know 1 byte = 8 bits, so 160 ÷ 8 = 20 bytes.
So, IP header size is 20 bytes (160 bits).