IPv4 Packet Header
The network layer takes data segments from the transport layer and converts them into packets. IP packet encapsulates the data unit received from the above layer and adds to its IPv4 Packet header information, as shown in the figure below. The IPv4 packet header has different fields containing important information about the packet. These fields contain binary numbers, which the network layer processes examine. The binary values of each field identify various settings of the IPv4 packet. Protocol header diagrams, like the one shown in the figure below:
- Important fields in the IPv4 packet header include
- Version – IPv4 packet header contains a 4-bit binary value set to 0100, identifying this as an IP version 4 packet.
- Internet Header Length (IHL)—This is a 4-bit field that tells us the length of the IP header in 32-bit increments. The minimum length of an IP header is 20 bytes. The maximum value we can create with 4 bits is 15, so with 32-bit increments, that would be a header length of 60 bytes.
- Differentiated Services (DS) – Previously called the Type of Service (ToS) field, the DS field is an 8-bit field used to decide the priority of each packet.
- Differentiated Services Code Point (DSCP)– Usually set to 0, but may indicate particular Quality of Service needs from the network; the DSCP defines how routers should queue packets while waiting to be forwarded.
- ECN: Explicit Congestion Notification. It carries information about the congestion seen in the route.
- Total Length: Length of entire IP Packet (including IP header and IP Payload).
- Identification: If an IP packet is fragmented during the transmission, all the fragments contain the same identification number. To find the original IP packet they belong to.
- Flags: As required by the network resources, if an IPv4 Packet is too large to handle, these ‘flags’ tell if it is fragmented or not. In this 3-bit flag, the MSB is always set to ‘0’.
- Fragment Offset: This 13-bit field specifies the fragment’s place in the original fragmented IP packet.
- Time-to-Live (TTL): This field has an 8-bit binary value used to limit a packet’s lifetime. The packet sender sets the initial TTL value, which decreases by one each time the packet is processed by a router. If the TTL field decrements to zero, the router discards the packet and sends an Internet Control Message Protocol (ICMP) Time Exceeded message to the source IP address.
- Protocol – This 8-bit binary value indicates the data payload type that the packet is carrying, which enables the network layer to pass the data to the appropriate upper-layer protocol. Common values include ICMP (1), TCP (6), and UDP (17).
- Header Checksum: This 16-bit field stores a checksum of the header. The receiver can use the checksum to check for errors in the header.
- Source IP Address – Contains a 32-bit binary value that represents the source IP address of the packet.
- Destination IP Address – Contains a 32-bit binary value that represents the destination IPv4 address of the packet.
- Options: This is an optional field of the IPv4 packet header, which is used if the value of IHL is greater than 5. These options may include security, record route, timestamp, etc.
The two most common fields of the IPv4 packet header are the source and destination IP addresses. These fields find the source and destination of the packet. Typically these addresses do not change while travelling from the source to the destination.