IP header format – Explanation of all fields
What is the IP header?
IP header is the peace of information that is inserted by the IP layer while sending the network packet to the remote peer. For a received message from the peer, the IP layer removes the header. The header information works as a piece of control information for the user data. Mainly the IP header does end to end routing and ensures the quality of service. In this tutorial, we will describer IP header format and each component of the IP header in detail. For simplicity, we are covering IPV4 format to understand better. In another tutorial, we will cover the IPV4 header too.
IP header format :
The IP header is specified in the standard rfc971.
A four bits value. We can also call it the Internet Protocol version. Along with the routing, the role of IP is to assign the IP addresses to a machine. Initially, the address started with a length of 32 bits. Soon this address space will be insufficient with the increasing number of new machines in the network. To adopt the network changes there could be various versions of IP protocol. Initially, version 4 was developed now we also have IPv6 implementation available.
IP Header Length –
The 4 bits in size, specify the length of the IP header. Length is in 32-bit words the minimum value is 5. If we calculate in terms of bytes, then IP header length is 20 bytes minimum. Because the length of the header may vary, the actual length depends on the presence or absence of the optional parameters. Ip layer, use the length, to get the start of user data. So that header can be stripped off and data can be passed to the user.
Type of Service –
The type of service in the Ip header is for controlling the quality of service of Internet Protocol packet traffic. With Quality of service, a network may choose how to handle the packets. Type of service is an 8 bits header field, each bit has a meaning for quality of service.
Precedence – The first three bits are for precedence. Precedence means the priority of an IP packet in case there is a high load ina network. The high priority packet will pass first. The following are the possible values for the precedence.
- Routing – 0
- Priority – 1
- Immediate – 2
- Flash – 3
- Flash Override – 4
- Critic/Ecp – 5
- Internetwork Control – 6
- Network Control – 7
Delay (bit 4) – Normal Delay – 0, No Delay -1
Throughput (bit 5) – Normal Throughput – 0, High Throughput – 1
Reliability (bit 6) – Normal Reliability – 0 , High Reliability – 1
Bits 7 to 8 are reserved.
Total Length –
Two bytes value represents a total length of an IP packet. Total length = Header length + User Data length. To get the user data, the IP layer finds the user data length from the total length and header length.
Identification/IP Field –
A two bytes unique value between the source, destination, and protocol. When the sender sends a packet it assigns a unique value to the IP packet during the Maximum Datagram Lifetime (MDL). While traversing the path, if an IP packet gets fragmented, the identification value remains the same for the fragments. Destination correlates the segments from the identification value.
IP Flags –
The flags are for control information. Menas how a transit network should treat the IP packet. The IP flags field is three bits long. Each bit provides control information to the network.
- The first bit is reserved, does not use currently.
- The second bit for the fragmentation also called Don’t fragment (DF). If the value is zero(0), the transit network can fragment the packet if requires. If the value is one(1), the underlying network does not fragment the IP packet. If the fragmentation is must on a node and DF value is 1, the node will drop the packet.
- The third bit of IP flags (More Fragment -MF) is for segment information. If the value is zero (0), means it is the last fragment if the packet is fragmented or no fragmentation at all. One (1) means a packet is fragmented and at least one frame will follow the current fragment.
Fragment offset –
The fragment offset unit is 8 bytes (64 bits). This IP flag parameter is for assembling the fragments on the destination. When all frames are received, the receiver IP layer builds the original message. For that, all fragments should be put together in the correct order. The lowe offset frame should be kept first. The first segment offset is zero, subsequent frames have offset equal to the current offset + offset unit (8 bytes)in the current frame.
Time To Live –
Time to live IP header parameter is one byte long. The value represents the number of seconds a frame/message should exist in the network. If the value is zero the receiving node should discard the packet. When a router forwards the packet, it reduces the value by 0ne. Even the time reduced by one, it does not mean that a router always takes one second to process the packet routing. Now maybe thinking what is the use of Time to Live? The parameter controls the lifetime, so an undelivered packet will be discarded after a fixed number of hopes. Very useful in case of looping.
The IP layer is a network layer. There can be various possible protocols over the IP layer e.g UDP and TCP are two examples. The protocol field is a one-byte long value that represents the user protocol. There is a list of protocol id values. Based on the protocol filed value, the IP layer decides to which upper protocol the user data should be delivered.
Header Checksum –
A two bytes field for header checksum only. While transmitting an IP packet from source to destination at each home the Time To Live is reduced. As a result, the checksum is calculated again on each home.
Source and Destination Addresses –
These two fields, each of 32 bits are the IP address of the sender and receiver node. Each IP address format has a different class of IP addresses. Based on classes, there could be various types of IP addresses. Each IP address has two parts one is network id and another is host id.