IPv4 Datagram Header

The datagram is a part of the IPV4 Header. It represents the Header and payload size. Datagram of IPV4 is a 16-bit field, which is equal to 65535 bytes. IPV4 Datagram is the combination of header size and payload  (data). IPV4 Datagram will always be in the range of 20 bytes to 65535 bytes (216 bytes).

1. Header Size

The minimum size of the header is 20 bytes or 160 bits, and a maximum of 60 bytes or 480 bits. The first five rows of the IPV4 header are mandatory, having a total size of 20 bytes.

Each row is of 4-byte. So, first five rows size will be 20 bytes which is minimum size of IPV4 header.

2. Payload

The minimum size of Payload  (Data) is 0 bytes and a maximum of 65515 bytes.

IPv4 Datagram Header Size Calculations

  • If the header size is 20 bytes (minimum) and the payload  is 0 bytes (minimum), then the datagram size = 20 bytes
  • If the header size is 20 bytes (minimum) and the payload is 65515 (maximum), then the datagram size = 65535 bytes
  • If the header size is 60 bytes, then the payload maximum value will be 65475 because 65475 + 60 bytes are equal to the maximum IPV4 datagram size, which is equal to 65535.

Note: If the header size is 60 bytes (maximum) and the payload is 65515 (maximum), then the datagram size = 65575 bytes. it cannot be represented by 16 bits field of a datagram.

The IPv4 Datagram Header diagram is given below

IPv4 Datagram Header

IPV4 Datagram Header Attributes

Let explain all attributes of IPV4 datagram header

1. VERSION

The version of the IP protocol is of 4 bits. These 4 bits are always fixed as 0100 to represent 4 in decimal for IPv4.

2. HLEN

IV4P header length is 4 bits. The minimum value for this field is 5, and the maximum is 15 bytes.

  • header length can be calculated by the following formula

Header length = Header length field value x 4 bytes

Examples: If the header length field contains the decimal value 11 (represented in binary 1011) then Header length = 11 x 4 = 44 bytes

Note: So decimal range of 4-bits will becomes [5 -15] to represent header length [20-60]

3. Type Of Service

It is an 8-bit field that is used for Quality of Service. The division of 8 bits is explained under

Type of Service in IPv4 datagram Header

  • Precedence (3 bits): The first 3 bits define the precedence. Precedence means priority, i.e., immediate, routine, etc. If a router is congested and needs to discard packets, it will discard packets having the lowest priority first. Bits values will be 0 or 1.
  • Delay (1 bit): if we want a minimum delay in data packets, then this field will be 1; otherwise, it is 0. It is Mostly in video calling where there is no delay.
  • Throughput (1 bit): If it needs high output, then its field bit will be 1; otherwise, it will be 0.
  • Reliability (1 bit): if it needs high reliability, then its field bit will be 1. Otherwise, it is 0. It is used where no data loss is tolerated.
  • Cost (1 bit): if it needs low cost, then its field bit will be 1 otherwise 0. It requires when to select the shortest path to its destination.
  • The last bit is reserved for future purposes, which mostly controls the congestion Notification. Congestion means it informs the sender to minimize the speed of sending data.

4. Total Length:

It is the Total length of the datagram. it is a 16-bit field that can represent 216 = 65536 value. It has a minimum size of 20 bytes and a max value of 65535 bytes. As we already discussed in the datagram topic, that

Total length = Header length + Payload length

5. Identification

  • It is a 16-bit field. It is helpful for the identification of the fragments of an original datagram.
  • When an IP datagram is fragmented, each fragmented datagram is assigned the same identification header number.
  • This header number is useful during the re-assembly of fragmented datagrams.

6. Flag Bits:

It uses 3 flag bits

  • The first flag bit is Reserved.
  • Second Flag bit (DF Bit). DF bit stands for Do Not Fragment bit. DF value may be 0 or 1.

When the DF value is 0, then It gives permission to the intermediate devices (i.e., routers) to fragment the datagram if required.

When the DF value is 1, then It indicates the intermediate devices (i.e., router) not to fragment the datagram at any cost.

  • The third flag bit is MF. MF bit stands for More Fragments bit. MF value may be 0 or 1.

When MF bit value is 0 then It tells to the receiver that the current datagram-fragment is the last fragment and no more segment will appear of same datagram.

When MF bit value is 1 then it tells more fragments are still to come after this fragment. MF bit is set to 1 for all the fragments except the last one.

7. Fragment Offset

Fragment Offset is a 13-bit field. It tells the position of a fragmented datagram in the original un-fragmented IP datagram.

Fragment offset for a given fragmented IP datagram = Number of data bytes ahead of it in the original un-fragmented IP datagram

 Hence, The 1st fragmented datagram has a fragment offset of zero.

8. Time to live

It is an 8-bit field that prevents the datagram from going to loop. If a datagram goes to a loop, then congestion can happen, which causes the problem. So, Time to Live (TTL) is avoided in such stations.

According to TTL, 8-bit can represent 256 nodes. Therefore, datagram is self-loop can goes to 256 nodes, when datagram goes to a node, it is decremented by 1 in values. As the value reaches 0, the datagram is terminated.

9. Protocol

It is an 8-bit number that defines what protocol is used inside the IP packet. TCP, UDP, ICMP, or IGMP protocols can be filtered, although they are most common. The protocol number of ICMP is 1 (in binary 00000001), IGMP is 2 (in binary 00000010), TCP is 6, and UDP is 17.

10. Header Checksum

It is a 16-bit field. It is used for checking errors in the datagram header. At the receiving end, it is used to know whether the receiving data is corrupted or not because data can be lost or corrupted while passing through the network.

11. Source IP address

32 bits IP address of the sender

12. Destination IP address

32 bits IP address of the receiver

13. Option

Due to the options field, datagram-header-size can be of variable length (20 bytes to 60 bytes). Optional information includes source route, etc.

IPv4 Datagram Header Numerical

Question: A datagram of 3000 bytes (20 bytes of IP header + 2980 bytes IP payload) reached the router and must be forwarded to link with MTU (maximum transmission unit) of 500 bytes. How many fragments will be granted? Also, write MF, offset, and total length values for all.

Numerical Solution

After the fragmentation of the datagram into fragments (packets), each fragment will carry the same header size, which is the same as the original datagram. So, in this question, 20 bytes will be the compulsory part of each fragment.

As the limit of a link is 500 bytes to transfer, in which 20 bytes is the header size. So, 480 bytes of payload can transfer in each fragment.

Total Number of Fragments

The total number of fragments can be calculated by considering a ceiling value of the following formula.

Total fragment = Total payload to transfer/ Payload in each fragment

So, Total fragment = 2980 / 480 = 7

Descriptive diagram in given below

IPv4 Datagram Header Numerical

Total Length

Total length is the combination of all fragmented payloads. Adding the payload of each fragment will always equal the size of the original payload. As

Total length of payload  = 480+480+480+480+480+480+100 = 2980.

Note: Header length will remain the same 20 bytes at the receiving end. So, 20+2980 bytes = 3000 bytes. It was the original datagram of 3000 bytes.

More Fragments (MF)

MF value may be 0 or 1.

  • When MF bit value is 0 then It tells to the receiver that the current datagram-fragment is the last fragment and no more segment will appear of same datagram.
  • When MF bit value is 1 then it tells more fragments are still to come after this fragment.

Fragment Offset

It uses a scaling factor of 8. The fragment offset can be calculated by using the following formula

Fragment offset for a given fragmented IP datagram = Number of data (payload) bytes ahead of it / 8  

  • At fragment F1, no byte has already been transferred. So fragment offset = 0/8 B = 0
  • At fragment F2, 480 bytes of F1 are already transferred. So fragment offset = 480/8 B = 60
  • At fragment F3, 480 bytes of F1 and F2 are already transferred. So fragment offset = 480*2/8 B =120
  • At fragment, F4, 480 bytes of F1, F2, and F3 are already transferred. So fragment offset = 480*3/8 B =180
  • At fragment F5, 480 bytes of F1,F2,F3 and F4 is already transferred. So fragment offset = 480*4/8 B =240
  • At fragment F6, 480 bytes of F1,F2,F3,F4 and F5 is already transferred. So fragment offset = 480*5/8 B =300
  • At fragment F7, 480 bytes of F1,F2,F3,F4,F5 and F6 is already transferred. So fragment offset = 480*6/8 B =360