Kahibaro
Discord Login Register

7.5 CIDR

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 maskBinary mask (first bits)Prefix
255.0.0.011111111.00000000.00000000.00000000/8
255.255.0.011111111.11111111.00000000.00000000/16
255.255.255.011111111.11111111.11111111.00000000/24
255.255.255.12811111111.11111111.11111111.10000000/25
255.255.255.19211111111.11111111.11111111.11000000/26
255.255.255.24011111111.11111111.11111111.11110000/28

In CIDR notation, you always write an IP address, a slash, and the prefix length, for example:

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:

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:

CIDRHost bitsTotal addressesUsable hosts (typical)
/248$2^8 = 256$254
/257$2^7 = 128$126
/266$2^6 = 64$62
/275$2^5 = 32$30
/284$2^4 = 16$14
/293$2^3 = 8$6
/302$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:

  1. Find how many host bits are in the last octet that contains part of the network.
  2. The block size in that octet is $2^{\text{host\_bits\_in\_that\_octet}}$.

For example, consider 192.168.10.0/26.

So the ranges in the fourth octet are:

Because the network is 192.168.10.0/26:

Another example is 192.168.10.128/25.

The ranges in the fourth octet are:

The network 192.168.10.128/25 covers:

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:

  1. Write 32 bits.
  2. Fill the first $n$ bits with 1, where $n$ is the prefix length.
  3. Fill the remaining bits with 0.
  4. Group the bits into four sets of 8 and convert to decimal.

To find the prefix from a mask:

  1. Convert each octet to binary.
  2. Count the total number of 1 bits from the left until you reach the first 0.
  3. That count is the prefix length.

Some common conversions are:

PrefixSubnet mask
/8255.0.0.0
/16255.255.0.0
/24255.255.255.0
/25255.255.255.128
/26255.255.255.192
/27255.255.255.224
/28255.255.255.240
/29255.255.255.248
/30255.255.255.252

To get the number of addresses from a prefix $/n$:

  1. Host bits: $h = 32 - n$
  2. Total addresses: $2^h$
  3. 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:

All of these share the same first 22 bits. They can be combined into a single summary:

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:

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.

Views: 44

Comments

Please login to add a comment.

Don't have an account? Register now!