Recall warm-up
- What is the smallest CIDR block size that can accommodate 50 usable hosts?
Stuck? Peek at 3.1.6 Variable-Length Subnet Masking (VLSM) & block allocation
- Block size for H usable hosts: smallest 2ʰ with 2ʰ − 2 ≥ H; prefix =
/(32 − h). - Largest-first rule: sort subnets by decreasing 2ʰ and allocate sequentially so every block is naturally aligned.
- Non-overlap: sum of block sizes ∑ 2ʰᵢ ≤ 2³²⁻ⁿ_parent, and every block starts on a multiple of its own 2ʰᵢ.
- Block size for H usable hosts: smallest 2ʰ with 2ʰ − 2 ≥ H; prefix =
- How does a receiver verify a 16-bit 1’s-complement Internet checksum?
Stuck? Peek at 2.2.3 The Internet checksum: compute and verify
- 16-bit words; checksum field = 0 while summing.
- Sum with 1's-complement addition (wrap carries); checksum = complement of the sum.
- Receiver: sum of all words + checksum = 0xFFFF → accept.
- Misses word reordering and compensating errors.
- What is the network-layer PDU called, and what does encapsulation add to the transport PDU?
Stuck? Peek at 1.1.3 Encapsulation, headers, PDU names, addresses and devices per layer
- Encapsulation: payload + header (+ trailer at data link); decapsulation in reverse.
- PDUs: message (app) → segment (transport) → packet/datagram (network) → frame (data link) → bits.
- Addresses: link (per hop, changes) · network (end to end, fixed) · which-program id · names.
- Devices: hub/repeater 1 · bridge/switch 2 · router 3 · gateway/host up to 7.
- Efficiency = data / (data + all headers + trailer).
The Hook
In Chapter 3.1 we stamped a 32-bit source IP and a 32-bit destination IP onto our network-layer envelope. Those two addresses take 4 + 4 = 8 bytes. Yet the minimum IPv4 header is 20 bytes!
What are the other 12 bytes doing? They protect the network from packets looping forever, tell the destination how long the header and packet are, help split and reassemble oversized datagrams, and identify which upper-layer protocol sits inside the payload.
Predict First
The IPv4 header length field (HLEN) is only 4 bits wide (maximum value 1111₂ = 15), yet the IPv4 header is at least 20 bytes and can be up to 60 bytes long. How can a 4-bit number represent 20 to 60 bytes?
By counting in 4-byte (32-bit) words instead of single bytes! Every value in HLEN is multiplied by 4: minimum 5 × 4 = 20 bytes (no options), maximum 15 × 4 = 60 bytes (20B base + up to 40B of options).
Core Concept
The 20-byte Fixed IPv4 Header (Five 32-bit Rows)
An IPv4 header consists of a mandatory 20-byte (5 × 32-bit) fixed part followed by 0 to 40 bytes of options (padded to a multiple of 4 bytes):
The Scaling-Factor Trio: HLEN (×4), Total Length (×1), Offset (×8)
GATE loves testing the three length/offset fields and their scaling factors:
- Version (4 bits): Always
4(0100₂) for IPv4. - HLEN / IHL (4 bits, scaling factor ×4 bytes): Header length in 32-bit words. Range 5 to 15 → 20 to 60 bytes. Values 0–4 are invalid!
- Total Length (16 bits, scaling factor ×1 byte): Total datagram length (header + payload) in bytes. Max = 2¹⁶ − 1 = 65,535 bytes; payload length =
Total Length − 4 × HLEN. - Identification (16 bits), Flags (3 bits: reserved 0, DF = Don't Fragment, MF = More Fragments), Fragment Offset (13 bits, scaling factor ×8 bytes): Used when a datagram is sliced into smaller fragments (3.2.2).
TTL, Protocol, and Header Checksum (What Changes at Every Router?)
Row 3 controls hop-by-hop survival, demultiplexing to the upper layer, and header integrity:
- Time to Live — TTL (8 bits): Despite the name, TTL is a hop counter, not seconds! Every router along the path decrements TTL by 1. If TTL reaches
0, the router discards the datagram (preventing infinite routing loops) and sends an error notification back to the source. - Protocol (8 bits): Tells the final destination's network layer which upper-layer protocol should receive the payload (e.g.,
1 = ICMP,6 = TCP,17 = UDP,89 = OSPF— here just protocol ID numbers). - Header Checksum (16 bits): 1's-complement checksum computed ONLY over the IPv4 header (NOT the data payload!). Because TTL decreases at every router, every router must recompute the Header Checksum on every hop!
| Field | Bits | Changed by a normal router? | Why? |
|---|---|---|---|
| Version, HLEN, TOS | 4, 4, 8 | No (unless TOS remarking) | Fixed at source |
| Total Length, ID, Flags, Offset | 16, 16, 3, 13 | Only if fragmentation occurs | Updated only when splitting datagram |
| TTL | 8 | YES — every router! | Decremented by 1 on each hop to stop loops |
| Protocol, Src IP, Dst IP | 8, 32, 32 | No | End-to-end identifiers |
| Header Checksum | 16 | YES — every router! | Must be recomputed because TTL changed! |
Putting it together
- The IPv4 header is 20 to 60 bytes long; the 4-bit HLEN field counts 4-byte words (5 to 15).
- Total Length (16 bits) gives the entire datagram size in bytes, so Payload = Total Length − 4×HLEN.
- Every router decrements TTL by 1 to prevent infinite loops and recomputes the 16-bit Header Checksum (which protects only the IP header).
Visual
Worked Examples
An IPv4 datagram arrives with HLEN = 5 and Total Length = 400. How many bytes of header, options, and upper-layer payload does it carry?
Show the full solution
Header length = 5 × 4 = 20 bytes. Since minimum header is 20 bytes, options = 0 bytes.
Payload = Total Length − Header = 400 − 20 = 380 bytes.
An IPv4 header carries 22 bytes of option data. What must be the value of HLEN, and how many bytes of padding are added?
Show the full solution
Total header length must be a multiple of 4 bytes. Base header (20B) + options (22B) = 42B → round up to next multiple of 4 = 44 bytes.
Padding added = 44 − 42 = 2 bytes.HLEN = 44 / 4 = 11 (1011₂).
The first 8 bits of an arriving IPv4 datagram are 01000100₂. Why does the router immediately discard the packet?
Show the full solution
First 4 bits = Version = 0100₂ = 4 (valid IPv4).
Next 4 bits = HLEN = 0100₂ = 4 → Header length = 4 × 4 = 16 bytes. Since the mandatory IPv4 base header is 20 bytes (minimum HLEN = 5), HLEN = 4 is corrupt/invalid and the packet is dropped!
GATE Traps
- HLEN minimum is 5 (0101₂), NOT 0 or 20! Any
HLEN < 5is invalid; maxHLEN = 15means at most 40 bytes of options (60 − 20 = 40). - IPv4 Header Checksum covers ONLY the IP header! Corruption in the data payload is NOT detected by the IPv4 header checksum.
- TTL is a hop count, not seconds! Even if a packet waits 5 seconds in a router queue, that router decrements TTL by 1.
Memory Hook
HLEN × 4, Total × 1, Offset × 8; TTL drops by 1 and Checksum is redone at every gate!
Connect the Dots
Look at Row 2 of the IPv4 header: Identification, Flags (DF, MF), and Fragment Offset (×8). Next question (3.2.2): What happens when our datagram is 4000 bytes long, but the next Ethernet link has an MTU of only 1500 bytes?
Self-Test
- NAT
An IPv4 datagram has HLEN = 9 (in decimal) and Total Length = 1000 bytes. How many bytes of data payload does the datagram carry?
Write your answer before opening the key.
- NAT
What is the maximum number of option bytes that can be placed in an IPv4 header?
Write your answer before opening the key.
- MSQ
Which fields of an IPv4 header are ALWAYS modified by a standard router when forwarding a datagram (assuming no fragmentation)?
- Time to Live (TTL)
- Header Checksum
- Source IPv4 Address
- Total Length
- MCQ
Why does the IPv4 Header Checksum need to be recomputed at every router along a path?
- Because the source and destination MAC addresses change at every hop.
- Because the TTL field in the IPv4 header is decremented at every hop.
- Because the data payload is re-encrypted at every hop.
- Because the Protocol field changes at every hop.
- MCQ
Which of the following values of the 4-bit HLEN field in an IPv4 datagram is INVALID?
- 5
- 6
- 15
- 3
Rule Card
- Base header = 20 B (`HLEN = 5`); Max header = 60 B (`HLEN = 15`, max 40 B options).
- Multipliers: `Header = 4 × HLEN`, `Total Length = Header + Payload` (max 65,535 B), `Offset × 8 = start byte`.
- Per-hop changes: Every router decrements TTL by 1 (drops if 0) and recomputes Header Checksum (which covers IP header only).
Concept Ledger
- IPv4 header
- version (4)
- HLEN (×4)
- type of service
- total length
- identification
- flags (DF, MF)
- fragment offset (×8)
- TTL (hop limit)
- protocol field (1/6/17)
- header checksum
- options (20–60 bytes)
Answer Vault
Try the questions first. Open when you are ready to check.
Warm-up answers
- 64 addresses (/26, since 2⁶ − 2 = 62 ≥ 50).
- It adds all 16-bit words including the checksum using 1’s-complement wrap-around addition; if the result is all 1s (complement = 0), no error is detected.
- A packet (or datagram); encapsulation prepends a network-layer header containing logical source/destination addresses and control fields.
Self-test answers
- 964 — Header length = 9 × 4 = 36 bytes. Data payload = 1000 − 36 = 964 bytes.
- 40 — 4-bit HLEN max is 15 → max total header = 15 × 4 = 60 bytes. Subtracting the 20-byte mandatory base header leaves 40 bytes for options.
- AB — Every router decrements TTL by 1 and must therefore recompute the Header Checksum. Source IP and Total Length (changed only on fragmentation) remain unchanged.
- C: Source IP is unchanged by normal routing (only MAC source changes at L2).
- D: Total Length changes only if the router fragments the datagram.
- B — The IPv4 header checksum covers the IPv4 header bytes, including TTL. Since TTL changes at every router, the checksum changes too.
- A: MAC addresses are in the Layer-2 Ethernet frame header, not the IPv4 header.
- C: IPv4 does not re-encrypt payloads.
- D: Protocol field is fixed end-to-end.
- D — Since the minimum IPv4 header is 20 bytes = 5 × 4 bytes, any HLEN < 5 (such as 3 → 12 bytes) is invalid.
- A: HLEN=5 → 20B (standard header with no options).
- B: HLEN=6 → 24B (valid, 4B options).
- C: HLEN=15 → 60B (valid, max 40B options).
Flashcards
- What are the minimum and maximum values of the 4-bit HLEN field, and what byte sizes do they represent?
Reveal answer
Min HLEN = 5 (20 bytes, no options); Max HLEN = 15 (60 bytes, 40 bytes of options). - Which two IPv4 header fields change at every router hop during normal forwarding?
Reveal answer
TTL (decremented by 1) and Header Checksum (recomputed). - Does the IPv4 Header Checksum cover the data payload?
Reveal answer
No — it covers ONLY the IPv4 header (20 to 60 bytes). - What are the scaling factors for HLEN, Total Length, and Fragment Offset?
Reveal answer
HLEN: ×4 bytes; Total Length: ×1 byte; Fragment Offset: ×8 bytes.
Exam shortcuts
- 4–1–8 Multiplier Rule:
HLEN × 4 = Header Bytes;Total Length × 1 = Total Bytes;Fragment Offset × 8 = Starting Payload Byte. — every IPv4 header numerical. - Max IPv4 Payload:
65,535 − 20 = 65,515 bytes(whenHLEN = 5). — questions asking for the maximum data bytes in one IPv4 datagram.