Headers: Headers are variously used in different fields of Computers. These are control information that is attached to data which guides it and makes it error free, reach destination reliably and make the data travel faster etc.

In Computer Networking IP datagrams also known as Packets. These IP datagrams composed of two parts the Header and payload (data), it is just like html page the header and the body respectively. Every protocol follows a different header format for its data to be transmit and received reliably.

Header format for IPv4: Header format for IPv4 is shown below:

IPv4 Header format

IPv4 Header format

The header of IPv4 is 32-bit in length and its multiples for each layer as shown above. The different terms in header are explained below:

Layer 1 of Header: (Please don’t confuse them with OSI Layers)

  • Version: Belongs to the first layer of the header and is of 4 bits. This defines the version of IP i.e 4 for IPv4.
  • Internet Header Length: This is also 4 bits and it defines the total length of the header in multiples of 32. This includes the length of any options fields and padding. The normal value of this field when no options are used is 5 (5 32-bit words = 5*4 = 20 bytes), or simply 20 octets.
  • DS: This field determines what service is used and measures its quality etc. also known as Differentiated Services. This is 6 bits in length.
  • ECN: The Explicit Congestion Notification field is 2 bits in length and are used to detect congestions in the network and tells the end node packets that there are congestions ahead.
  • Total Length: This tells the total length of the IP datagram including header + data. Since this is 16 bits in length so the maximum length of the IP datagram comes out to be 65,536.

Layer 2 of Header: 32 bit in length

  • Identification: This is 16 bits sequence number that is allocated to each of the fragments belonging to a particular message. This field is used by the recipient to reassemble messages without accidentally mixing fragments from different messages. This is needed because fragments may arrive from multiple messages mixed together
  • Flags: Flags control data fragmentations. It is 3 bits in length and contains 3 flags out of which two controls fragmentation and one is reserved.
  • Fragment Offset: When fragmentation of a message occurs, this field specifies the offset, or position, in the overall message where the data in this fragment goes. It is 13 bits in length.

Layer 3 of Header: 32 bit in length

  • Time to Live (8 bits): Specifies how long the datagram is allowed to “live” on the network, in terms of router hops. Each router decrements the value of the TTL field (reduces it by one) prior to transmitting it. If the TTL field drops to zero, the datagram is assumed to have taken too long a route and is discarded.
  • Protocol: Identifies what protocol is used e.g. TCP (6) or UDP (17). It is 8 bits in length.
  • Header Checksum: It is 16 bits long and use as an error checking code.

Layer 4 of Header: 32 bit in length

  • Source Address: IPv4 is 32 bit address and this layer of the header tells the source address of the originating IP datagram.

Layer 5 of Header: 32 bit in length

  • Destination Address: IPv4 is 32 bit address and this layer of the header tells the destination address of the IP datagram.

Layer 6 of Header: 32 bit in length

  • Options: One or more of several types of options may be included after the standard headers in certain IP datagrams
  • Padding: Use to complete the 32 bit profile for Options or its multiples by adding 0’s.

Layer 7 of Header:

  • Data: The data to be transmitted in the datagram.