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
| Field | Offset | Size | Type | Description |
|---|---|---|---|---|
Version version | 0 bits | 4 bits | uint8 | IP version (always 4 for IPv4) |
IHL ihl | 4 bits | 4 bits | uint8 | Internet Header Length in 32-bit words (minimum 5) |
DSCP dscp | 8 bits | 6 bits | uint8binary | Differentiated Services Code Point (QoS) |
ECN ecn | 14 bits | 2 bits | uint8binary | Explicit Congestion Notification |
Total Length total_length | 16 bits | 16 bits | uint16 | Total length of IP packet in bytes (header + data) |
Identification identification | 32 bits | 16 bits | uint16hex | Unique identifier for fragmentation reassembly |
Flags flags | 48 bits | 3 bits | uint8binary | Control flags (Reserved, DF, MF) |
Fragment Offset fragment_offset | 51 bits | 13 bits | uint16 | Position of fragment in original datagram (in 8-byte blocks) |
TTL ttl | 64 bits | 8 bits | uint8 | Time To Live (hop limit) |
Protocol protocol | 72 bits | 8 bits | uint8 | Protocol used in data portion Known values: 1=ICMP, 2=IGMP, 6=TCP, 17=UDP, +5 more |
Header Checksum header_checksum | 80 bits | 16 bits | uint16hex | Checksum of IP header only |
Source IP source_ip | 96 bits | 32 bits | uint32hex | Source IP address |
Destination IP dest_ip | 128 bits | 32 bits | uint32hex | Destination 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)
Related Resources
Quick Facts
ProtocolIPv4
Header Size20 bytes
Fields13
Endiannessbig
SpecificationRFC 791