CIDR and subnetting
Classless addressing with the a.b.c.d/n notation: the mask from the prefix length, the network and broadcast address, usable hosts 2^(32-n) - 2, splitting a block into equal subnets by borrowing host bits, variable-length subnet masks (VLSM) allocation largest first, route aggregation (supernetting) and when blocks can be merged, and forwarding by longest prefix match; every calculation was cross-checked with Python's ipaddress module on thousands of random cases.
Why it exists
Classful addresses wasted space and bloated routing tables. CIDR (classless inter-domain routing) lets the boundary between the network part and the host part fall at any bit: an address block is written a.b.c.d/n where is the prefix length, the number of leading bits that identify the network. Blocks can be cut into smaller ones (subnetting), several adjacent blocks can be advertised as one (aggregation), and routers forward by the longest matching prefix. GATE asks for the arithmetic in all of these.
Prerequisites
You need the structure of an IPv4 address (IPv4 addressing).
Precise definitions
A CIDR block a.b.c.d/n is the set of the addresses that share the first bits. The mask is ones followed by zeros (prefix : 255.255.240.0). For an address in the block:
- network address (host bits cleared);
- broadcast address (host bits set);
- usable host addresses (network and broadcast are not given to hosts); first host network , last host broadcast .
A block is aligned: its first address is a multiple of its size . Any block of a given size starts at such a multiple.
Subnetting divides a block (a network) into smaller blocks by moving the boundary to the right: borrowing host bits gives subnets, each with prefix .
VLSM (variable length subnet masks) uses subnets of different sizes so that each department gets about what it needs.
Aggregation (supernetting, route summarisation) replaces several prefixes by one that covers exactly the same addresses.
Longest prefix match. A router's forwarding table has entries prefix/length → next hop. A destination address may match several entries; the router chooses the matching entry with the longest prefix (the most specific route). The default route 0.0.0.0/0 matches everything and has the lowest priority.
How it works
Computing the block of an address
Network, broadcast and hosts of 172.16.37.5/20: start
Computed by a script, not typed| quantity | dotted decimal | binary |
|---|---|---|
| address | ||
| mask | ||
| network address (address AND mask) | ||
| broadcast (network OR NOT mask) | ||
| first host | ||
| last host | ||
| number of hosts |
Step 0
Address 172.16.37.5/20.
For 172.16.37.5/20: the mask has ones: 255.255.240.0. ANDing with the third byte and gives , so the network is 172.16.32.0. Setting the host bits to one gives the broadcast 172.16.47.255. There are addresses and hosts.
Network, broadcast and hosts of 192.168.10.77/26: start
Computed by a script, not typed| quantity | dotted decimal | binary |
|---|---|---|
| address | ||
| mask | ||
| network address (address AND mask) | ||
| broadcast (network OR NOT mask) | ||
| first host | ||
| last host | ||
| number of hosts |
Step 0
Address 192.168.10.77/26.
For 192.168.10.77/26 the block size is ; the interesting octet is the last: the networks start at and lies in the block starting at : network 192.168.10.64, broadcast 192.168.10.127, hosts.
Shortcut for the interesting octet: block size (mask octet); the network address is the largest multiple of the block size not exceeding the address octet.
Splitting a block into subnets
Borrowing bits from a /24 gives:
Splitting a /24 block: prefix length, subnets, hosts: start
Computed by a script, not typed| prefix | mask | subnets of the /24 | addresses per subnet | usable hosts per subnet |
|---|---|---|---|---|
| /24 | ||||
| /25 | ||||
| /26 | ||||
| /27 | ||||
| /28 | ||||
| /29 | ||||
| /30 |
Step 0
Borrowing b bits from the host part gives 2^b subnets; each has 2^(32 - n) addresses.
To cut 192.168.10.0/24 into equal subnets borrow bits:
192.168.10.0/24 cut into 4 equal subnets: start
Computed by a script, not typed| subnet | network | usable hosts | broadcast |
|---|---|---|---|
| subnet 1 | |||
| subnet 2 | |||
| subnet 3 | |||
| subnet 4 |
Step 0
Borrowing 2 host bits gives 4 subnets of 64 addresses (62 usable).
Each subnet has addresses ( usable). To serve hosts the prefix must satisfy ; the largest suitable prefix is .
VLSM
An office network 192.168.1.0/24 needs subnets for , , and hosts. Allocate the largest first, each block aligned to its own size:
VLSM: subnets for 100, 50, 25 and 10 hosts inside 192.168.1.0/24: start
Computed by a script, not typed| requirement | prefix | addresses | subnet | usable hosts |
|---|---|---|---|---|
| 100 hosts | ||||
| 50 hosts | ||||
| 25 hosts | ||||
| 10 hosts |
Step 0
Variable length subnet masks: allocate the largest request first so that every block stays aligned. The blocks use 128 + 64 + 32 + 16 = 240 of the 256 addresses.
hosts need a /25 ( usable), a /26 (), a /27 (), a /28 (). They occupy of addresses, leaving 192.168.1.240/28 free. Allocating the small ones first would break alignment and may not fit.
Aggregation
Route aggregation (supernetting): start
Computed by a script, not typed| case | prefixes | after aggregation | routes |
|---|---|---|---|
| four contiguous /24 blocks | |||
| two blocks that are adjacent but not aligned | |||
| a block and its more specific | |||
| two /25 halves |
Step 0
Aggregation replaces several prefixes by one that covers exactly the same addresses.
Four consecutive /24 blocks 200.1.0.0 to 200.1.3.0 combine into 200.1.0.0/22, because the first block starts at a multiple of (third octet , a multiple of ) and they are adjacent. The blocks 200.1.1.0/24 and 200.1.2.0/24 are adjacent but cannot be merged into one prefix: the first is not aligned to . A block already covered by a shorter prefix (10.1.0.0/16 inside 10.0.0.0/8) can be dropped from the advertisement when it has the same next hop.
Longest prefix match
Longest prefix match in a forwarding table: start
Computed by a script, not typed| destination | matching entries | chosen entry → next hop |
|---|---|---|
| 10.1.2.200 | ||
| 10.1.2.5 | ||
| 10.1.9.9 | ||
| 10.200.0.1 | ||
| 192.168.0.1 |
Step 0
Forwarding table: 0.0.0.0/0 → R0 (default), 10.0.0.0/8 → R1, 10.1.0.0/16 → R2, 10.1.2.0/24 → R3, 10.1.2.128/25 → R4. A router picks, among all matching prefixes, the one with the most bits.
The table has the default route and four nested prefixes. The destination 10.1.2.200 matches all five; the /25 is the most specific, so it is used. 10.1.2.5 is not in 10.1.2.128/25 and falls to the /24. 192.168.0.1 matches only the default route.
Worked examples
EX 1Hosts in a block
Easy200.10.20.0/22 has addresses, so usable hosts. A /28 has , a /30 has (used on point-to-point links between routers), a /24 has .
EX 2Network address
Medium130.50.77.200/18: the mask is 255.255.192.0; the third octet AND gives . Network 130.50.64.0, broadcast 130.50.127.255 (the block size in the third octet is , so the third octet runs from to ).
EX 3Number of subnets
MediumA /24 split into subnets of /27: subnets, each with addresses and hosts. The fourth octets of the networks are .
EX 4Typical questions
GATE level(a) "Which mask gives at least hosts per subnet?" , so host bits, /23, 255.255.254.0. (b) "Smallest block for router interfaces plus network and broadcast?" /30. (c) "Are 10.1.4.0/24 and 10.1.5.0/24 summarised by 10.1.4.0/23?" Yes: aligned to (third octet is even) and adjacent. (d) "Is 10.1.5.0/24 and 10.1.6.0/24 summarised by a /23?" No: the first block's third octet is odd. (e) "The router has routes /16 and /24 that match; which is used?" The /24.
Cheat box
Cheat box
- Block
a.b.c.d/n: addresses, hosts; mask ones; network AND, broadcast OR with the inverted mask. - Block size in the interesting octet ; networks at multiples of it.
- Borrow bits: subnets of prefix .
- VLSM: largest request first, aligned.
- Aggregate only adjacent blocks of equal size where the first is aligned to twice the size.
- Forwarding: longest prefix match; default route
0.0.0.0/0.
Traps and GATE patterns
Connections
Across subjects
CIDR keeps routing tables short by aggregating prefixes (distance vector routing, link state routing). Private blocks and NAT save addresses (NAT). The IP header and fragmentation are on the next pages (fragmentation). Longest prefix match is a search in a binary trie of address bits, a tree like the ones in binary trees.
PYQs
14 previous year questions from your book. I re-solved each one myself (14 by running or simulating, 0 by reasoning only); the book's key is shown next to my answer. All PYQs
If an IP network uses a subnet mask of 255.255.240.0, the maximum number of IP addresses that can be assigned to network interfaces is ______. (answer in integer)
An ISP having an address block 202.16.0.0/15 assigns a block of 6000 IP addresses to a client using the Classless Internet Domain Routing (CIDR) supernetting approach. Which of the following address blocks can be assigned by the ISP?
- (a)202.16.0.0/19
- (b)202.17.64.0/19
- (c)202.16.32.0/19
- (d)202.17.24.0/19
A packet with the destination IP address 145.36.109.70 arrives at a router whose routing table is shown. Which interface will the packet be forwarded to? Subnet Address Subnet Mask (in CIDR notation) Interface 145.36.0.0 /16 E1 145.36.128.0 /17 E2 145.36.64.0 /18 E3 145.36.255.0 /24 E4 Default -- E5
- (a)E3
- (b)E1
- (c)E2
- (d)E5
Which one of the following CIDR prefixes exactly represents the range of IP address 10.12.2.0 to 10.12.3.255?
- (a)10.12.2.0/24
- (b)10.12.2.0/22
- (c)10.12.0.0/22
- (d)10.12.2.0/23
Consider the entries shown below in the forwarding table of an IP router. Each entry consists of an IP prefix and the corresponding next hop router for packets whose destination IP address matches the prefix. The notation "/N" in a prefix indicates a subnet mask with the most significant N bits set to 1. Prefix Next hop router 10.1.1.0/24 R1 10.1.1.128/25 R2 10.1.1.64/26 R3 10.1.1.192/26 R4 This router forwards 20 packets each to 5 hosts. The IP addresses of the hosts are 10.1.1.16, 10.1.1.72, 10.1.1.132, 10.1.1.191, and 10.1.1.205. The number of packets forwarded via the next hop router R2 is ________. COMPUTER NETWORK
The forwarding table of a router is shown below: Subnet Number Subnet mask Interface ID 200.150.0.0 255.250.0.0 1 200.150.64.0 255.255.224.0 2 200.150.68.0 255.255.255.0 3 200.150.68.64 255.255.255.224 4 Default 0 A packet addressed to a destination address 200.150.68.118 arrives at the router. It will be forwarded to the interface with ID ________.
Consider the routing table of an organization's router shown below: Subnet number Subnet mask Next hop 12.20.164.0 255.255.252.0 R1 12.20.170.0 255.255.254.0 R2 12.20.168.0 255.255.254.0 Interface 0 12.20.166.0 255.255.254.0 Interface 1 default R3 Which of the following prefixes in CIDR notation can be collectively used to correctly aggregate all of the subnets in the routing table?
- (a)12.20.164.0/20
- (b)12.20.164.0/22
- (c)12.20.164.0/21
- (d)12.20.168.0/22
An organization requires a range of IP addresses to assign one to each of its 1500 computers. The organization has approached an Internet Service Provider (ISP) for this task. The ISP uses CIDR and serves the requests from the available IP address space 202.61.0.0/17. The ISP wants to assign an address space to the organization which will minimize the number of routing entries in the ISP's router using route aggregation. Which of the following address spaces are potential candidates from which the ISP can allot any one to the organization? I. 202.61.84.0/21 II. 202.61.104.0/21 III. 202.61.64.0/21 IV. 202.61.144.0/21
- (a)I and IV only
- (b)III and IV only
- (c)I and II only
- (d)II and III only
Consider the following routing table at an IP router: Network No Net Mask Next Hop 128.96 .170 .0 255.255 .254 .0 Interface 0 128.96 .168 .0 255.255 .254 .0 Interface 1 128.96 .166 .0 255.255 .254 .0 R2 128.96 .164 .0 255.255 .252 .0 R3 0.0 .0 .0 Default R4 For each IP address in Group I Identify the correct choice of the next hop from Group II using the entries from the routing table above. Group I Group II i) 128.96 .171 .92
- (a)Interface 0 ii) 128.96 .167 .151
- (b)Interface 1 iii) 128.96 .163 .151
- (c)R2 iv) 128.96 .164 .121
- (d)R3 e) R4 A. i-a, ii-c, iii-e, iv-d B. i-a, ii-d, iii-b, iv-e c, j-b, ii-c, iii-d, iv-e D. j-b, ij-c, iii-e. iv-d
An IP router implementing Classless Interdomain Routing (CIDR) receives a packet with address 131.23.151.76. The router's routing table has the following entries: Prefix Output Interface Identifier 131.16.0/12 3 131.28.0.0/4 5 131.19.0.0/16 2 131.22.0.0/15 1 The identifier of the output interface on which this packet will be forwarded is ______. COMPUTER NETWORK
An Internet Service Provider (ISP) has the following chunk of CIDR-based IP addresses available with it: 245.248.128.0/20. The ISP wants to give half of this chunk of addresses to Organization A, and a quarter to Organization B, while retaining the remaining with itself. Which of the following is a valid allocation of addresses to A and B?
- (a)245.248.136.0/21 and 245.248.128.0/22
- (b)245.248.128.0/21 and 245.248.128.0/22
- (c)245.248.136.0/22 and 245.248.132.0/21
- (d)245.248.136.0/24 and 245.248.132.0/21
If a class B network on the Internet has a subnet mask of 255.255.248.0, what is the maximum number of hosts per subnet?
- (a)1022
- (b)1023
- (c)2046
- (d)2047
The address of a class B host is to be split into subnets with a 6-bit subnet number. What is the maximum number of subnets and the maximum number of hosts in each subnet?
- (a)62 subnets and 262142 hosts
- (b)64 subnets and 262142 hosts
- (c)62 subnets and 1022 hosts
- (d)64 subnets and 1024 hosts
An organization has a class B network and wishes to form subnets for 64 departments. The subnet mask would be:
- (a)255.255.0.0
- (b)255.255.64.0
- (c)255.255.128.0
- (d)255.255.252.0 COMPUTER NETWORK
Self-check
Question 1
Network address and number of hosts of 100.20.30.40/21?
Show answerHide
Third octet , mask octet : AND gives . Network 100.20.24.0, broadcast 100.20.31.255, hosts.
Question 2
How many /30 subnets fit in a /24?
Show answerHide
, each with usable addresses.
Question 3
Aggregate 172.16.8.0/24, 172.16.9.0/24, 172.16.10.0/24, 172.16.11.0/24.
Show answerHide
172.16.8.0/22 (third octets to ; is a multiple of ).
Revision card
One-screen revision
/n: mask ones, addresses, hosts.- Network address AND mask; broadcast sets host bits.
- Subnet: borrow bits subnets. VLSM: largest first.
- Aggregate aligned adjacent blocks; forward by longest prefix.
References
- ·Kurose, Ross, Computer Networking: A Top-Down Approach (8th edition), Chapter 4, Section 4.3.3 (Classless interdomain routing)
- ·Tanenbaum, Wetherall, Computer Networks (5th edition), Chapter 5, Section 5.6.2 (Subnets, CIDR, classful and special addressing)
- ·Forouzan, Data Communications and Networking (5th edition), Chapter 19, Section 19.2 (Classless addressing)
Verification
scripts/enum-checks/cn_net_check.py against Python's ipaddress module: network, broadcast, mask and host counts on 5000 random address/prefix pairs; splitting a block into 2^k subnets equals ip_network.subnets on 500 random blocks; VLSM allocations on 1000 random request lists are aligned, disjoint, inside the block, large enough and the smallest block that suffices (largest-first allocation never failed when the block sizes summed to at most the block); aggregation equals ipaddress.collapse_addresses on 1500 random sets of prefixes (the rule: merge two blocks of equal size that are adjacent and whose first block is aligned to twice the size; drop blocks covered by another); longest prefix match equals a brute-force scan on 1500 random forwarding tables. CONVENTIONS: usable hosts 2^(32-n) - 2 (the textbook rule; /31 point-to-point links (RFC 3021) and /32 host routes are exceptions mentioned but not computed); subnets with all-zeros and all-ones subnet bits are allowed (modern CIDR); older books exclude them, which changes 'number of subnets' answers by 2: exam questions state which they assume. The remark that longest prefix match is a search in a binary trie is an analogy, not a claim about router hardware. Textbook chapter references are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (CRC remainders, binomial tail, checksums); long C programs were not re-read line by line (they are compiled and compared by npm run verify:c, and their printed outputs were checked against the prose). No defect found. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)