IPv4: fragmentation, CIDR notation, network address translation
GATE CS120 min read
IPv4 datagram
Definition. IPv4 provides connectionless, best-effort delivery of datagrams across internetworks. The header carries source and destination addresses, length, fragmentation control, TTL, protocol, and checksum. Routers may forward, fragment when permitted, or discard a datagram. Example. An IPv4 packet with protocol value 6 carries TCP; value 17 identifies UDP. Exam point. IP best effort does not guarantee delivery, order, or duplicate suppression.
IPv4 header fields
Definition. The IPv4 header is at least 20 bytes and can be longer when options are present. IHL counts 32-bit words; total length counts header plus data in bytes. The header checksum covers only the IPv4 header and must be recomputed when fields such as TTL change. Example. IHL=5 means 20-byte header; total length 1500 leaves 1480 bytes of payload. Exam point. Fragment offset is measured in 8-byte units, not bytes.
| Field | Size | Meaning |
|---|---|---|
| Version | 4 bits | IPv4 version value 4 |
| IHL | 4 bits | Header length in 32-bit words |
| DS field | 8 bits | Differentiated service/ECN markings |
| Total length | 16 bits | Entire datagram length in bytes |
| Identification | 16 bits | Associates fragments of one original datagram |
| Flags | 3 bits | Reserved, DF, MF |
| Fragment offset | 13 bits | Payload position in 8-byte units |
| TTL | 8 bits | Hop limit decremented by routers |
| Protocol | 8 bits | Identifies encapsulated upper protocol |
| Header checksum | 16 bits | Error check over header only |
| Source, destination | 32 bits each | IPv4 addresses |
| Options + padding | variable | Optional fields to word boundary |
CIDR and prefix length
Definition. CIDR notation writes an IPv4 address and prefix length /p. The first p bits identify the network prefix; the remaining 32−p bits identify addresses within that block. A /p block contains addresses when all bit patterns are counted. Example. A /26 has 6 host bits and contains 64 addresses. Exam point. Usable host counts in ordinary subnets may reserve network and broadcast addresses; address-block size still counts all patterns.
Network and broadcast address
Definition. For address A with prefix length p, the network address is A bitwise AND the prefix mask. The broadcast address sets all host bits to 1. In a conventional IPv4 subnet with p≤30, ordinary usable host range is network+1 through broadcast−1; /31 and /32 have special uses. Example. 192.0.2.77/26 has mask 255.255.255.192, network .64, broadcast .127, and conventional host range .65–.126. Exam point. Find the block size in the subnetted octet to locate the correct boundary.
Worked CIDR block calculation
Definition. For /p, the host-bit count h=32−p; block size is . The network start is the greatest multiple of block size not exceeding the address in the relevant low-order region. A subnet mask has p leading ones followed by h zeroes. Example. Determine the network and broadcast for 172.19.33.201/20. Exam point. A /20 mask spans 16 values in the third octet, not 20 values.
- /20 gives mask 255.255.240.0 and 12 host bits.
- The third-octet block size is 256−240=16.
- Third octet 33 lies in block 32–47; network is 172.19.32.0.
- Set host bits to one: broadcast is 172.19.47.255.
- Block size is addresses.
Subnetting a larger block
Definition. Borrowing b host bits creates equal-size subnets and leaves h−b host bits per subnet. Each new prefix is p+b. Subnets are aligned to their block boundaries and must not overlap when assigned to one address plan. Example. Split 192.168.10.0/24 into eight equal subnets. Exam point. Borrow bits when N is a power of two.
Eight subnets need 3 borrowed bits, giving /27. Each has addresses, with conventional 30 usable host addresses. Network starts are .0, .32, .64, .96, .128, .160, .192, and .224. The last block is .224–.255, so its broadcast is .255.
Variable-length subnet allocation
Definition. VLSM assigns blocks of different sizes according to host needs. Allocate the largest requirement first, round each need up to a power-of-two address block, then place each block on a matching boundary. Keep blocks nonoverlapping and aligned. Example. A /24 must support subnets for 100, 50, and 20 hosts. Exam point. Include network and broadcast addresses when choosing conventional IPv4 subnet size.
For 100 hosts, 7 host bits are needed because , so allocate /25. For 50 hosts, 6 host bits give 62 usable, so allocate /26. For 20 hosts, 5 host bits give 30 usable, so allocate /27. Total allocation requires 128+64+32=224 addresses and fits in the /24’s 256 addresses if aligned as .0/25, .128/26, .192/27. The remaining block is .224/27.
Longest-prefix match
Definition. A router compares a destination address with all route prefixes that match and selects the route with the longest prefix. More prefix bits mean a smaller, more specific address block. A default route /0 matches every destination not matched by a more specific route. Example. 203.0.113.77 matches 203.0.113.0/24 and 203.0.0.0/16; /24 wins. Exam point. Use bitwise prefix match; do not choose based on route insertion order unless tie rules are specified.
| Prefix | Output |
|---|---|
| 203.0.113.64/26 | interface 2 |
| 203.0.113.0/24 | interface 1 |
| 203.0.0.0/16 | interface 3 |
| 0.0.0.0/0 | gateway G |
You have read the free 30% of this note
Sign in with Google to keep reading. It is free, takes one tap, and you also get:
- 6 practice questions from this note
- Every note in full, plus the PDF library
- Official past papers as timed tests, with explanations
- An AI tutor for doubts, in Hindi or English
- Your progress, mistakes and study plan saved on every device