IPv4 Datagram Header

Learn via video courses
Topics Covered

Overview

IPv4, where IP stands for Internet Protocol, and v4 stands for Version Four, is used to route Internet traffic and other packet-switched layer networks, such as Ethernet. It was the first version brought into action for production on SATNET in 1982 and on the ARPANET in 1983. It is a 32-bit address that is organized into four octets of 8 bits (4x8), which is often expressed in dotted decimal numbers and looks like this: 172.140.153.12.

Introduction to IPv4

IPv4 (Internet Protocol Version 4) is the first major version (Fourth version) of the Internet Protocol and is a widely used protocol for transmitting data over various networks. It is a connectionless protocol that is used in packet-switched networks. By providing an identity for each network device, it establishes a logical connection between them. It is a connectionless, unreliable datagram protocol that uses a best-effort delivery strategy. The term best effort refers to the fact that IPv4 provides no error or flow control.

IPv4 is a 32-bit address that is organized into four octets of 8 bits (4x8), which is often expressed in dotted decimal numbers and looks like this: 172.140.153.12. There are five classes in the IPv4 address space: A, B, C, D, and E. The IP address range for each class is distinct. The majority of devices on the Internet mostly use classes A, B, and C.

Class D addresses are reserved for use in the military, whereas class E addresses are reserved for future use.

IPv4 Datagram Header

ipv4-header

Let's go through each IPv4 header field one at a time.

Version (VER)

It is a 4-bit field that defines the version of the IPv4 protocol, which is 4. Version-4 (IPv4) and version-6 (IPv6) of the IP protocol are the most widely used versions.

Header Length (HLEN)

It is a 4-bit field containing the IP header's length. This field helps in knowing from where the actual data begins. This field is needed because the header's length is variable (between 20 and 60 bytes).

Since it is a 4-bit field,[0, 15] is the range of decimal values that can be expressed. The IP header's first five rows are always used.

Therefore, an IP header's minimum length is (5 x 4 bytes). The sixth row, which represents the Options field, has a maximum size of 40 bytes. Therefore, an IP header's maximum length is 20+40=6020 + 40 = 60 bytes. We use a scaling factor of 4 to represent the header length [20, 60].

Type of Service

It is an 8-bit field, and Low Delay, High Throughput, and Reliability are the types of services. This field is used for Quality of Service (QoS).

Total Length

It is a 16-bit field that contains the total length of the IP Packet (including the IP header and IP Payload).

Total length=Header length + Payload length

The total length has a minimum value of 20 bytes (20 bytes header + 0 bytes data), and the maximum is 65,535 bytes.

Identification

It is a 16-bit field used to identify the fragments of an original IP datagram.

If an IP packet is fragmented during the transmission, Each fragment contains the same identification number. It helps to identify the original IP packet they belong to.

DF Bit

DF bit stands for Do Not Fragment bit. It is a 1-bit field, and its value may be 0 or 1. When it is set to 0, it allows intermediate devices to fragment the datagram if necessary. When it is set to 1, it instructs the intermediary devices to avoid IP datagram fragmentation at all costs.

MF Bit

MF bit stands for More Fragments bit. It is a 1-bit field, and its value may be 0 or 1. If it is set to 0, it indicates to the receiver that the current datagram is either the final fragment of the set or the only fragment. If it is set to 1, it indicates to the receiver that the current datagram is a fragment of some larger datagram.

Fragment Offset

It is a 13-bit field. It tells the exact position of the fragmented datagram in the original unfragmented IP datagram.

Time To Live (TTL)

TTL is an 8-bit field. It prevents the datagram from looping over the network by reducing the number of hops a packet can take before reaching its destination.

Protocol

It is an 8-bit field. It identifies to the network layer at the destination host which protocol this IP datagram belongs to, i.e., the next level Protocol. For example, the ICMP's protocol number is 1, while TCP's is 6 and UDP's is 17.

Header Checksum

It is a 16-bit field containing the entire header's checksum value. This checksum value is used for checking errors in the datagram header.

The header checksum is only calculated for the header, not for the data, since some fields, like TTL, etc., change at every router hop. Therefore every time calculating checksum of data will be a waste of resources.

Source IP Address

This is a 32-bit field and contains the IP address of the datagram's sender (or source).

Destination IP Address

This is a 32-bit field and contains the IP address of the datagram's receiver (or destination).

Options

This field is optional and can range in size from 0 bytes to 40 bytes. The datagram header's size can vary from 20 bytes to 60 bytes due to this field. This field has many uses, including Record Route, Source Routing, and Padding.

  1. Record Route: The record route option is used to record the IP address of a datagram as it travels through the router. When the record route option is set, the router's IP address gets recorded in the Options field.
  2. Source Routing: The route that the datagram must follow to reach its destination is specified using a source routing option. This option is usually used to determine whether a particular path is working correctly or not.
  3. Padding: Padding is used to validate that the IP packet header's length is a multiple of 32 bits. It is necessary due to the variable length of the IP header's options field.

Conclusion

  • IPv4 is the first major version (Forth version) of the Internet Protocol and is a widely used protocol for transmitting data over various networks.
  • IPv4 was the first version brought into action for production on SATNET in 1982 and on the ARPANET in 1983.
  • IPv4 (Internet Protocol Version 4) is used to route Internet traffic and other packet-switched layer networks, such as Ethernet.
  • IPv4 is a 32-bit address that is organized into four octets of 8 bits (4x8), which is often expressed in dotted decimal numbers and looks like this: 172.140.153.12.
  • There are five classes in the IPv4 address space: A, B, C, D, and E. The majority of devices on the Internet mostly use classes A, B, and C.
  • The fields present in the IPv4 header are- Version, Header Length, Type Of Service, Total Length, Identification, DF Bit, MF Bit, Fragment Offset, Time To Live, Protocol, Header Checksum, Source IP Address, Destination IP Address, and Options.
  • TTL is an 8-bit field used to avoid a situation in which an undeliverable datagram keeps circulating on an Internet system.
  • The record route option is used to record the IP address of a datagram as it travels through the router.
  • The source Routing option is usually used to determine whether a particular path is working correctly or not.
  • The padding option is used to validate that the IP packet header’s length is a multiple of 32 bits.