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.
KnowledgeGate Team
Exam prep & CS education

An IP address looks familiar, yet it is easy to mix up what the network layer, an IPv4 header and a router each do. A 60-byte datagram crosses two routers. Its header checksum is calculated, its end-to-end fields remain unchanged, and other values change at every hop. Use GATE CS Exam Preparation as the preparation hub.
1. What the network layer does before the header arithmetic
Application data enters a TCP or UDP segment, then an IPv4 datagram, then a link-layer frame. Together, these layers form the path from application data to a link-layer frame.
The network layer provides logical addressing and moves datagrams through routers. Forwarding selects an interface or next hop for one packet; routing creates and updates table paths. The header discovers no route, and no routing algorithm travels inside it.
Basic IPv4 is best effort and promises no delivery, ordering, duplicate suppression or recovery. Reliability belongs elsewhere.
2. Read the IPv4 header in functional groups
Version identifies IPv4, while IHL counts 32-bit header words. Thus 0x45 means Version 4, IHL 5 and 5 x 4 = 20 bytes. Total Length includes header and payload. 0x003C = 60 bytes, leaving 60 - 20 = 40 bytes.
DS supports differentiated treatment. Identification, Flags and Fragment Offset support fragmentation. TTL limits lifetime, Protocol names the next layer, Header Checksum protects the header, and Source and Destination are 32-bit addresses.
IHL above 5 indicates options. Protocol 0x06 identifies TCP, not port 6. The checksum covers the IPv4 header, not payload or frame.
3. Worked example: decode one complete 20-byte IPv4 header
Decode this constructed header, whose checksum is filled:
45 00 00 3C 1C 46 40 00 40 06 32 24 C0 00 02 0A C6 33 64 14
Byte range | Hex | Decoded value |
|---|---|---|
0 |
| Version |
1 |
| DS field |
2-3 |
| Total Length |
4-5 |
| Identification |
6-7 |
| DF |
8 |
| TTL |
9 |
| Protocol |
10-11 |
| Header Checksum |
12-15 |
| Source |
16-19 |
| Destination |
Payload starts at offset 20 and occupies 40 bytes. DF prevents router fragmentation; MF and offset are zero, so this is not presented as a fragment. The three address blocks are documentation networks, not endpoints to contact.

4. Calculate the checksum, then update it at a router
Set the checksum to 0000, then add these 16-bit words using one's-complement addition:
4500 + 003C + 1C46 + 4000 + 4006 + 0000 + C000 + 020A + C633 + 6414
The sum is 0x2CDD9. Fold the carry: 0xCDD9 + 0x0002 = 0xCDDB. Its one's complement is 0x3224. Adding the words with 0x3224 present folds to 0xFFFF, verifying it.
With no options, fragmentation or other changes, R1 lowers TTL from 64 to 63. Word 0x4006 becomes 0x3F06 and checksum becomes 0x3324. R2 lowers TTL to 62, producing 0x3424. The protected header changed, so its checksum changed.
Remains unchanged on this path | Changes at each forwarding router |
|---|---|
Source | TTL and Header Checksum |
The path assumes no NAT, options or fragmentation.
5. Direct delivery, next-hop forwarding and changing frames
Host A 192.0.2.10/24 sees Host B 198.51.100.20/24 is outside its /24. It sends a frame towards R1 192.0.2.1/24, retaining Host B as the IPv4 destination. IP Addressing and Subnetting Explained covers the decision.
R1 has 192.0.2.0/24 directly connected, 203.0.113.0/30 directly connected, and 198.51.100.0/24 via 203.0.113.2. R1 is 203.0.113.1/30; R2 is 203.0.113.2/30. R1 selects the last route, sets TTL 63 and checksum 0x3324, then builds a frame.
R2 sets TTL 62 and checksum 0x3424, then uses its directly connected 198.51.100.0/24 LAN interface 198.51.100.1/24 to frame Host B.
Each link gets a new frame; IPv4 Source and Destination remain end to end here. For ARP, ICMP, DHCP, NAT and fragmentation, use IPv4 and Network Layer Protocols: Complete Guide with Worked Examples for GATE CS. The unfragmented datagram isolates the forwarding lookup and per-hop header changes.

6. IPv4 basics traps to catch before submitting an answer
Mistake | Wrong conclusion | Correction |
|---|---|---|
IHL | Payload begins too early | Multiply IHL by 4 |
Total Length | Claims 60 data bytes | Subtract the 20-byte header |
Protocol | Mixes layers | Identify TCP; TCP reads ports |
Destination becomes | Confuses destination and next hop | Only the first frame targets the gateway |
One frame travels end to end | Ignores link boundaries | Routers rebuild the frame |
TTL stays | Misses router processing | Use |
Checksum includes payload | Uses the wrong scope | Check only the IPv4 header |
Recalculation includes | Produces the wrong result | Zero the field first |
| Misreads the flags | DF |
NAT, options or fragmentation would break these assumptions.
7. How questions test IPv4 basics
Practice can ask you to decode Version and IHL, derive payload length, identify Protocol, read flags, verify checksum, trace TTL, choose local delivery or a gateway, and distinguish frame from IPv4 addresses.
Try these answer-first drills:
Header:
0x47gives Version4, IHL7, and7 x 4 = 28 bytes. With Total Length100, payload is100 - 28 = 72 bytes.TTL: TTL
5across three routers leaves them as4,3and2.Delivery:
10.1.2.9/24and10.1.3.8are on different/24networks, so the source uses a next hop.
Use the GATE Test Series for optional timed practice on network-layer and IPv4 questions.
8. The short version and the next step
IPv4 supplies logical addressing and datagram forwarding.
IHL gives header size in 4-byte words.
Total Length includes the header and payload.
Protocol identifies the next layer.
On this path, routers change TTL and Header Checksum while preserving Source and Destination.
The packet has 0x45, Total Length 60, header 20, payload 40, TCP, TTL 64 and checksum 0x3224.
In five minutes, cover the table, rebuild it, recompute 0x3224, then trace R1 and R2. GATE Guidance by Sanchit Sir is an optional study route. Return to GATE CS Exam Preparation for the wider catalogue.
Keep learning
MPLS Explained: Label Switching, Header Fields and a Packet Walkthrough
See where an MPLS label comes from, why it changes at each hop, how the shim header is encoded, and when ordinary IP forwarding resumes.
IPv4 Basics MCQs: 10 Solved Network Layer Questions with Explanations
Solve 10 IPv4 and Network Layer MCQs, then verify each answer through field widths, layer counts and a connected hexadecimal-header calculation.
TTL, Protocol & IPv4 Checksum MCQs: 12 Solved Questions with Explanations
Solve 12 published IPv4 questions covering TTL, Protocol, IHL, checksum position, CRC, NAT and hop counting. Each answer includes a fresh, step-by-step explanation.
TCP Header Fields MCQs: 12 Solved Questions on Sequence Numbers, Windows and Checksums
Solve 12 TCP header questions with the original stems and options, then check clear explanations for fields, sequence space, windows, checksums and payload size.





