A packet capture shows bytes, addresses and numbers, but where does the data begin? Read the Internet Protocol version 4 (IPv4) header’s length first, then use the total length to find the other boundary. The layout of an IPv4 packet header also tells you how the packet is routed, what follows the header and whether it is a fragment.
IPv4 header format: The first boundaries
An IPv4 packet consists of a header followed by a payload. The header begins with a four-bit version field: the value 4 identifies IPv4. Next is the four-bit Internet Header Length, or IHL. Its unit is a 32-bit word, which is four bytes. An IHL of 5 therefore means a 20-byte header; an IHL of 6 means 24 bytes. Valid headers range from 20 to 60 bytes, including any options and padding.
The 16-bit total length field is measured in bytes and includes both header and payload. Its maximum value is 65,535 bytes. Subtract the header length from total length to find the payload length in this packet. The IPv4 specification, RFC 791, defines the fields and their units.
For example, suppose IHL is 5 and total length is 100. The header is 5 × 4 = 20 bytes, so the payload is 80 bytes. Counting from byte offset zero at the start of the IP header, the header occupies offsets 0–19 and the payload occupies offsets 20–99. A link-layer frame can contain additional headers or padding outside that IP length; a truncated capture may contain fewer bytes than the packet declares.
Addresses, service and protocol
The source and destination addresses are each 32 bits, normally displayed as four decimal numbers such as 192.0.2.1. They identify the IP endpoints in the packet as observed at that point; network address translation can change an address in transit. Routers use destination information along with their routing tables to choose where to forward traffic.
The IPv4 header format also contains an eight-bit protocol field that identifies what follows the IP header. Common values include 6 for TCP, 17 for UDP and 1 for ICMP. Protocol is not a port number: TCP and UDP ports, when present, are fields in their respective transport headers, which begin inside the IP payload. A noninitial fragment may not contain the beginning of that transport header.
The byte historically called Type of Service is now used for differentiated services and explicit congestion notification, commonly shown as DSCP and ECN. These fields convey traffic-handling and congestion information; they are not a promise that every network will provide a particular level of service. RFC 3168 describes the ECN use of the field.
TTL and checksum
Time to Live (TTL) limits a packet’s lifetime in the network. Each forwarding router reduces it by at least one; if it reaches zero, the packet is discarded, preventing indefinite circulation. A router may send an ICMP Time Exceeded message back to the source. Traceroute exploits this behavior with probes that have progressively larger TTL values, although not every router responds.
The IPv4 header has a header checksum that helps detect corruption in the header. It does not cover the payload or authenticate the sender. Because TTL changes in forwarding, the checksum must be updated as well. If a capture reports an apparently invalid checksum, consider where it was captured and whether checksum offloading by the network interface affects what the capture shows before concluding that the packet was damaged on the wire.
Identification, flags and fragment offset
An IPv4 datagram may be divided into fragments if it is too large for a link and fragmentation is permitted. Each fragment has its own IP header. The identification field helps the receiving host associate fragments of the same original datagram, together with address and protocol context.
The flags include DF, or Don’t Fragment, and MF, or More Fragments. DF requests that the datagram not be fragmented; if it cannot pass a link at its current size, it may be discarded with an appropriate error returned. MF indicates that more fragments follow. The fragment offset says where this fragment’s payload belongs in the original payload, in units of eight bytes. An offset of 100 therefore means 800 bytes from the beginning of the original payload. A final fragment has MF set to zero; an unfragmented datagram also has offset zero and MF zero.
When interpreting the structure of a fragmented IPv4 datagram, remember that total length describes that fragment, not the original datagram’s complete size. Its header length determines where that fragment’s data begins. Options, when present, can affect header length, so do not assume every IPv4 header is 20 bytes.
Do not apply the same layout to IPv6
IPv6 has a fixed 40-byte base header and uses extension headers for optional information. Its routers do not fragment packets; fragmentation is performed by the source using a Fragment extension header. IPv6 also has no checksum in its base header. The IPv6 specification, RFC 8200, describes those differences.
For a quick reference to the fields and boundaries of an IPv4 datagram header: multiply IHL by four for header bytes; subtract that from total length for this packet’s payload; read addresses, TTL and protocol for delivery context; and check DF, MF, identification and offset × eight bytes before interpreting fragments. The checksum covers the header only.



