All notes

IPv4: fragmentation, CIDR notation, network address translation

GATE CS120 min read

Free preview: 30% of the note

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.

FieldSizeMeaning
Version4 bitsIPv4 version value 4
IHL4 bitsHeader length in 32-bit words
DS field8 bitsDifferentiated service/ECN markings
Total length16 bitsEntire datagram length in bytes
Identification16 bitsAssociates fragments of one original datagram
Flags3 bitsReserved, DF, MF
Fragment offset13 bitsPayload position in 8-byte units
TTL8 bitsHop limit decremented by routers
Protocol8 bitsIdentifies encapsulated upper protocol
Header checksum16 bitsError check over header only
Source, destination32 bits eachIPv4 addresses
Options + paddingvariableOptional 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 232−p2^{32-p} 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 2h2^h. 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.

  1. /20 gives mask 255.255.240.0 and 12 host bits.
  2. The third-octet block size is 256−240=16.
  3. Third octet 33 lies in block 32–47; network is 172.19.32.0.
  4. Set host bits to one: broadcast is 172.19.47.255.
  5. Block size is 212=40962^{12}=4096 addresses.

Subnetting a larger block

Definition. Borrowing b host bits creates 2b2^b 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 log⁡2N\log_2 N bits when N is a power of two.

Eight subnets need 3 borrowed bits, giving /27. Each has 25=322^5=32 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 27−2=1262^7-2=126, 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.

PrefixOutput
203.0.113.64/26interface 2
203.0.113.0/24interface 1
203.0.0.0/16interface 3
0.0.0.0/0gateway 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
Continue reading, free