Introduction
Classful addressing gave every network a fixed size: , or 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 bits are the network prefix and the remaining 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
- IPv4 Addressing and Header: 32-bit addresses, dotted decimal, classes and special addresses.
Core concepts
Prefix, mask and block
| Quantity | For a.b.c.d/n |
|---|---|
| Mask | ones followed by zeros; /20 is 255.255.240.0 |
| Block size | addresses |
| Network address | address AND mask (host bits 0) |
| Directed broadcast address | For a conventional broadcast subnet with : 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 addresses | 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 |
| Alignment | The 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 .
Subnetting
Splitting a /n block by taking more prefix bits gives subnets of size . For conventional broadcast subnets with at least two host bits, each has 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)
blocks of the same size 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 matches entry when the first bits of and agree. Of all matching entries the router uses the one with the largest ; 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.
| Need | Smallest block | Usable | Subnet | Range | Broadcast |
|---|---|---|---|---|---|
| 100 | /25 (128) | 126 | 198.51.100.0/25 | .0 to .127 | .127 |
| 50 | /26 (64) | 62 | 198.51.100.128/26 | .128 to .191 | .191 |
| 25 | /27 (32) | 30 | 198.51.100.192/27 | .192 to .223 | .223 |
| 2 | /30 (4) | 2 | 198.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.

Mathematical explanation: bit-level reasoning
For address and prefix length , with , 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 . 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:
In the byte where the prefix ends, with prefix bits in that byte, the network byte is the address byte rounded down to a multiple of .
Number of subnets and hosts from a mask. If the original block is /n and the subnet mask is /m, there are subnets. Each conventional broadcast subnet with has 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 , each /m, aggregate to /(m - k) if and only if for all and is a multiple of .
Worked examples
Example 1: one address, its block
172.21.147.200/20. The prefix ends 4 bits into the third byte; rounded down to a multiple of 16 is 144.
| Item | Value |
|---|---|
| Mask | 255.255.240.0 |
| Network | 172.21.144.0 |
| Broadcast | 172.21.159.255 (144 + 15 = 159) |
| Usable range | 172.21.144.1 to 172.21.159.254 |
| Usable hosts |
Example 2: subnets from a mask
The block 130.50.0.0/16 is subnetted with mask 255.255.252.0 (/22): subnets, each with 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
| Entry | Interface |
|---|---|
| 10.10.0.0/16 | if0 |
| 10.10.64.0/18 | if1 |
| 10.10.72.0/21 | if2 |
| 0.0.0.0/0 | if3 |
| Destination | Matching entries | Chosen |
|---|---|---|
| 10.10.75.1 | /16, /18, /21, /0 | if2 (75 is in 72 to 79) |
| 10.10.100.5 | /16, /18, /0 | if1 (100 is in 64 to 127, not 72 to 79) |
| 10.10.200.9 | /16, /0 | if0 |
| 10.11.0.1 | /0 | if3 |

Example 5: how many addresses
200.10.64.0/18 holds 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.
| Address | Usable host in the same subnet? |
|---|---|
| 10.1.38.200 | Yes |
| 10.1.40.1 | No: 40 is outside 36 to 39 |
| 10.1.39.255 | No: the broadcast address |
| 10.1.36.0 | No: the network address |
| 10.1.37.255 | Yes: only the first and last addresses of the whole /22 are reserved |
| 10.1.38.0 | Yes, 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 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/29exists, but.40/28does 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 ." That rule excluded all-zeros and all-ones subnets in old classful practice; with CIDR all 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 for the prefix base. The last address is a directed broadcast only for a conventional broadcast subnet with ; /31 point-to-point links have two endpoints and no directed broadcast, while /32 denotes a single host.
- Counts. subnets; each conventional broadcast subnet with has 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
- A. S. Tanenbaum, D. J. Wetherall, Computer Networks, 5th ed., Pearson, 2011: Section 5.6.2 (IP Addresses).
- J. F. Kurose, K. W. Ross, Computer Networking: A Top-Down Approach, 8th ed., Pearson, 2021: Section 4.3.2 (IPv4 Addressing).
- B. A. Forouzan, Data Communications and Networking, 5th ed., McGraw-Hill, 2013: Chapter 18 (Introduction to Network Layer).
- 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).
- 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).