Table of Contents
Understanding CIDR
Classless Inter‑Domain Routing, or CIDR, is a way to write IP address ranges and subnet masks more flexibly and efficiently than the old classful system. In CIDR, you describe a network using an IP address plus a prefix length, such as 192.168.10.0/24. The prefix length tells you how many bits at the start of the address belong to the network part. CIDR is used everywhere in modern IP addressing, from small home networks to global internet routing.
From Subnet Masks to Prefix Length
In classful addressing, networks were grouped into fixed classes with fixed masks, but CIDR ignores those classes and simply uses a prefix length. The prefix length represents the number of 1 bits in the subnet mask, counted from the left.
For example, the following masks and prefixes match:
| Subnet mask | Binary mask (first bits) | Prefix |
|---|---|---|
| 255.0.0.0 | 11111111.00000000.00000000.00000000 | /8 |
| 255.255.0.0 | 11111111.11111111.00000000.00000000 | /16 |
| 255.255.255.0 | 11111111.11111111.11111111.00000000 | /24 |
| 255.255.255.128 | 11111111.11111111.11111111.10000000 | /25 |
| 255.255.255.192 | 11111111.11111111.11111111.11000000 | /26 |
| 255.255.255.240 | 11111111.11111111.11111111.11110000 | /28 |
In CIDR notation, you always write an IP address, a slash, and the prefix length, for example:
10.0.0.0/8172.16.0.0/16192.168.1.0/24192.168.1.128/25
The IP address in CIDR notation is the network address for that block, not a random host in the range.
Network and Host Bits
In CIDR, the prefix defines the network bits, and the remaining bits are host bits. If you have an IPv4 address, there are always 32 bits in total. If the prefix is /n, then there are $n$ network bits and $32 - n$ host bits.
For example:
/24means 24 network bits and 8 host bits./26means 26 network bits and 6 host bits./30means 30 network bits and 2 host bits.
CIDR does not care whether the address would have been Class A, B, or C. Only the prefix length matters.
Calculating Number of Addresses
Once you know the prefix length, you can calculate how many IP addresses are in that CIDR block. The number of host bits is $h = 32 - \text{prefix}$. The total number of addresses in the block is then $2^h$.
For an IPv4 CIDR block with prefix length $/n$:
- Host bits: $h = 32 - n$
- Total addresses: $2^h$
If you need usable host addresses on a typical IPv4 subnet, you normally subtract the network address and the broadcast address. So the number of usable host addresses is usually $2^h - 2`, except for very small prefixes where special rules may apply.
Some common examples:
| CIDR | Host bits | Total addresses | Usable hosts (typical) |
|---|---|---|---|
| /24 | 8 | $2^8 = 256$ | 254 |
| /25 | 7 | $2^7 = 128$ | 126 |
| /26 | 6 | $2^6 = 64$ | 62 |
| /27 | 5 | $2^5 = 32$ | 30 |
| /28 | 4 | $2^4 = 16$ | 14 |
| /29 | 3 | $2^3 = 8$ | 6 |
| /30 | 2 | $2^2 = 4$ | 2 |
Finding the Network Range from CIDR
When you see a CIDR block, you can determine the network address, broadcast address, and the first and last usable host addresses by looking at the prefix and the remaining host bits.
The size of each block in the last affected octet is determined by the number of host bits in that octet. For IPv4, each octet is 8 bits, so you can look at where the prefix cuts across the octets.
An easy way to think about block size is:
- Find how many host bits are in the last octet that contains part of the network.
- The block size in that octet is $2^{\text{host\_bits\_in\_that\_octet}}$.
For example, consider 192.168.10.0/26.
- Prefix is
/26, so there are $32 - 26 = 6$ host bits total. - The first 24 bits are the first three octets, and the next 2 bits are in the fourth octet.
- That leaves 6 host bits, all in the fourth octet. So the block size in the fourth octet is $2^6 = 64$.
So the ranges in the fourth octet are:
- 0 to 63
- 64 to 127
- 128 to 191
- 192 to 255
Because the network is 192.168.10.0/26:
- Network address:
192.168.10.0 - Broadcast address:
192.168.10.63 - First usable host:
192.168.10.1 - Last usable host:
192.168.10.62
Another example is 192.168.10.128/25.
- Prefix is
/25, so host bits are $32 - 25 = 7`. - The first 24 bits are full octets, plus 1 network bit in the fourth octet, leaving 7 host bits there.
- Block size in the fourth octet is $2^7 = 128$.
The ranges in the fourth octet are:
- 0 to 127
- 128 to 255
The network 192.168.10.128/25 covers:
- Network address:
192.168.10.128 - Broadcast address:
192.168.10.255 - First usable host:
192.168.10.129 - Last usable host:
192.168.10.254
Converting Between CIDR and Subnet Masks
You can move between prefix length and dotted decimal masks by counting bits.
To find the mask from a prefix:
- Write 32 bits.
- Fill the first $n$ bits with 1, where $n$ is the prefix length.
- Fill the remaining bits with 0.
- Group the bits into four sets of 8 and convert to decimal.
To find the prefix from a mask:
- Convert each octet to binary.
- Count the total number of 1 bits from the left until you reach the first 0.
- That count is the prefix length.
Some common conversions are:
| Prefix | Subnet mask |
|---|---|
| /8 | 255.0.0.0 |
| /16 | 255.255.0.0 |
| /24 | 255.255.255.0 |
| /25 | 255.255.255.128 |
| /26 | 255.255.255.192 |
| /27 | 255.255.255.224 |
| /28 | 255.255.255.240 |
| /29 | 255.255.255.248 |
| /30 | 255.255.255.252 |
To get the number of addresses from a prefix $/n$:
- Host bits: $h = 32 - n$
- Total addresses: $2^h$
- Typical usable hosts: $2^h - 2$
CIDR and Route Aggregation
CIDR is not only about local subnetting. It is also very important for aggregation of routes, which is also called route summarization. Instead of announcing many small routes, a router can announce one larger CIDR block that covers them all. This reduces the size of routing tables.
For example, imagine a provider has these networks:
192.168.0.0/24192.168.1.0/24192.168.2.0/24192.168.3.0/24
All of these share the same first 22 bits. They can be combined into a single summary:
192.168.0.0/22
This one route tells others that the provider can reach any address from 192.168.0.0 to 192.168.3.255. Inside its own network the provider can still use the individual /24 networks, but outside, other routers only see the single /22 route.
CIDR allows this type of flexible aggregation because it ignores fixed class boundaries and uses only the prefix length.
CIDR and Classless Addressing
With classful addressing, there were only three main network sizes: Class A, Class B, and Class C. CIDR removed these fixed sizes and allows any prefix from /0 to /32 for IPv4.
Some interesting examples:
/32represents a single IP address, often used for a specific host or a loopback address./31historically had no usable hosts, but some modern systems use it for point to point links where there is no need for broadcast./0would represent the entire IPv4 space, and in routing is known as the default route.
CIDR gives network designers the ability to choose address block sizes that match actual needs instead of being limited by fixed classes. This flexibility is used in subnetting within an organization and also in summarization toward the internet.