IP Options and Padding Explained: IHL, Alignment and a Worked IPv4 Header
Learn to locate the IPv4 options area, calculate padding, decode a Record Route option byte by byte, and find the payload boundary without guessing.
KnowledgeGate Team
Exam prep & CS education

An IPv4 question says IHL = 10, and it is easy to read that as 10 bytes. Another gives 17 option bytes, and the tempting subtraction forgets both the fixed header and alignment padding. The options follow the fixed header, padding completes the aligned header, Record Route encodes route data, and the payload follows the header. Use GATE CS Exam Preparation as a preparation hub for the wider subject.
1. Where IPv4 options and padding sit in the header
The fixed IPv4 header occupies the first 20 bytes. Options follow the destination address, then any needed zero padding makes the complete header end on a 4-byte boundary. The payload begins at offset 4 x IHL, counting the datagram's first byte as offset 0. Use IPv4 and Network Layer Protocols: Complete Guide for the full header and supporting protocols. For option-specific problems, track padding and payload boundaries byte by byte.
Keep three different lengths separate:
Field | Unit | What it counts |
|---|---|---|
IHL | 32-bit words | The entire IPv4 header |
Option Length | Bytes | That option itself, including its Type and Length bytes |
Total Length | Bytes | Header plus payload |
The IPv4 header checksum covers everything selected by IHL, including options and padding, but not the payload.
No options gives IHL = 5, or 5 x 4 = 20 bytes. The largest valid IHL is 15, or 15 x 4 = 60 bytes. Options plus padding can therefore occupy at most 60 - 20 = 40 bytes; padding may consume part of that space.
2. Calculate option padding and IHL without guessing
Let O be the raw option-list length before alignment. The fixed header is already aligned, so use:
Padding:
P = (4 - (O mod 4)) mod 4Header bytes:
H = 20 + O + PInternet Header Length:
IHL = H / 4
Three quick checks confirm the formula. For O = 0, P = 0, H = 20, and IHL = 5. For O = 6, P = 2, H = 28, and IHL = 7. For O = 17, P = 3, H = 40, and IHL = 10.
The first header byte holds Version in its upper four bits and IHL in its lower four bits. Version 4 and IHL 10 become 0100 1010, or hexadecimal 0x4A. If Total Length is 100 bytes, payload length is 100 - 40 = 60 bytes. The answer is not 100 - 17 = 83, because that subtraction ignores the 20-byte fixed header and three padding bytes.

3. Read the option Type, Length and control bytes
An option Type is copied flag, 1 bit | class, 2 bits | option number, 5 bits. In 0x07 = 00000111, these are copied flag 0, class 00, and option number 00111 = 7, the Record Route type. In 0x83 = 10000011, they are copied flag 1, class 00, and option number 00011 = 3.
Two controls are one byte long. EOL, Type 0, ends the meaningful list. NOP, Type 1, consumes one byte and continues, so it can align the next option. A multi-byte option has Type, Length, then its defined control or data bytes. Length includes its own Type and Length octets, but not padding after EOL.
Record Route is Type, Length, Pointer, route-data slots. With n IPv4-address slots, Length is 3 + 4n bytes, so three slots need 3 + 4(3) = 15 bytes. Pointer is the one-based position for the next address. It starts at 4; after three addresses, 16 is one past this option and signals no free slot.
4. Worked example: parse a 40-byte IPv4 header byte by byte
In this constructed area, offset 20 contains NOP 01. Offsets 21 to 35 hold a 15-byte Record Route option:
Offset
21: Type07Offset
22: Length0F, decimal15Offset
23: Pointer10, decimal16Offsets
24to27:C0 00 02 01, or192.0.2.1Offsets
28to31:C6 33 64 09, or198.51.100.9Offsets
32to35:CB 00 71 07, or203.0.113.7Offset
36: EOL00Offsets
37to39: padding00 00 00
Here NOP places the first route address at offset 24, a 4-byte boundary. This does not mean every option must begin on one.
Audit the lengths:
Meaningful option list
= 1 NOP + 15 Record Route + 1 EOL = 17 bytes.Padding
= (4 - (17 mod 4)) mod 4 = (4 - 1) mod 4 = 3 bytes.Option area including padding
= 17 + 3 = 20 bytes.Header
= 20 + 20 = 40 bytes.IHL = 40 / 4 = 10, so the first byte is0x4A.Payload
= 100 - 40 = 60 bytes.
A parser uses IHL to mark offset 40 as payload, reads NOP at 20, and uses Length 15 to advance from 21 to 36. EOL stops meaningful options; the last three zero octets are header padding. Payload starts at the IHL boundary, not after EOL at offset 37.

5. What the copied flag changes during fragmentation
Copied flag 1 puts an option in every fragment. Flag 0 keeps it in the first fragment but not later ones. This is not sender-to-receiver copying or duplication at every router. Fragment sizes and offsets are worked in IP Fragmentation and MTU Explained. Option copying is a separate calculation: determine which bytes survive, then recompute each fragment's IHL.
Suppose the original list has a 0x83 option of Length 7, a 0x07 Record Route option of Length 7, and EOL. Meaningful bytes are 7 + 7 + 1 = 15. One pad byte gives a 16-byte option area, so header length is 20 + 16 = 36 bytes and IHL = 9.
A later fragment keeps copied option 0x83 plus EOL: 7 + 1 = 8 bytes, already aligned. Its header is 20 + 8 = 28 bytes, so IHL = 7. Option sets can make IHL differ between fragments. Use each fragment's own IHL and Total Length, and derive its payload offset from its first byte.
6. Common IP options and padding traps
Use mistake -> wrong result -> fix:
Reading
IHL = 10as 10 bytes puts payload at offset 10. Multiply by 4 to get offset 40.Treating Total Length as payload size gives 100 data bytes. Subtract the 40-byte header to get 60.
Dividing
17 / 4and rounding down gives IHL 9. Add three pad bytes first, then use IHL 10.
Sanity box:
0x45means Version 4, IHL 5, and a 20-byte header.0x4Fmeans Version 4, IHL 15, and a 60-byte header. Six raw option bytes need two pad bytes. Thirty-nine need one and exactly fill the 40-byte option-area limit.
If an option list's rounded size exceeds 40 bytes, it cannot fit in a valid IPv4 header.
7. How questions test IP options and padding, then the short version
Questions can ask you to decode Version/IHL, convert IHL to bytes, find padding, subtract the header from Total Length, step through Type-Length bytes, read a Record Route pointer, or apply the copied bit. Use this routine: decode IHL, multiply by 4, mark payload, total meaningful option bytes, check padding, then parse within the header boundary.
Review IP Addressing and Subnetting Explained for address and prefix foundations, then use the GATE Test Series for timed practice.
The short version
IHL counts 4-byte words. Padding rounds options to a 4-byte boundary. Total Length includes header and payload. EOL ends options, NOP can align, and the copied bit decides which fragments retain an option.
For a five-minute check, take first byte 0x48, Total Length 84, and raw options of 9 bytes. Version is 4; IHL is 8; header is 8 x 4 = 32 bytes; padding is (4 - (9 mod 4)) mod 4 = 3 bytes; payload is 84 - 32 = 52 bytes.
Keep learning
Structures and Unions in C: Padding, Alignment and Worked sizeof Problems for GATE
Calculate structure and union sizes byte by byte, see where padding enters, and learn how member order changes the result.
IPv4 Basics Explained: Header Fields, Checksum and Packet Forwarding
Decode a complete IPv4 header, verify its checksum with one's-complement arithmetic, and follow the datagram from Host A through two routers. See exactly what changes at each hop and what remains end to end.
IPv4 Header and Fragmentation for GATE: Offset, MTU and TTL Numericals Solved
Decode the IPv4 header, split a 4000-byte datagram across a 1500-byte MTU, and verify every offset, flag and fragment length.
IP Fragmentation and MTU Explained: IPv4 Formula, Worked Examples and Exam Traps
Learn how IPv4 fragmentation works, calculate fragment sizes and offsets step by step, and catch the alignment and MF mistakes that commonly spoil correct answers.





