CIDR and VLSM Explained: Prefix Math, Allocation and Exam Patterns
Learn how to choose valid prefixes, place unequal subnets without overlap, summarize routes, and apply longest-prefix matching through checked examples.
KnowledgeGate Team
Exam prep & CS education

Students often remember 2^h - 2 but still lose marks because they choose the wrong prefix, start a subnet on an invalid boundary, or allocate smaller networks first. CIDR represents classless blocks and route aggregation. VLSM assigns suitable prefix lengths to networks with different host requirements, while longest-prefix matching chooses the most specific matching route.
1. CIDR and VLSM solve related but different problems
An IPv4 address contains 32 bits. In /n, the value n is the number of network bits, leaving 32 - n host bits. For example, 192.168.10.0/24 has the mask 255.255.255.0, 24 network bits, 8 host bits, and 2^8 = 256 total addresses.
CIDR is classless prefix notation used to represent address blocks and aggregate routes. VLSM is the method of assigning unequal subnet sizes from a larger block. FLSM, by contrast, gives every subnet the same prefix even when their host requirements differ.
The distinction is simple:
CIDR asks, "What block or summarised route does this prefix represent?"
VLSM asks, "Which different-sized prefixes should these LANs receive?"
Use the IP addressing and subnetting worked guide for address structure and equal-size /26 subnetting. Unequal allocation adds descending-demand order, valid-boundary checks, remaining-space checks, aggregation alignment, and route specificity.
2. Prefix arithmetic you need before allocating a block
For a prefix /p, the conventional exam formulas are:
Total addresses
= 2^(32 - p)Usable host addresses
= 2^(32 - p) - 2
The subtraction reserves the network and broadcast addresses. A /31 on a point-to-point link is a special operational case, so follow the convention stated in the question.
Prefix | Total addresses | Conventionally usable | Mask |
|---|---|---|---|
| 256 | 254 |
|
| 128 | 126 |
|
| 64 | 62 |
|
| 32 | 30 |
|
| 16 | 14 |
|
| 8 | 6 |
|
| 4 | 2 |
|
Now check 172.16.35.77/27. The last mask octet is 224, so the block size is 256 - 224 = 32. Valid blocks begin at 0, 32, 64, 96, and so on. Since 77 lies in the 64-95 block, the network is 172.16.35.64, the usable range is 172.16.35.65-172.16.35.94, and the broadcast is 172.16.35.95.
3. Worked VLSM example: divide 10.44.8.0/23 for four LANs

Allocate 10.44.8.0/23 to LAN A with 200 hosts, LAN B with 100, LAN C with 50, and LAN D with 20. The /23 spans 512 addresses from 10.44.8.0 through 10.44.9.255; every LAN needs one contiguous, non-overlapping subnet.
Sort the requirements from largest to smallest: 200, 100, 50, 20. Then choose the smallest block whose conventional usable capacity meets each requirement.
LAN A needs 8 host bits because 2^8 - 2 = 254, giving /24. LAN B needs 7 host bits because 2^7 - 2 = 126, giving /25. LAN C needs 6 host bits because 2^6 - 2 = 62, giving /26. LAN D needs 5 host bits because 2^5 - 2 = 30, giving /27.
Place each subnet on the next valid boundary:
The remaining 10.44.9.224/27 covers 10.44.9.224-10.44.9.255. The allocations consume 256, 128, 64, and 32 addresses respectively, leaving 32; the total is 256 + 128 + 64 + 32 + 32 = 512, so the full /23 is accounted for without overlap.
4. Worked CIDR aggregation and longest-prefix match
Consider four routes: 10.20.0.0/24, 10.20.1.0/24, 10.20.2.0/24, and 10.20.3.0/24. Their third octets are 00000000, 00000001, 00000010, and 00000011. The first six bits match, so 16 fixed bits from 10.20 plus six matching bits give the summary 10.20.0.0/22.
A /22 has mask 255.255.252.0 and covers exactly 10.20.0.0-10.20.3.255. Four consecutive /24 blocks can be summarised this way only when the first block is aligned to a four-block boundary.
Now apply this routing table:
Prefix | Next hop |
|---|---|
| R1 |
| R2 |
| R3 |
| R4 |
The decisions are 10.20.2.200 -> R3, 10.20.2.50 -> R2, 10.20.9.4 -> R1, and 8.8.8.8 -> R4. A router chooses the matching route with the largest prefix length, not the route listed first.

5. Traps that produce plausible but wrong answers
Wrong order: Placing the 20-host LAN first can fragment space needed by the 200-host LAN. Sort by descending host requirement.
Wrong capacity:
2^hcounts every address. For 50 hosts,/27supplies only 30 conventionally usable addresses, so/26with 62 is required.Wrong boundary:
192.168.10.70/26is not a network start./26blocks begin at.0,.64,.128, and.192, so.70is a host inside192.168.10.64/26.Wrong summary or route: Routes must be contiguous, equal-sized, and aligned before aggregation. Forwarding uses the longest matching prefix, not the numerically closest address.
6. How exam questions test CIDR and VLSM
Questions usually ask you to convert a mask and prefix, count addresses, find a network and broadcast, design a VLSM allocation, aggregate routes, or apply longest-prefix matching. Do not assume a fixed weight or frequency.
Use this scratch-work sequence:
Write host needs in descending order.
Choose the smallest sufficient power of two and convert it to a prefix.
Place the block on the next valid boundary.
Write the network and broadcast first, then fill the host range.
Check overlap and remaining space.
Try two quick checks before reading the answers. Can 60 hosts fit in a /27? No, it has only 30 conventionally usable addresses. Do 172.16.4.0/24 through 172.16.7.0/24 aggregate to 172.16.4.0/22? Yes, they are four contiguous /24 blocks aligned at a multiple of four.
KnowledgeGate has over 2,000 Computer Networks questions live in our practice bank. Use the subnetting and IP addressing MCQ guide to turn these checks into targeted practice.
7. Short version and the next practice step
Prefix length fixes the address block size.
CIDR represents and aggregates classless blocks.
VLSM allocates different prefix sizes, largest requirement first.
Longest-prefix matching chooses the most specific route.
Redraw the /23 allocation table from memory. Then change LAN C from 50 to 62 hosts and confirm that it still fits /26. At 63 hosts, /26 is too small, so the allocation must be recomputed with a /25 for that LAN.
For a structured GATE preparation path, continue with GATE Guidance by Sanchit Sir. For broader CS and placement revision, use CS Fundamentals for Placements by Sanchit Sir, or explore the wider GATE course path.
Keep learning
CIDR and VLSM MCQs: 12 Solved Subnetting Questions with Explanations
Solve 12 published CIDR and VLSM questions step by step. Learn prefix conversion, aligned subnet ranges, VLSM allocation and longest-prefix routing.
IP Addressing in Computer Networks: Classes, Subnetting, CIDR, and Worked Examples for GATE
Build IP addressing from its 32-bit foundation through classful ranges, subnetting, VLSM, CIDR aggregation, and longest prefix match with checked examples.
Huffman Coding Explained: Greedy Construction, Prefix Codes and a Worked Example
Build a Huffman tree step by step, derive exact prefix codes, verify the 224-bit weighted cost twice, and learn why the greedy merge is optimal.
Infix, Postfix and Prefix Expressions: Stack Rules, Conversions and Worked Examples
Learn how one expression becomes infix, postfix and prefix form. Follow the operator stack, build the expression tree and evaluate both stack notations safely.





