Introduction

Classful addressing gave every network a fixed size: 2242^{24}, 2162^{16} or 282^8 addresses. An organisation needing 2000 addresses had to take a class B block of 65,536 or several class C blocks, and every class C block was a separate entry in the Internet's routing tables. Classless Inter-Domain Routing (CIDR) removes the classes: a block is written a.b.c.d/n, meaning its first nn bits are the network prefix and the remaining 32−n32 - n bits number the addresses inside it. Blocks of any power-of-two size can be allocated, split into subnets, and merged again into larger aggregates for routing.

Routers then forward by longest-prefix match: among all table entries whose prefix matches the destination, use the most specific one. Subnetting and forwarding calculations reduce to bit operations on the 32-bit address: AND with the mask, OR with its complement, and counting bits.

Prerequisites

Core concepts

Prefix, mask and block

QuantityFor a.b.c.d/n
Masknn ones followed by 32−n32 - n zeros; /20 is 255.255.240.0
Block size232−n2^{32 - n} addresses
Network addressaddress AND mask (host bits 0)
Directed broadcast addressFor a conventional broadcast subnet with n≤30n\le30: address OR (NOT mask), host bits 1; /31 point-to-point links and /32 host routes have no separate subnet-directed broadcast address
Usable host addresses232−n−22^{32-n}-2 for conventional broadcast subnets with at least two host bits; /31 point-to-point links use both addresses as endpoints (RFC 3021); /32 denotes one address/host route
AlignmentThe network address is a multiple of the block size

A mask must be contiguous ones then zeros; 255.255.0.255 is not a mask. The byte where the prefix ends is the only one needing arithmetic: in /20 the third byte keeps its top 4 bits, so block boundaries in that byte fall at multiples of 28−4=162^{8 - 4} = 16.

Subnetting

Splitting a /n block by taking ss more prefix bits gives 2s2^s subnets of size 232−n−s2^{32 - n - s}. For conventional broadcast subnets with at least two host bits, each has 232−n−s−22^{32 - n - s} - 2 usable host addresses; /31 point-to-point links use both addresses as endpoints (RFC 3021), while /32 denotes one address/host route. With variable-length subnet masks (VLSM), the subnets may have different sizes: give each need the smallest block with enough usable addresses, and allocate the largest blocks first so that every block starts at a multiple of its own size.

Aggregation (supernetting)

2k2^k blocks of the same size /m/m can be written as one /(m - k) exactly when they are contiguous and the first is aligned to a multiple of the combined size. A provider that owns 200.30.8.0/22 advertises one route for all four /24 blocks inside it.

Longest-prefix match

A destination dd matches entry p/np/n when the first nn bits of dd and pp agree. Of all matching entries the router uses the one with the largest nn; the default route 0.0.0.0/0 matches everything and is used only when nothing else does. This is what lets a more specific route (a customer that moved to another provider) override an aggregate.

How it works: dividing a block with VLSM

An organisation owns 198.51.100.0/24 and needs subnets for LANs of 100, 50 and 25 hosts and one point-to-point link (2 hosts). This worked plan assumes conventional /30 addressing for that link, rather than RFC 3021 /31 support; "smallest block" is relative to that assumption. With /31 support, two addresses suffice for the link.

NeedSmallest blockUsableSubnetRangeBroadcast
100/25 (128)126198.51.100.0/25.0 to .127.127
50/26 (64)62198.51.100.128/26.128 to .191.191
25/27 (32)30198.51.100.192/27.192 to .223.223
2/30 (4)2198.51.100.224/30.224 to .227.227

The addresses .228 to .255 (28 addresses) remain free, for example as 198.51.100.228/30, .232/29 and .240/28. A LAN of 126 hosts would still fit a /25; one of 127 would need a /24.

An address line from 198.51.100.0 to 198.51.100.255 divided into consecutive blocks drawn to scale: .0/25 covering .0 to .127 labelled "100 hosts, 126 usable", .128/26 covering .128 to .191 labelled "50 hosts, 62 usable", .192/27 covering .192 to .223 labelled "25 hosts, 30 usable", .224/30 covering .224 to .227 labelled "link, 2 usable", and a hatched free region .228 to .255. Each block's network and broadcast addresses are marked at its two ends.
Figure 1. VLSM split of 198.51.100.0/24: /25, /26, /27 and /30 blocks starting at .0, .128, .192 and .224, with .228 to .255 left free.

Mathematical explanation: bit-level reasoning

For address AA and prefix length 0≤n≤320\le n\le32, with B=232−nB = 2^{32 - n}, the network value is the prefix base and the last address is the upper end of the block. That last address is the directed broadcast only for a conventional broadcast subnet with n≤30n\le30. Under RFC 3021, a /31 point-to-point link uses both addresses as endpoints and has no directed broadcast address; /32 denotes a single host address, not a separate network/broadcast pair:

network=B⌊AB⌋,last address=network+B−1.\text{network} = B \left\lfloor \frac{A}{B} \right\rfloor, \qquad \text{last address} = \text{network} + B - 1 .

In the byte where the prefix ends, with jj prefix bits in that byte, the network byte is the address byte rounded down to a multiple of 28−j2^{8 - j}.

Number of subnets and hosts from a mask. If the original block is /n and the subnet mask is /m, there are 2m−n2^{m - n} subnets. Each conventional broadcast subnet with m≤30m\le30 has 232−m−22^{32 - m} - 2 usable host addresses; /31 point-to-point links use both addresses as endpoints (RFC 3021), while /32 denotes one address/host route.

Aggregation test. Blocks N1<N2<⋯<N2kN_1 < N_2 < \cdots < N_{2^k}, each /m, aggregate to /(m - k) if and only if Ni+1=Ni+232−mN_{i+1} = N_i + 2^{32 - m} for all ii and N1N_1 is a multiple of 232−m+k2^{32 - m + k}.

Worked examples

Example 1: one address, its block

172.21.147.200/20. The prefix ends 4 bits into the third byte; 147147 rounded down to a multiple of 16 is 144.

ItemValue
Mask255.255.240.0
Network172.21.144.0
Broadcast172.21.159.255 (144 + 15 = 159)
Usable range172.21.144.1 to 172.21.159.254
Usable hosts212−2=40942^{12} - 2 = 4094

Example 2: subnets from a mask

The block 130.50.0.0/16 is subnetted with mask 255.255.252.0 (/22): 222−16=642^{22 - 16} = 64 subnets, each with 210−2=10222^{10} - 2 = 1022 usable hosts.

Example 3: aggregation

200.30.8.0/24, 200.30.9.0/24, 200.30.10.0/24 and 200.30.11.0/24 are contiguous, and 8 is a multiple of 4, so they aggregate to 200.30.8.0/22. The four blocks starting at 9, 10, 11 and 12 are contiguous too, but 9 is not a multiple of 4; the shortest exact cover is 200.30.9.0/24, 200.30.10.0/23 and 200.30.12.0/24, three routes.

Example 4: longest-prefix match

EntryInterface
10.10.0.0/16if0
10.10.64.0/18if1
10.10.72.0/21if2
0.0.0.0/0if3
DestinationMatching entriesChosen
10.10.75.1/16, /18, /21, /0if2 (75 is in 72 to 79)
10.10.100.5/16, /18, /0if1 (100 is in 64 to 127, not 72 to 79)
10.10.200.9/16, /0if0
10.11.0.1/0if3
Top: four /24 blocks 200.30.8.0, .9.0, .10.0 and .11.0 drawn as adjacent boxes merging into one box 200.30.8.0/22; beneath, the misaligned set .9.0 to .12.0 drawn as three boxes .9.0/24, .10.0/23 and .12.0/24. Bottom: the forwarding table 10.10.0.0/16 if0, 10.10.64.0/18 if1, 10.10.72.0/21 if2, 0.0.0.0/0 if3 drawn as nested ranges on the third byte (0 to 255, 64 to 127, 72 to 79), with destinations 10.10.75.1, 10.10.100.5, 10.10.200.9 and 10.11.0.1 as arrows landing on if2, if1, if0 and if3.
Figure 2. Aggregation and longest-prefix match: four aligned /24 blocks become 200.30.8.0/22 while the misaligned set needs three routes, and nested prefixes /16, /18, /21 send 10.10.75.1, 10.10.100.5 and 10.10.200.9 to if2, if1 and if0.

Example 5: how many addresses

200.10.64.0/18 holds 214=16,3842^{14} = 16{,}384 addresses, from 200.10.64.0 to 200.10.127.255.

Example 6: same subnet, and real host addresses

Host 10.1.37.18/22 is in 10.1.36.0/22 (37 rounded down to a multiple of 4 is 36), with broadcast address 10.1.39.255.

AddressUsable host in the same subnet?
10.1.38.200Yes
10.1.40.1No: 40 is outside 36 to 39
10.1.39.255No: the broadcast address
10.1.36.0No: the network address
10.1.37.255Yes: only the first and last addresses of the whole /22 are reserved
10.1.38.0Yes, for the same reason

Example 7: the smallest block holding two addresses

192.168.10.5 and 192.168.13.200 agree in their first two bytes; in the third byte, 10 = 00001010 and 13 = 00001101 share their first five bits. The common prefix is 16+5=2116 + 5 = 21 bits, so the smallest block containing both is 192.168.8.0/21, from 192.168.8.0 to 192.168.15.255 (2048 addresses).

Example 8: what is left after a VLSM plan

After the plan in "How it works", 28 addresses (.228 to .255) are free, yet no /27 (30 hosts) can be created: the only /27 boundary in that range is .224, and .224 to .227 is in use. The largest new subnet is the /28 at .240 (14 usable hosts); the free /29 blocks are .232, .240 and .248 (the last two together are that /28).

Important properties and observations

  • Blocks are powers of two and aligned. A "block" of 48 addresses or one starting at .40 with size 16 is not a CIDR block; .40 is a multiple of 8, so .40/29 exists, but .40/28 does not.
  • Classes no longer matter. A /20 inside old class B space and a /20 inside old class C space are handled the same way.
  • More specific routes win. Aggregates and exceptions coexist in one table.
  • Subnetting need not be visible outside. If only the aggregate is advertised, external routers need not learn the internal subnets; more-specific routes may also be advertised.

Common misconceptions.

  • "Usable hosts equal the block size." For conventional broadcast subnets with at least two host bits, subtract the network and broadcast addresses; /31 point-to-point links use both addresses as endpoints (RFC 3021), while /32 denotes one address/host route.
  • "The first matching entry is used." The longest matching prefix is used, regardless of table order.
  • "Any contiguous blocks aggregate." They must also be aligned to the combined size.
  • "Subnet count is 2s−22^s - 2." That rule excluded all-zeros and all-ones subnets in old classful practice; with CIDR all 2s2^s are usable unless a question says otherwise.

GATE examination perspective

  • Network and directed broadcast. Find the byte where the prefix ends; round down to a multiple of 28−j2^{8-j} for the prefix base. The last address is a directed broadcast only for a conventional broadcast subnet with n≤30n\le30; /31 point-to-point links have two endpoints and no directed broadcast, while /32 denotes a single host.
  • Counts. 2m−n2^{m - n} subnets; each conventional broadcast subnet with m≤30m\le30 has 232−m−22^{32 - m} - 2 usable hosts. /31 point-to-point links have two endpoints; /32 denotes one address/host route.
  • VLSM. Largest first; each block aligned to its size.
  • Aggregation. Contiguous and aligned, or not one prefix.
  • Longest-prefix match. Check every entry; the default route is the last resort.
  • Validity of a mask or block. Contiguous ones; network address a multiple of the block size.
  • Reserved addresses. In a conventional broadcast subnet with at least two host bits, the first and last addresses are reserved as network and broadcast; an address ending in .0 or .255 inside a larger subnet can be a host (Example 6). /31 point-to-point links use both addresses as endpoints; /32 denotes one address/host route.
  • Free space after allocation. Count aligned blocks, not free addresses (Example 8).

Summary

Sources

  1. A. S. Tanenbaum, D. J. Wetherall, Computer Networks, 5th ed., Pearson, 2011: Section 5.6.2 (IP Addresses).
  2. J. F. Kurose, K. W. Ross, Computer Networking: A Top-Down Approach, 8th ed., Pearson, 2021: Section 4.3.2 (IPv4 Addressing).
  3. B. A. Forouzan, Data Communications and Networking, 5th ed., McGraw-Hill, 2013: Chapter 18 (Introduction to Network Layer).
  4. V. Fuller, T. Li, RFC 4632, Classless Inter-domain Routing (CIDR), The Internet Address Assignment and Aggregation Plan, 2006, Sections 3.1 (Basic Concept and Prefix Notation), 4.1 (Aggregation Efficiency and Limitations) and 5.1 (Rules for Route Advertisement: longest-match forwarding), (consulted 2026-11-11).
  5. A. Retana et al., RFC 3021, Using 31-Bit Prefixes on IPv4 Point-to-Point Links, Sections 2.1 and 2.2.1, (consulted 2026-11-11).

Next steps