How to convert CIDR Notation to IP Address Range Manually
Though there are lot of online tools to convert CIDR notation into IP address range but its always good to learn how the Host IP address range is actually calculated.
Let us take below example of a CIDR notation.
As we know the number after the / is a short hand way to write the subnet mask. Subnet mask helps us find the bits reserved for the network part and the bits reserved for the hosts part.
12 here means that first 12 bits in the binary format of IP address are reserved for the network part and last 20 are reserved for the hosts and hence can be used to find the usable IP address range.
To find the first IP address in the range, we will consider only the first 12 binary bits of the CIDR Notation and rest all will be made zero. we can also call this step as “cleaning” the CIDR notation as we are getting rid of unwanted bits in the given CIDR notation.
In this example 184.108.40.206 , the last octets will have all zeroes. So cleaned CIDR Notation will be
The second octet has conflicting bits i.e. its first 4 bits are for the network part and last 4 bits are for the Host part.
58 in binary is
0 0 1 1 1 0 1 0
As only the first 4 binary bits are reserved for the network part, we will make all following binary bits as zero.
0 0 1 1 0 0 0 0
which when converted into decimal is 48 that makes our clean CIDR notation as 220.127.116.11/12
So our initial given CIDR notation of 18.104.22.168/12 should have been actually written as 22.214.171.124/12 and that’s why we called the last step as cleaning the CIDR notation.
Now to calculate the IP addresses in this network , we will use the last 20 bits reserved for the Hosts IP range and start by making the right most bit as 1 till we make all bits from right to left as 1.
So the first IP address will have 32nd bit as 1 and that gives us 126.96.36.199 and last last IP address will have all binary bits that are reserved for Host IP address (i.e. last 20 binary bits in this example) as 1.
This means that our last IP address will be
as last two octets will have all 1's.
Now let us calculate the second octet of the last IP address. To find that, we will have to make last 4 bits of this octet as 1.
48 when written in binary format is
0 0 1 1 0 0 0 0
last 4 bits in this octet of last IP address will be 1, so second octet will be
0 0 1 1 1 1 1 1
which when converted into decimal is 63.
So our last IP address will be 188.8.131.52