Imagine you and your friends are planning to have a big party in your backyard. You need to make sure you have enough space for everyone to sit comfortably.
CIDR stands for Classless Inter-Domain Routing, and it’s like a way to divide up the available space in your backyard so you can plan for your party.
CIDR uses a series of numbers to represent an address range, just like how you might use numbers to represent the length and width of your backyard. For example, if you have a backyard that’s 50 feet wide and 100 feet long, you might say the address range is from 0 feet to 50 feet on the width, and from 0 feet to 100 feet on the length.
Similarly, in CIDR, we use a series of numbers to represent an address range. For example, an IP address range might be represented as 192.168.0.0/24. The number after the slash (/) tells us how many bits in the IP address are used to represent the network part of the address. In this example, the first 24 bits are used to represent the network, and the remaining 8 bits are used to represent individual hosts on the network.
Think of CIDR like a way to divide up your backyard into smaller sections, so you can plan for your party more effectively. By dividing up the address space into smaller ranges, CIDR allows us to more efficiently manage and allocate IP addresses in a network.
CIDR, which stands for Classless Inter-Domain Routing, is an IP addressing scheme that improves the allocation of IP addresses. It replaces the old system based on classes A, B, and C. This scheme also helped greatly extend the life of IPv4 as well as slow the growth of routing tables.
In this article, we’ll explore how CIDR actually works, as well as provide examples to better demonstrate the concepts explained.
Problems with class-based IP addressing#
The old method of IP addressing came with inefficiencies that exhausted the availability of IPv4 addresses faster than it needed to. The classful routing system included classes A, B, and C:
- Class A – Over 16 million host identifiers
- Class B – 65,535 host identifiers
- Class C – 254 host identifiers
The problem would commonly occur when an organization required more than 254 host machines and therefore would no longer fall into class C but rather class B. This means that the organization would use a class B license even though they had far less than 65,535 hosts. Therefore if an organization only required 2,500 hosts, they would be wasting about 63,000 hosts by holding a class B license which would greatly decrease the availability of IPv4 addresses unnecessarily.
How does CIDR work?#
CIDR is based on variable-length subnet masking (VLSM). This allows it to define prefixes of arbitrary lengths making it much more efficient than the old system. CIDR IP addresses are composed of two sets of numbers. The network address is written as a prefix, like you would see a normal IP address (e.g. 192.255.255.255). The second part is the suffix which indicates how many bits are in the entire address (e.g. /12). Putting it together, a CIDR IP address would look like the following:
192.255.255.255/12
The network prefix is also specified as part of the IP address. This varies depending upon the number of bits required. Therefore, taking the example above, we can say that the first 12 bits are the network part of the address while the last 20 bits are for host addresses.
Wikipedia’s IPv4 CIDR blocks table below provides a good overview of how varying address formats render a different number of addresses. Formats are also categorized by typical uses.
CIDR example#
We’ve already covered what a CIDR IP address looks like, now let’s go over a couple of examples that break down their formatting. The CIDR Calculation tool is great if you want to easily determine what IP range a particular CIDR address equates to. Simply enter the CIDR address into the tool and click Calculate. This will return information such as the first IP, last IP, number of hosts and more.
Similarly, you can also convert an IP range to a CIDR. For example, let’s say you wanted the CIDR notation for IP ranges between 192.0.0.0 and 192.0.0.255. You would simply plug these two numbers into the IP Range to CIDR tool and have it return the corresponding CIDR address.
CIDR Length | Mask | # of Networks | # of Hosts |
---|---|---|---|
/1 | 128.0.0.0 | 128 A | 2,147,483,392 |
/2 | 192.0.0.0 | 64 A | 1,073,741,696 |
/3 | 224.0.0.0 | 32 A | 536,870,848 |
/4 | 240.0.0.0 | 16 A | 268,435,424 |
/5 | 248.0.0.0 | 8 A | 134,217,712 |
/6 | 252.0.0.0 | 4 A | 67,108,856 |
/7 | 254.0.0.0 | 2 A | 33,554,428 |
/8 | 255.0.0.0 | 1 A | 16,777,214 |
/9 | 255.128.0.0 | 128 B | 8,388,352 |
/10 | 255.192.0.0 | 64 B | 4,194,176 |
/11 | 255.224.0.0 | 32 B | 2,097,088 |
/12 | 255.240.0.0 | 16 B | 1,048,544 |
/13 | 255.248.0.0 | 8 B | 524,272 |
/14 | 255.252.0.0 | 4 B | 262,136 |
/15 | 255.254.0.0 | 2 B | 131,068 |
/16 | 255.255.0.0 | 1 B | 65,024 |
/17 | 255.255.128.0 | 128 C | 32,512 |
/18 | 255.255.192.0 | 64 C | 16,256 |
/19 | 255.255.224.0 | 32 C | 8,128 |
/20 | 255.255.240.0 | 16 C | 4,064 |
/21 | 255.255.248.0 | 8 C | 2,032 |
/22 | 255.255.252.0 | 4 C | 1,016 |
/23 | 255.255.254.0 | 2 C | 508 |
/24 | 255.255.255.0 | 1 C | 254 |
/25 | 255.255.255.128 | 2 subnets | 124 |
/26 | 255.255.255.192 | 4 subnets | 62 |
/27 | 255.255.255.224 | 8 subnets | 30 |
/28 | 255.255.255.240 | 16 subnets | 14 |
/29 | 255.255.255.248 | 32 subnets | 6 |
/30 | 255.255.255.252 | 64 subnets | 2 |
/31 | 255.255.255.254 | none | none |
/32 | 255.255.255.255 | none | 1 |
Summary#
CIDR is a great way to improve the efficiency of IP address distribution. It was vital with IPv4 as IP addresses were quickly being exhausted. IPv6 is now rolling out and although running out of IP address is now less of a problem, CIDR will continue to be used. Read our IPv6 tutorial guide to learn more about what differences exist in the newest version of the Internet Protocol.