CIDR (Classless Inter-Domain Routing)

1. What is CIDR ?

CIDR (Classless Inter-Domain Routing ) is a method introduced in 1993 by the IETF to improve IPv4 address allocation and reduce IPv4 waste.

It replaced the old classful system, where networks were rigidly defined as:

  • Class A → fixed /8 prefix
  • Class B → fixed /16 prefix
  • Class C → fixed /24 prefix
Diagram showing the evolution of IPv4 addressing, from Class A, B, and C in 1981, to subnetting in 1985, and finally to CIDR in 1993 which allows choosing any prefix length.

Figure 1 – IPv4 evolution: classes, subnetting, CIDR.

Before CIDR, in 1981, IPv4 addresses were assigned to hosts by using three fixed classes, a system that quickly led to significant address waste.

In 1985, Subnetting was introduced, allowing Class A, B, and C networks to be divided into smaller segments. For example, a Class A network could be split into Class B or Class C networks.

However, subnetting still required using the default class-based prefixes of /8, /16, and /24. This meant you still couldn’t choose an arbitrary prefix length.

In 1993, CIDR solved this limitation by removing fixed classes entirely, allowing any prefix length.

2. How CIDR Works ?

To understand CIDR, let’s break it down step by step with a simple example.

In this diagram, we use the network 198.51.100.0/24, which has a subnet mask of 255.255.255.0

An IPv4 address has two parts:

  • Network portion → Identifies the network.
  • Host portion → Identifies devices within that network.

The number after the slash / is called the prefix length.
It tells you how many bits are reserved for the network portion.

For example:

Diagram showing IPv4 address 198.51.100.0/24 and subnet mask 255.255.255.0 in binary, highlighting network portion and host portion.
Figure 2 – IPv4 198.51.100.0/24 with subnet mask, showing network and host bits.

In 198.51.100.0/24, the /24 prefix means that 24 bits are allocated to the network portion, leaving 8 bits for the host portion.

Why CIDR is Powerful

With CIDR, you can adjust the prefix length to fit your network needs.

When you increase the prefix length (for example from /24 to /25, /26, /27…), you are shifting bits from the host portion to the network portion..

  • Those extra network bits let you create more subnets.
  • With fewer host bits, each subnet supports fewer devices.

The Formula for Usable Addresses

To calculate the number of usable host addresses in any subnet, we use:

Formula to calculate usable IP addresses in a subnet.
Figure 3– Formula for usable IP addresses.

Where:

  • n = 32 − prefix length (number of host bits)
  • We subtract 2 for the network and broadcast addresses

Example with /24

Let’s apply the formula to the network 198.51.100.0/24

IPv4 /24 subnet mask with binary notation, network and host bits, and usable address calculation.
Figure 4 – Calculating usable addresses with a /24 subnet mask.

The prefix length is /24.
So:

  • n = 32 − 24 = 8 host bits
  • 2⁸ − 2 = 254 usable hosts

Now let’s see how increasing the prefix length (/25, /26, /27…) changes the number of usable addresses.

Examples of Prefix Length and Usable Addresses

Now, let’s apply the formula step by step for different prefix lengths.

IPv4 /25 subnet mask showing binary notation, network and host bits, and calculation of usable addresses.
Figure 5 – Calculating usable addresses with a /25 subnet mask.

With a /25 prefix, 25 bits are for the network and 7 bits for hosts.
2⁷ − 2 = 126 usable IP addresses.

IPv4 /26 subnet mask with binary notation, network and host bits, and usable address calculation.
Figure 6 – Calculating usable addresses with a /26 subnet mask.

A /26 prefix uses 26 bits for the network, leaving 6 host bits.
2⁶ − 2 = 62 usable IP addresses.

IPv4 /27 subnet mask with binary notation, network and host bits, and usable address calculation.
Figure 7 – Calculating usable addresses with a /27 subnet mask.

Here, /27 leaves 5 host bits.
2⁵ − 2 = 30 usable IP addresses.

IPv4 /28 subnet mask with binary notation, network and host bits, and usable address calculation.
Figure 8 – Calculating usable addresses with a /28 subnet mask.

With /28, only 4 host bits remain.
2⁴ − 2 = 14 usable IP addresses.

IPv4 /29 subnet mask with binary notation, network and host bits, and usable address calculation.
Figure 9 – Calculating usable addresses with a /29 subnet mask.

A /29 leaves 3 host bits.
2³ − 2 = 6 usable IP addresses.

IPv4 /30 subnet mask with binary notation, network and host bits, and usable address calculation.
Figure 10 – Calculating usable addresses with a /30 subnet mask.

With /30, only 2 host bits remain.
2² − 2 = 2 usable IP addresses.

Traditionally used for point-to-point links between two devices, but also valid for very small subnets.

IPv4 /31 subnet mask with binary notation, network and host bits, and usable address calculation.
Figure 11 – Calculating usable addresses with a /31 subnet mask.

A /31 leaves 1 host bit.
Normally, 2¹ − 2 = 0 would give no usable addresses, but RFC 3021 allows 2 usable IPs for point-to-point links.

Both addresses can be assigned since network and broadcast addresses are not required in this context.

This results in exactly 2 usable IP addresses, making /31 a more address-efficient option than /30 for point-to-point connections.

IPv4 /32 subnet mask with binary notation, network and host bits, and usable address calculation.
Figure 12 – Calculating usable addresses with a /32 subnet mask.

With /32, there are 0 host bits.

Normally, applying the formula gives 2⁰ − 2 = −1, which would mean no usable addresses.
This is an exception because /32 represents a single IP address.

It is typically used for loopbacks, host routes, or identifying a specific device.

3. How to Calcule a Subnet ?

Understanding CIDR theory is essential, but for your CCNA exam, you also need to know how to apply it to real subnetting scenarios.

CIDR allows us to take an initial network and divide it into smaller, well-sized networks that match specific needs.

Let’s look at an example question:

Diagram showing subnetting of 198.51.100.0/24 into four networks for Office A (50 hosts), Office B (43 hosts), Office C (59 hosts), and Office D (55 hosts).
Figure 13 – Subnetting 198.51.100.0/24 into four offices.

You are given the network 198.51.100.0/24 and need to create four separate networks for four offices, each with a specific number of hosts.

At this point, you might think:

“That’s a good question, but so far, we’ve only seen how to take bits from the host portion and give them to the network portion to make smaller networks.”

Here’s the important part:
With CIDR, we use that same idea of adjusting the prefix length, but now we have a clear objective:

  1. Make sure each subnet has enough addresses for its hosts.
  2. Avoid wasting addresses by preventing subnets that are larger than necessary.

We will learn exactly how to size subnets with CIDR in the next lesson by using step-by-step examples and a simple, repeatable method.

For now, keep in mind:
CIDR is the tool that lets you precisely adjust the prefix length so you can create multiple subnets that match requirements while reducing address waste.