Internet Protocol (IP) is the communications protocol in the network layer. Its main operation is routing. It forwards packets originating at a host to its destination, one router at a time.
In summary, the transport layer breaks up data streams into IP packets. Then, IP routers forward these packets through the Internet. At the destination, the network layer reassembles all the packets into the original stream. Finally, the transport layer takes and processes the data.
The Internet is made up of different networks. The hardware for these networks supports varying bandwidths. As a result, sometimes, the routers have to break the IP packets into smaller parts along the way. This is called fragmentation.
In this tutorial, we’ll discuss the IPv4 datagram in detail.
2. IPv4 Datagram
IPv4 was developed in 1981, and it’s still widely used. It uses 32-bit address space.
An IPv4 packet is called a datagram. It is made up of a header and a data part:
IPv4 header contains a 20-byte fixed mandatory part, followed by optional fields. Hence, the minimum size of an IPv4 header is 20 bytes.
The optional part contains options and padding. It can grow up to 40 bytes in size. So, the maximum header size is 60 bytes.
A datagram can carry up to 65,535 bytes of data (), at least 20 bytes of it being the header. Hence, the maximum amount of data it carries is 65,515 bytes.
The header part contains 14 fields. The first 13 are mandatory. The last one is the optional field called options. Let’s look at the individual header fields.
IP version field, set to 4 for IPv4.
2.2. Internet Header Length
IHL is the number of 32-bit words making up the header field. The minimum available number is 5, as the first 20 bytes are mandatory.
2.3. Differentiated Services Code Point (DSCP)
It specifies the type of service for differentiated services, such as voice over IP.
2.4. Explicit Congestion Notification (ECN)
When supported, ECN carries a network congestion notification without dropping packets or wasting bandwidth.
2.5. Total Length
It’s the total size of the datagram, including both header and data parts.
It’s mainly used to indicate a group of fragments if the datagram is fragmented.
Different combinations of the flags control the fragmentation and indicate fragmented datagrams.
We assume the don’t fragment flag is set when the destination can’t assembly the fragmented packet. Therefore, the packet is dropped if the flags mark the datagram as not to be fragmented, but it must be.
2.8. Fragment Offset
It contains the offset of a fragmented packet.
2.9. Time to Live (TTL)
The number of hops a packet lives. Each router on the way decrements the TTL field. If it reaches 0, the packet is discarded. This way, looping packets are eliminated.
It’s the protocol for the data part.
2.11. Header Checksum
It’s a checksum for error detection, covering only the header field. Each router checks this value and discards the packet if an error is detected.
The data part’s checksum is not calculated.
2.12. Source Address
Source host IPv4 address.
2.13. Destination Address
Destination host IPv4 address.
Additional options are stored in this field when present.
In this article, we’ve learned about the most widely used network communications protocol. Then we investigated the structure of a datagram.