Figure 1 shows the IPv4 packet format.
An IPv4 datagram consists of a header and a data field. The first 20 bytes in the header are mandatory for all IPv4 datagrams. The Options field following the 20 bytes has a variable length.
Table 1 describes the meaning of each field in an IPv4 packet.
Field |
Length |
Description |
---|---|---|
Version |
4 bits |
Specifies the IP protocol version, IPv4 or IPv6. |
Header Length |
4 bits |
Specifies the length of the IPv4 header. |
Type of Service (ToS) |
8 bits |
Specifies the type of service. This field takes effect only in the differentiated service model. |
Total Length |
16 bits |
Specifies the length of the header and data. |
Identification |
16 bits |
IPv4 software maintains a counter in the storage device to record the number of IP datagrams. The counter value increases by 1 every time a datagram is sent, and is filled in the identification field. |
Flags |
3 bits |
Only the rightmost two bits are valid. The rightmost bit indicates whether the datagram is not the last data fragment. The value 1 indicates the last fragment, and the value 0 indicates non-last fragment. The middle bit is the fragmentation flag. The value 1 indicates that the datagram cannot be fragmented, and the value 0 indicates that the datagram can be fragmented. |
Fragment Offset |
13 bits |
Specifies the location of a fragment in a packet. |
Time to Live (TTL) |
8 bits |
Specifies the life span of a datagram on a network. TTL is measured by the number of hops. |
Protocol |
8 bits |
Specifies the type of the protocol carried in the datagram. |
Header Checksum |
16 bits |
A device calculates the header checksum for each datagram received. If the checksum is 0, the device knows that the header remains unchanged and retains the datagram. This field checks only the header but not the data. |
Source IP Address |
32 bits |
Specifies the IPv4 address of a sender. |
Destination IP Address |
32 bits |
Specifies the IPv4 address of a receiver. |
Options |
0-40 bytes (variable length) |
Allows IPv4 to support various options such as fault handling, measurement, and security. Pad bytes with a value of 0 are added if necessary. |
Data |
Variable |
Pads an IP datagram. |