Protocol Tutorial

IPv4 Header Format

In-depth guide to IPv4 header structure: version, IHL, TOS, total length, identification, flags, fragment offset, TTL, protocol, header checksum, source address, and destination address.

Protocol Overview

Internet Protocol version 4 (RFC 791)

Header Size: 20 bytes (160 bits)
Fields: 13
Endianness: big
Spec: RFC 791

Header Fields

FieldOffsetSizeTypeDescription
Version
version
0 bits4 bitsuint8IP version (always 4 for IPv4)
IHL
ihl
4 bits4 bitsuint8Internet Header Length in 32-bit words (minimum 5)
DSCP
dscp
8 bits6 bitsuint8binaryDifferentiated Services Code Point (QoS)
ECN
ecn
14 bits2 bitsuint8binaryExplicit Congestion Notification
Total Length
total_length
16 bits16 bitsuint16Total length of IP packet in bytes (header + data)
Identification
identification
32 bits16 bitsuint16hexUnique identifier for fragmentation reassembly
Flags
flags
48 bits3 bitsuint8binaryControl flags (Reserved, DF, MF)
Fragment Offset
fragment_offset
51 bits13 bitsuint16Position of fragment in original datagram (in 8-byte blocks)
TTL
ttl
64 bits8 bitsuint8Time To Live (hop limit)
Protocol
protocol
72 bits8 bitsuint8Protocol used in data portion
Known values: 1=ICMP, 2=IGMP, 6=TCP, 17=UDP, +5 more
Header Checksum
header_checksum
80 bits16 bitsuint16hexChecksum of IP header only
Source IP
source_ip
96 bits32 bitsuint32hexSource IP address
Destination IP
dest_ip
128 bits32 bitsuint32hexDestination IP address

Common IPv4 Mistakes

  • 1Confusing IHL (32-bit words) with header length in bytes (multiply IHL by 4)
  • 2Forgetting that Total Length includes both header and payload
  • 3Misreading the Flags field: DF (Don't Fragment) and MF (More Fragments) are critical bits
  • 4Not understanding that Fragment Offset is in 8-byte blocks, not bytes
  • 5Assuming TTL is in seconds (it's actually hop count in modern implementations)

Try It Yourself

Parse real IPv4 packets in the interactive visualizer

Open Visualizer

Quick Facts

ProtocolIPv4
Header Size20 bytes
Fields13
Endiannessbig
SpecificationRFC 791