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

Updated 26 Nov 20265 min read
IPv4 Basics Explained: Header Fields, Checksum and Packet Forwarding

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

45

Version 4; IHL 5, so header 20 bytes

1

00

DS field 0x00

2-3

00 3C

Total Length 0x003C = 60 bytes

4-5

1C 46

Identification 0x1C46 = 7238

6-7

40 00

DF 1; MF 0; Fragment Offset 0

8

40

TTL 0x40 = 64

9

06

Protocol 6 = TCP

10-11

32 24

Header Checksum 0x3224

12-15

C0 00 02 0A

Source 192.0.2.10

16-19

C6 33 64 14

Destination 198.51.100.20

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.

Grid of the 20-byte IPv4 header showing Version 4, IHL 5, Total Length 60, TTL 64, Protocol TCP and checksum 0x3224.

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 192.0.2.10; Destination 198.51.100.20; Protocol 6; Total Length 60; Identification 7238; DF 1; MF 0; Offset 0

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.

Path from Host A through routers R1 and R2 to Host B, with TTL dropping 64 to 63 to 62 and the checksum updated at each hop.

6. IPv4 basics traps to catch before submitting an answer

Mistake

Wrong conclusion

Correction

IHL 5 means 5 bytes

Payload begins too early

Multiply IHL by 4

Total Length 60 means payload

Claims 60 data bytes

Subtract the 20-byte header

Protocol 6 means a port

Mixes layers

Identify TCP; TCP reads ports

Destination becomes 192.0.2.1

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 64

Misses router processing

Use 63 after R1, 62 after R2

Checksum includes payload

Uses the wrong scope

Check only the IPv4 header

Recalculation includes 0x3224

Produces the wrong result

Zero the field first

0x4000 means MF

Misreads the flags

DF 1, MF 0, offset 0

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:

  1. Header: 0x47 gives Version 4, IHL 7, and 7 x 4 = 28 bytes. With Total Length 100, payload is 100 - 28 = 72 bytes.

  2. TTL: TTL 5 across three routers leaves them as 4, 3 and 2.

  3. Delivery: 10.1.2.9/24 and 10.1.3.8 are on different /24 networks, 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.