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.
CIDR Notation
Assume our fictitious ISP (or big enterprise) is assigned the following IP address range (using CIDR notation):
100.45.48.0 /20
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.
IMPORTANT NOTE
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:
100.45.48.1 up to 100.45.63.254 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 |
/32 | 1 | 1 | 255.255.255.255 | 1/256 C |
/31 | 2 |
O |
255.255.255.254 | 1/128 C |
/30 | 4 | 2 | 255.255.255.252 | 1/64 C |
/29 | 8 | 6 | 255.255.255.248 | 1/32 C |
/28 | 16 | 14 | 255.255.255.240 | 1/16 C |
/27 | 32 | 30 | 255.255.255.224 | 1/8 C |
/26 | 64 | 62 | 255.255.255.192 | 1/4 C |
/25 | 128 | 126 | 255.255.255.128 | 1/2 C |
/24 | 256 | 254 | 255.255.255.0 | 1 C |
/23 | 512 | 510 | 255.255.254.0 | 1/128 B |
/22 | 1,024 | 1,022 | 255.255.252.0 | 1/64 B |
/21 | 2,048 | 2,046 | 255.255.248.0 | 1/32 B |
/20 | 4,096 | 4,094 | 255.255.240.0 | 1/16 B |
/19 | 8,192 | 8,190 | 255.255.224.0 | 1/8 B |
/18 | 16,384 | 16,382 | 255.255.192.0 | ¼ B |
/17 | 32,768 | 32,766 | 255.255.128.0 | ½ B |
/16 | 65,536 | 65,534 | 255.255.0.0 | 1 B |
/15 | 131,072 | 131,070 | 255.254.0.0 | 1/128 A |
/14 | 262,144 | 262,142 | 255.252.0.0 | 1/64 A |
/13 | 524,288 | 524,286 | 255.248.0.0 | 1/32 A |
/12 | 1,048,576 | 1,048,574 | 255.240.0.0 | 1/16 A |
/11 | 2,097,152 | 2,097,150 | 255.224.0.0 | 1/8 A |
/10 | 4,194,304 | 4,194,302 | 255.192.0.0 | 1/4 A |
/9 | 8,388,608 | 8,388,606 | 255.128.0.0 | 1/2 A |
/8 | 16,777,216 | 16,777,214 | 255.0.0.0 | 1 A |
/7 | 33,554,432 | 33,554,430 | 254.0.0.0 | 2 A |
/6 | 67,108,864 | 67,108,862 | 252.0.0.0 | 4 A |
/5 | 134,217,728 | 134,217,726 | 248.0.0.0 | 8 A |
/4 | 268,435,456 | 268,435,454 | 240.0.0.0 | 16 A |
/3 | 536,870,912 | 536,870,910 | 224.0.0.0 | 32 A |
/2 | 1,073,741,824 | 1,073,741,822 | 192.0.0.0 | 64 A |
/1 | 2,147,483,648 | 2,147,483,646 | 128.0.0.0 | 128 A |
/0 | 4,294,967,296 | 4,294,967,294 | 0.0.0.0 | 256 A |
Some Examples
- 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
Related Posts
- Comparison of Fiber Optic vs Copper Ethernet Cables in Networking
- Understanding IP Prefix Lists in TCP/IP Networks (With Cisco Examples)
- The Purpose of Routing Protocols in TCP/IP Networking
- What is a Wildcard Mask – All About Wildcard Masks Used in Networking
- Differences Between Routing, Forwarding, Switching in Networks