Unless you are an absolute begineer, I will assume that you know what IP addresses(IPV4 specifically) are. For the sake of this article, all we need to know is that IP addresses are 32 bit integer values, grouped into 4 sections of 8 bits each(also known as octate) and represented in binary(dotted-decimal) & decimal(for human readbility purpose) format. IP addresses start from 0.0.0.0(00000000.00000000.00000000.00000000) and go all the way upto 255.255.255.255(11111111.11111111.11111111.11111111).
CIDR notation is a method for allocating IP addresses. Say you want to reserve the following IP address range : 10.10.10.0-10.10.10.255. In total, we have 256 IP addresses. The first & the last IP address in the range are reserved. The first IP address(10.10.10.0) is reserved for identifying the network itself & the last IP address(10.10.10.255) is used as broadcast address. 10.10.10.0/24 is the CIDR notation equivalent of the above range. Lets decipher the CIDR notation & try to understand how 10.10.10.0/24 maps to the above range.
Below is the decimal-dotted representation of the above range:
10.10.10.0 : 00001010.00001010.00001010.00000000 10.10.10.1 : 00001010.00001010.00001010.00000001 10.10.10.2 : 00001010.00001010.00001010.00000010 . . . 10.10.10.255 : 00001010.00001010.00001010.11111111
Notice how the first 24 bits are same across the entire IP range. That’s one way to look at the value 24 i.e. mask-bits tells you the number of bits that remain constant in a given IP range. In more scientific term, 255.255.255.0 is the subnet mask for the above range & in 255.255.255.0 first 24 bits are set to 1.
We can extract the network address from a given ip address by bit &ing the address with its subnet mask. E.g.
00001010.00001010.00001010.00000001 & 11111111.11111111.11111111.00000000 = 00001010.00001010.00001010.00000000(10.10.10.0)
Let’s try again with another example. Suppose we have the following range: 18.104.22.168 - 22.214.171.124. Can you figure out the CIDR notation value just by looking at the range? Here’s a small tip: You can easily calculate the number of address in a given CIDR block by using the following formula : 2 power (address length - prefix length) e.g. 2 power (32 - 24) = 256 IP addresses.
In the above example, we have 32 addresses(0-31). And 32 is 2 power 5. Thus our prefix is 27 and our CIDR notation value is 126.96.36.199/27. 255.255.255.224 is our subnet mask.