IPv4 header format – Explanation of all fields.
A header is a piece of information appended to the actual content for message delivery. For example, in real life, the postal address information on the envelope is the header to post the letter.
What is the IP header?
In network communication, an IP header is the information the network layer inserts next to the user data before sending the packet to the remote peer. The receiver removes the header from the received message and delivers the data to the user. The header information works as control information for the user data routing and other functionalities.
Mainly, the IP header does end-to-end routing and ensures the Quality of service. In this tutorial, we will describe the IP header format and each component of the IP header in detail.
IPv6 and IPv4 are the two versions of Internet Protocol currently in use. For simplicity, we will discuss the IPV4 format to understand it better. In another tutorial, we will cover the IPV6 header too.
What is the format of the IPv4 header?
The IP header is specified in the standard rfc971. The Following explains each component of it.
It is a four-bit 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 devices in the network. There could be various versions of the IP protocol to adopt network changes. 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 the IP header length is 20 bytes minimum.
Because the header’s length may vary, the actual size depends on the presence or absence of the optional parameters.
The IP layer uses the length to determine the start of user data in the byte stream. 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 controls the Quality of Service of Internet Protocol packet traffic. With Quality of service, a network may choose how to handle the packets. The type of service is an 8-bit header field. Each bit has a meaning for Quality of service. Following is the explanation of the bit number from 1 to 8.
Precedence (1-3)- The first three bits are for precedence. Precedence means the priority of an IP packet. The higher-priority packet will pass first if a network has a high load. 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 the total length of an IP packet. Total length = Header length + User Data length. The IP layer finds the user data length from the total length and header length to get the user data.
Identification/IP Field –
A two-byte 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 in size. Each bit provides control information to the network.
- The first bit is reserved and not in use currently.
- The second bit is for fragmentation, called Don’t Fragmentation (DF). If the value is zero(0), the transit network can fragment the packet if required. If the value is one(1), the underlying network does not fragment the IP packet. If fragmentation is a must on a node and the 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), it is the last fragment if the packet is fragmented or there is no fragmentation. One (1) means a packet is fragmented, and at least one frame will follow the current fragment.
Fragment offset –
The fragment offset is a 13-bit field. The value indicates after how many bytes the fragment will start. The value of the first fragment offset is zero. This IP flag parameter is for assembling the fragments on the destination.
The receiver IP layer builds the original message when all frames are received. For that, all fragments should be put together in the correct order. The low 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 –
The 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 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 that an undelivered packet will be discarded after a fixed number of hopes. Very useful in the 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 size value representing the user protocol. There is a list of protocol ID values. The IP layer decides which upper protocol the user data should be delivered to based on the protocol filed value.
Header Checksum –
A two-byte field for header checksum only. While transmitting an IP packet from source to destination at each hop, the Time To Live is reduced. As a result, the checksum is calculated again on each hop.
Source and Destination Addresses –
These two fields of 32 bits are the sender and receiver nodes’ IP addresses. 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 the network ID, and the other is the host ID.