IPv4 Header Explained: Format, Fields, Diagram & Examples
Learn the IPv4 packet header in simple language. This complete guide explains the header format, field meanings, IHL, DSCP, ECN, TTL, protocol numbers, checksum, fragmentation, Options and a decoded packet example.
What Is an IPv4 Header?
The IPv4 header is the control section at the beginning of every IPv4 datagram. It works like a shipping label: routers read the destination address, reduce the packet lifetime, identify the encapsulated protocol and decide whether the packet can be forwarded across the next link.
The minimum IPv4 header size is 20 bytes. When the optional Options field is present, the header can grow to 60 bytes. The payload follows the header and normally contains a TCP segment, UDP datagram, ICMP message or another upper-layer protocol.
IPv4 Header Lesson Contents
1. IPv4 Header Format and Packet Structure
The Internet Protocol Version 4 header is arranged in 32-bit rows and transmitted in network byte order, with the most significant byte first. The first 20 bytes contain the mandatory fields. If IHL is greater than 5, Options and Padding extend the header before the payload begins.
2. IPv4 Header Fields Explained
The fields below follow the order in which they appear on the wire. Each explanation covers one field, what the value means and how a host or router uses it.
Version - 4 bits
Purpose: identifies which Internet Protocol header format follows. Routers must interpret the remaining bits according to this value.
IPv4 value: binary 0100, which is decimal 4. A value of 6 indicates an IPv6 header instead.
IHL (Internet Header Length) - 4 bits
Purpose: tells the receiver where the IPv4 header ends and the encapsulated TCP, UDP or ICMP data begins.
How to read it: IHL counts 32-bit words. IHL 5 means 5 x 4 = 20 bytes; IHL 6 means 24 bytes. The maximum value, 15, represents a 60-byte header.
DSCP (Differentiated Services Code Point) - 6 bits
Purpose: classifies traffic for Quality of Service. Routers can use the marking to place packets into different queues or apply different forwarding treatment.
Example: DSCP 0 is normal best-effort traffic, while DSCP 46 is commonly associated with expedited forwarding for delay-sensitive voice traffic.
ECN (Explicit Congestion Notification) - 2 bits
Purpose: allows ECN-capable endpoints and routers to signal congestion without immediately dropping a packet.
How it works: endpoints indicate ECN capability, and a congested router can mark the packet. The transport protocol then reacts to the congestion signal.
Total Length - 16 bits
Purpose: gives the complete IPv4 datagram size in bytes, including the IPv4 header and its payload.
Range: 20 to 65,535 bytes. If Total Length is 1,500 and IHL is 5, the header is 20 bytes and the IPv4 payload is 1,480 bytes.
3. Identification, Flags and Fragment Offset
The next three fields work together when an IPv4 datagram is fragmented. They are still present when no fragmentation occurs.
Identification - 16 bits
Purpose: helps the destination associate fragments that belong to the same original IPv4 datagram.
Example: if a router creates three fragments, all three carry the same Identification value. The destination also considers source address, destination address and Protocol while matching fragments.
Flags - 3 bits
Reserved bit: the first bit is reserved and must be zero.
DF (Don't Fragment): when set to 1, routers must not fragment the datagram. A router drops an oversized packet and normally sends an ICMP error instead.
MF (More Fragments): set to 1 on every fragment except the final one. An unfragmented packet normally has MF 0 and Fragment Offset 0.
Fragment Offset - 13 bits
Purpose: identifies where this fragment's data belongs inside the original payload so the destination can restore the correct order.
How to read it: the value uses 8-byte units. Offset 185 means this fragment begins at payload byte 185 x 8 = 1,480.
4. TTL, Protocol and Header Checksum
Time To Live (TTL) - 8 bits
Purpose: prevents a packet from circulating forever if a routing loop occurs.
Router behavior: each router reduces TTL by at least one. A router discards the packet when TTL reaches zero and normally returns an ICMP Time Exceeded message. Traceroute uses this behavior to discover hops.
Protocol - 8 bits
Purpose: identifies the protocol carried immediately after the IPv4 header so the destination knows which decoder or transport handler should receive the payload.
Common values: ICMP 1, TCP 6, UDP 17, IPv6 encapsulation 41, GRE 47 and ESP 50.
Header Checksum - 16 bits
Purpose: detects accidental corruption in the IPv4 header. It does not protect TCP, UDP or other payload data.
Router behavior: because every router changes TTL, it must also update the header checksum before forwarding the packet.
Calculation: set the checksum field to zero, add the 16-bit header words using one's-complement addition, fold any carry, then invert all bits.
The payload is not protected by the IPv4 checksum. TCP includes its own checksum, while UDP also has a transport checksum that is optional in IPv4 and mandatory in IPv6.
5. Source, Destination, Options and Padding
Source IPv4 Address - 32 bits
Purpose: identifies the IPv4 address that originated the packet and provides an address for replies and error reporting.
Practical note: NAT, a proxy, a tunnel or another middlebox can replace the visible source address while the packet travels.
Destination IPv4 Address - 32 bits
Purpose: identifies the intended receiving IPv4 address.
Router behavior: each router compares this address with its routing table and uses longest-prefix matching to select a route and next hop.
Options - 0 to 40 bytes
Purpose: adds optional controls such as timestamps, record-route information or source-routing data.
Header effect: Options exist only when IHL is greater than 5 and can expand the IPv4 header from 20 to 60 bytes. They are uncommon and may receive slower processing or be filtered.
Padding - variable
Purpose: adds zero-value bits after Options so the complete header ends on a 32-bit boundary.
Important: Padding is included in the IHL calculation but does not carry application data.
6. IPv4 Header Explained With a Worked Example
The following 20 bytes form a valid IPv4 header. The first byte, 0x45, combines Version 4 in the high nibble and IHL 5 in the low nibble. With no Options, the payload begins immediately after byte 20.
| Field | Raw value | Decoded meaning |
|---|---|---|
| Version + IHL | 0x45 | Version 4 and IHL 5, so the header is 20 bytes. |
| DSCP + ECN | 0x00 | Default traffic class and not ECN-capable. |
| Total Length | 0x0064 | 100 bytes for header plus payload. |
| Identification | 0x0000 | Identification value 0. |
| Flags + Offset | 0x0000 | No flags set and fragment offset 0. |
| TTL | 0xFF | Decimal 255. |
| Protocol | 0x01 | ICMP. |
| Checksum | 0x2245 | Valid checksum for the displayed header. |
| Source | C0 A8 0C 01 | 192.168.12.1. |
| Destination | C0 A8 0C 02 | 192.168.12.2. |
7. IPv4 Fragmentation Example
Assume an IPv4 datagram has a 20-byte header and 3,980 bytes of payload, producing a total length of 4,000 bytes. It must cross a link with a 1,500-byte MTU, and DF is not set.
| Fragment | Payload | Total Length | MF | Fragment Offset |
|---|---|---|---|---|
| 1 | 1,480 bytes | 1,500 bytes | 1 | 0 |
| 2 | 1,480 bytes | 1,500 bytes | 1 | 185 |
| 3 | 1,020 bytes | 1,040 bytes | 0 | 370 |
The second offset is 1480 / 8 = 185. The third is 2960 / 8 = 370. All three fragments use the same Identification value, and only the final fragment has MF set to zero.
8. IPv4 Header vs IPv6 Header
IPv6 simplifies the fixed header and moves optional information into extension headers. The comparison below focuses on the parts most useful for packet analysis and CCNA study.
| Feature | IPv4 header | IPv6 header |
|---|---|---|
| Address size | 32 bits | 128 bits |
| Base header size | 20-60 bytes | Fixed 40 bytes |
| Checksum | Header checksum included | No base-header checksum |
| Router fragmentation | Possible when DF is clear | Routers do not fragment; the source uses a Fragment extension header |
| Lifetime field | TTL | Hop Limit |
| Upper-layer identifier | Protocol | Next Header |
| Optional information | Options inside the variable header | Separate extension headers |
Continue with IPv6 address types, IPv6 address shortening and the IPv6 practice page.
9. How to Analyze an IPv4 Header in Wireshark
- Capture traffic or open a packet capture file.
- Use the display filter
ipto show IPv4 traffic. - Expand Internet Protocol Version 4 in the packet details pane.
- Compare Header Length and Total Length to calculate payload size.
- Inspect DSCP and ECN when troubleshooting QoS or congestion marking.
- Check DF, MF and Fragment Offset when packets cross links with different MTUs.
- Follow TTL changes across captures from different network points.
- Verify the Protocol value before analyzing the next header as TCP, UDP or ICMP.
IPv4 Header CCNA and Interview Notes
- IHL value 5: the packet has the normal 20-byte header and no Options.
- TTL: decreases at every router and is the field that makes traceroute possible.
- Fragment Offset: uses 8-byte units, not individual bytes.
- Total Length: includes both the IPv4 header and its payload.
- Checksum: covers the header only and changes as TTL changes.
- Protocol field: points to the encapsulated upper-layer protocol.
- IPv4 Options: increase IHL and can cause slow-path handling or filtering.
For related networking basics, review IP addressing, subnetting and CIDR, IP vs MAC addressing and NAT operation.
IPv4 Header Frequently Asked Questions
What is an IPv4 header?
It is the control information placed before an IPv4 payload. It carries addressing, packet size, lifetime, protocol, fragmentation and checksum information that hosts and routers use to process the datagram.
What is IHL in IPv4?
IHL means Internet Header Length. It counts 32-bit words, so IHL 5 is 20 bytes and IHL 15 is 60 bytes.
Why is TTL used?
TTL prevents packets from looping forever. Every router reduces it, and the packet is discarded when it reaches zero.
What does the IPv4 header checksum protect?
It detects corruption in the IPv4 header only. It does not cover the payload, and routers update it after changing TTL.
What is IPv4 fragmentation?
Fragmentation divides a datagram into smaller packets for a lower-MTU link. Identification, Flags and Fragment Offset let the destination group and reassemble the pieces.
How many fields are in an IPv4 header?
The minimum header has 12 mandatory field groups when DSCP and ECN are treated as one combined field. Some diagrams count DSCP, ECN and flag bits separately. Options and Padding appear only when IHL is greater than 5.
What is the IPv4 Options field?
It is a variable-length area for controls such as timestamps or routing information. Padding aligns the header to a 32-bit boundary, and the complete header cannot exceed 60 bytes.
IPv4 Header Standards and Additional Resources
- RFC 791 - Internet Protocol
- RFC 2474 - Differentiated Services Field
- RFC 3168 - Explicit Congestion Notification
- IANA Protocol Numbers
- Subnet Calculator for IPv4 prefix, mask and host-range practice.
This lesson was independently rewritten and expanded from the supplied IPv4 header notes, with calculations and diagrams checked against the Internet Protocol specification.