What's the CIDR notation and how to use it?

What's the CIDR notation and how to use it?

The Classless Inter-Domain Routing (CIDR) notation is a method to define prefixes of arbitrary lengths thus allowing to divide a network into smaller network sections. The general process also called subnetting is useful in many different contexts to help isolate group of hosts together and deal with them easily.

The idea with CIDR is that you can add a specification in the IP address itself as to the number of significant bits that make up the routing or networking portion.

For instance, you could express the idea that IP address 192.168.0.9 is associated with the netmask 255.255.255.0 by using the CIDR notation of 192.168.0.9/24. The second part (24) means that only the first 24 bits of the IP address given are considered significant for the network routing.

Taking the example above, we can say the first 24 bits are the network part of the address while the last 8 bits are for host addresses.

Using CIDR enables interesting possibilities. Let's say you want to combine the address blocks 192.168.0.0/24 and 192.168.1.0/24, meaning the range from 192.168.0.0 to 192.168.1.255. You can reference both blocks with 192.168.0.0/23 using the CIDR notation. This specifies that there are 23 bits used for the network portion that we are referring to.

So the first network (192.168.0.0 ) could be represented in binary as follows:

11000000 10101000 00000000 00000000

While the second network (192.168.1.0) looks like this:

11000000 10101000 00000001 00000000

The CIDR address we specified indicates that the first 23 bits are used for the network block we are referencing. This is equivalent to a netmask of 255.255.254.0, or:

11111111 11111111 11111110 00000000

As you can see, with this block the 24th bit can be either 0 or 1 and it will still match, because the network block only cares about the first 23 digits.

The notation works with both IPv4 and IPv6. In the former case the mask may use up to 32 bits, while with IPv6 the mask allows up to 128 bits.

Basically, CIDR enables great control over addressing continuous blocks of IP addresses. It is also a means to filter or whitelist a set of host addresses.

Get started with 100,000 free lookups: sign up