CIDR was invented to facilitate better and more efficient allocation of IP addressing and especially IPv4 addresses which started running out pretty fast when the whole Internet accelerated its pace during the last 2-3 decades.
What is Classless Inter-Domain Routing (CIDR)
As you know, an IPv4 address consists of 32 bits and is represented as four octets (1 octet=8 bits). An IP address is divided into a network part (leftmost bits) and a host part (remaining bits after the network part).
Originally, IP addresses were assigned to organizations and ISP networks in bulk and according to the following 3 classes:
- Class A IP range: First 8 bits are the network part and remaining 24 bits are the host part (allowing more than 16 million hosts).
- Class B IP range: First 16 bits are the network part and remaining 16 bits are the host part (allowing 65,535 IP for hosts).
- Class C IP range: First 24 bits are the network part and remaining 8 bits are the host part (allowing 254 IP for hosts).
The above was very inefficient and resulted in a lot of wasted IP addresses. Let’s say an ISP wanted to get 4000 IP addresses to assign to its customers. The ISP was allocated a whole Class B range of 65,535 host IPs although they wanted only 4000. Thus, around 61,000 IP addresses were wasted.
How CIDR is used
CIDR uses variable length subnet mask (VLSM) which is not based on the hard boundaries of the 3 Classes described above.
The subnet mask is what defines the length of the network and host portions of the IP address.
Therefore, instead of having for example 16-bits on the network part (by using the old Class B assignment) you can have for example 20-bits on the network part and thus 12-bits of the remaining length for the host part.
The above example means that you can have 212 = 4096 available IP addresses for Hosts. This means that when an ISP or big enterprise wants to get around 4000 IP addresses (as in our example), it will be allocated a specific subnet range with 20-bits on the network portion and 12-bits on the host portion instead of a whole Class B range.
Assume our fictitious ISP (or big enterprise) is assigned the following IP address range (using CIDR notation):
The above notation means that the Network part is 20 bits (as indicated by the CIDR prefix number /20 at the end of the IP address range). Therefore, the Host part is 32-20 = 12 bits which allows for a total of 212 = 4096 IP addresses for hosts.
Using our example above, the actual usable IP addresses that can be assigned to hosts are always 2 less than the total number of IPs. This is because we don’t use the network address and the broadcast address for hosts.
Therefore, the above ISP or big enterprise could allocate the following IP addresses to hosts:
18.104.22.168 up to 22.214.171.124 for a total of 4094 usable hosts.
CIDR Cheat Sheet
The table below shows a CIDR cheat sheet which you can download also as PDF file at the end of this article:
|CIDR Prefix||Total Host IPs||Usable Host IPs||Netmask||# of subnets relative to Class A,B,C|
- In a /24 CIDR subnet there are a total of 256 host IP addresses but the usable host IPs are 256-2= 254
- In a /30 CIDR subnet there are total of 4 host IPs but the usable host IPs are 4-2=2 . This subnet is usually used in point-to-point link connections (e.g links between routers) where you only need 2 IPs (one on each end of the point-to-point link).
- In a /23 CIDR subnet there are total of 512 host IPs but the usable host IPs are 512-2=510