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

Updated 28 Nov 20265 min read
CIDR and VLSM Explained: Prefix Math, Allocation and Exam Patterns

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.

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

/24

256

254

255.255.255.0

/25

128

126

255.255.255.128

/26

64

62

255.255.255.192

/27

32

30

255.255.255.224

/28

16

14

255.255.255.240

/29

8

6

255.255.255.248

/30

4

2

255.255.255.252

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

VLSM flow allocating 10.44.8.0/23 to four LANs from 200 to 20 hosts with remaining space.

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

10.20.0.0/16

R1

10.20.2.0/24

R2

10.20.2.128/25

R3

0.0.0.0/0

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.

Four /24 blocks sharing six third-octet bits summarise to 10.20.0.0/22, and destination 10.20.2.200 matches 10.20.2.128/25 through R3.

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^h counts every address. For 50 hosts, /27 supplies only 30 conventionally usable addresses, so /26 with 62 is required.

  • Wrong boundary: 192.168.10.70/26 is not a network start. /26 blocks begin at .0, .64, .128, and .192, so .70 is a host inside 192.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:

  1. Write host needs in descending order.

  2. Choose the smallest sufficient power of two and convert it to a prefix.

  3. Place the block on the next valid boundary.

  4. Write the network and broadcast first, then fill the host range.

  5. 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.