Where did the packet come from? Where should it go? How large is it? Which Transport Layer protocol is inside it? Can the packet be fragmented?
All this information is stored inside the IPv4 header.
An IPv4 packet or IPv4 datagram contains an IPv4 header followed by payload data.
The minimum IPv4 header is 20 bytes and the maximum is 60 bytes.
Important header fields include Version, IHL, DSCP/ECN, Total Length, Identification, Flags, Fragment Offset, TTL, Protocol, Header Checksum, Source Address and Destination Address.
IPv4 also supports fragmentation when a packet is larger than the MTU of an outgoing link and fragmentation is allowed.
What Is an IPv4 Packet?
An IPv4 packet is the Network Layer data unit used by Internet Protocol version 4.
It carries data from a source IP address toward a destination IP address across interconnected networks.
Every IPv4 packet contains two main parts:
- IPv4 Header
- Payload or Data
IPv4 Packet vs IPv4 Datagram
In IPv4 discussions, the words packet and datagram are often used for the same Network Layer unit.
You may therefore see:
In university questions, both terms normally refer to the complete IPv4 header plus payload.
Basic IPv4 Packet Structure
20 to 60 Bytes
TCP Segment, UDP Datagram or Other Data
Complete IPv4 Header Format
The IPv4 header is organised in rows of 32 bits.
IPv4 Header Size
The minimum IPv4 header is:
If options are present, the header can become larger.
The maximum IPv4 header size is:
1. Version Field
The Version field tells the receiver which IP version is being used.
For an IPv4 packet:
2. IHL — Internet Header Length
IHL tells us how large the IPv4 header is.
The field is 4 bits long.
But the IHL value does not directly store bytes.
It stores the number of:
Minimum Header
Maximum Header
3. DSCP and ECN Field
The 8-bit field after IHL was historically called the Type of Service field.
Modern use divides it into:
- DSCP — 6 bits
- ECN — 2 bits
DSCP
DSCP stands for Differentiated Services Code Point.
It can be used to classify traffic for different forwarding treatment.
ECN
ECN stands for Explicit Congestion Notification.
It can help compatible endpoints and routers signal congestion without depending only on packet loss.
4. Total Length Field
Total Length tells us the size of the complete IPv4 datagram.
The field is 16 bits long.
Therefore the largest value it can represent is:
5. Identification Field
Identification is a 16-bit field used during IPv4 fragmentation.
When one original IPv4 datagram is fragmented, the fragments use the same Identification value so the destination can recognise that they belong to the same original datagram.
6. IPv4 Flags Field
The Flags field contains 3 bits.
Normally 0
7. DF — Don't Fragment Flag
DF tells routers whether the IPv4 datagram may be fragmented.
Fragmentation is allowed.
The packet must not be fragmented by an IPv4 router.
If DF is set and the packet is too large for the outgoing MTU, the router cannot fragment it.
8. MF — More Fragments Flag
MF tells the destination whether more fragments are still expected.
More fragments follow.
This is the final fragment.
9. Fragment Offset
Fragment Offset tells the destination where a fragment's payload belongs in the original datagram.
The field contains 13 bits.
It is measured in:
10. TTL — Time To Live
TTL is an 8-bit field used to prevent packets from circulating forever if a routing loop occurs.
Each router decreases the TTL value as the packet is forwarded.
TTL = 64
TTL = 63
TTL = 62
If TTL reaches zero, the packet is discarded.
The router normally sends an ICMP Time Exceeded message toward the source.
11. Protocol Field
The Protocol field tells the destination which upper-layer protocol is carried inside the IPv4 payload.
TCP = 6
UDP = 17
12. IPv4 Header Checksum
The IPv4 Header Checksum is used to detect corruption in the IPv4 header.
Calculates IPv4 Header Checksum
TTL changes, so header changes
Recalculates Header Checksum
13. Source IPv4 Address
The Source Address field is 32 bits long.
It identifies the IPv4 address of the packet's source.
192.168.1.20
14. Destination IPv4 Address
The Destination Address field is also 32 bits long.
Routers use the destination address when making forwarding decisions.
Destination Address: Where packet should go.
15. IPv4 Options
Options are optional fields that can extend the IPv4 header beyond its normal 20-byte minimum.
Options have historically supported functions such as:
- Timestamp information
- Route recording
- Special routing controls
Options are not normally present in ordinary IPv4 traffic.
16. Padding
Padding is added when required so the IPv4 header ends on a 32-bit boundary.
This is necessary because IHL measures the header length in 32-bit words.
IPv4 Encapsulation
At the Internet Layer, IPv4 takes data from an upper-layer protocol and adds an IPv4 header.
What Is IPv4 Fragmentation?
IPv4 fragmentation divides one large IPv4 datagram into smaller fragments.
This may be necessary when the packet is larger than the MTU of an outgoing link and fragmentation is allowed.
Cannot Fit Smaller MTU
+
Data Part 1
+
Data Part 2
+
Remaining Data
Why Does IPv4 Fragmentation Happen?
Different network links can have different MTUs.
Suppose:
A 4000-byte packet cannot fit directly into a 1500-byte MTU.
If DF is not set, IPv4 fragmentation may be used.
How IPv4 Fragmentation Works
- Router receives an IPv4 datagram.
- Router checks the outgoing interface MTU.
- If packet size is less than or equal to MTU, it forwards the packet normally.
- If packet is too large, router checks the DF flag.
- If DF = 1, the router cannot fragment it.
- If DF = 0, the router may divide the datagram into fragments.
- Each fragment receives its own IPv4 header.
- Identification, MF and Fragment Offset help the receiver reassemble the original packet.
IPv4 Fragment Reassembly
IPv4 fragments are reassembled at the destination host.
Reassembled at Destination
Important IPv4 Fragmentation Formulas
Solved IPv4 Fragmentation Numerical
An IPv4 datagram has:
Step 1: Find Original Payload
Step 2: Maximum Data Per Full Fragment
1480 is already divisible by 8.
Step 3: Divide Payload
Step 4: Fragment Offsets
Final Fragmentation Table
| Fragment | Data Size | Total Length | Offset | MF |
|---|---|---|---|---|
| 1 | 1480 bytes | 1500 bytes | 0 | 1 |
| 2 | 1480 bytes | 1500 bytes | 185 | 1 |
| 3 | 1020 bytes | 1040 bytes | 370 | 0 |
Offsets = 0, 185, 370
MF = 1, 1, 0
Solved IHL Numerical
Suppose an IPv4 packet has:
Find header size.
Solved Total Length Numerical
Suppose:
IPv4 + TCP Overhead Numerical
Assume:
Segment vs Packet vs Frame
IPv4 vs IPv6 Fragmentation
| Point | IPv4 | IPv6 |
|---|---|---|
| Router Fragmentation | Allowed when required and DF permits it | Transit routers do not fragment |
| Source Fragmentation | Possible | Performed by source when required |
| Fragment Fields | Identification, Flags and Offset are in IPv4 header | Uses Fragment extension header |
| Reassembly | Destination | Destination |
IPv4 Packet Format Remember Tricks
MF = More fragments?
Offset = Where does this data belong?
TCP = 6
UDP = 17
Common IPv4 Packet Format Exam Mistakes
Wrong. IHL gives the number of 32-bit words. Multiply it by 4 to get bytes.
Wrong. Minimum IPv4 header is 20 bytes.
Wrong. It contains header plus payload.
Wrong. It checks only the IPv4 header.
In normal forwarding behaviour, routers reduce the TTL value as packets cross router hops.
Wrong. DF = 1 means Don't Fragment.
Wrong. MF = 0 also appears on the final fragment.
Wrong. It is measured in units of 8 bytes.
Wrong. Fragments belonging to the same original datagram use the same Identification value.
Wrong. IPv4 fragments are reassembled at the destination.
Wrong. It identifies the upper-layer protocol, such as TCP or UDP.
Wrong. Each IPv4 address field is 32 bits.
40 Important IPv4 Packet Format Questions With Answers
20 IPv4 Packet Format MCQs With Answers
A. 8 bytes
B. 20 bytes
C. 32 bytes
D. 64 bytes
A. 40 bytes
B. 48 bytes
C. 60 bytes
D. 64 bytes
A. 4
B. 6
C. 8
D. 32
A. 32-bit words
B. Bytes directly
C. Kilobytes
D. Seconds
A. 5 bytes
B. 10 bytes
C. 20 bytes
D. 40 bytes
A. Header only
B. Payload only
C. Header + Payload
D. MAC header only
A. 1500 bytes
B. 65,535 bytes
C. 4096 bytes
D. 255 bytes
A. Data Fragment
B. Don't Fragment
C. Destination Flag
D. Direct Frame
A. More Fragments
B. Main Frame
C. Maximum Fragment
D. Multiple Format
A. More fragments follow
B. Final fragment
C. Fragment corrupted
D. Fragment offset zero
A. 8-byte units
B. 16-byte units
C. Bits only
D. Seconds
A. Routers
B. Browsers only
C. DNS only
D. Switches only
A. 1
B. 6
C. 17
D. 32
A. 1
B. 6
C. 17
D. 41
A. 1
B. 6
C. 17
D. 20
A. IPv4 header only
B. Entire Ethernet frame
C. Application payload only
D. TCP payload only
A. 8 bits
B. 16 bits
C. 32 bits
D. 64 bits
A. Final destination
B. Every router
C. First switch
D. DNS server
A. Protocol
B. TTL
C. IHL
D. Identification
A. 10 bytes
B. 20 bytes
C. 32 bytes
D. 40 bytes
Frequently Asked Questions
What is an IPv4 packet?
An IPv4 packet is a Network Layer data unit containing an IPv4 header followed by payload data.
What is the minimum IPv4 header size?
The minimum IPv4 header size is 20 bytes.
What is the maximum IPv4 header size?
The maximum IPv4 header size is 60 bytes.
What does IHL mean?
IHL means Internet Header Length. Its value represents the number of 32-bit words in the IPv4 header.
What does the Total Length field contain?
It contains the complete IPv4 datagram length, including the header and payload.
What is the purpose of TTL?
TTL prevents packets from circulating forever by being reduced as packets cross routers.
What is the IPv4 Protocol field?
It identifies the protocol carried in the IPv4 payload, such as TCP, UDP or ICMP.
What is IPv4 fragmentation?
IPv4 fragmentation divides a large datagram into smaller fragments so it can cross a link with a smaller MTU.
What is Fragment Offset?
Fragment Offset indicates where a fragment's payload belongs within the original datagram and is measured in units of 8 bytes.
What is the difference between DF and MF?
DF controls whether fragmentation is allowed, while MF indicates whether more fragments follow the current fragment.
Where are IPv4 fragments reassembled?
They are reassembled at the final destination host.
Does IPv4 Header Checksum check the payload?
No. IPv4 Header Checksum protects only the IPv4 header.
Quick IPv4 Packet Format Revision
Final Memory Trick:
Version tells which IP.
IHL tells header size.
Total Length tells packet size.
ID + Flags + Offset handle fragmentation.
TTL stops endless loops.
Protocol tells what comes next.
Checksum checks the header.
Source and Destination tell where the packet comes from and where it has to go.
