The aim of this blog post is to help you understand CIDR notations. The purpose of this blog post is not to understand IP address calculations. Let’s get started.
Let’s take Microsoft Azure as an example, but the same applies on all networks.
When building a VNET in Azure one of the requirements is to specify an IP range for your VNET, for example, I’ll use 10.7.0.0/16 for the purpose of this post. We further segment the IP address name space into Subnets, for example, 10.7.1.0/24, 10.7.2.0/24 and so on. To learn more about Azure Virtual Networks, visit the following Microsoft Learn link – Explore Azure Virtual Networks – Training | Microsoft Learn
The above ranges 10.7.0.0/16, 10.7.1.0/24 and 10.7.2.0/24 are known as CIDR notations.
So why do we use CIDR notations and how do we work them out?
The definition of CIDR notation from Wikipedia: Classless Inter-Domain Routing is a method for allocating IP addresses and for IP routing.
Let’s try to simplify further,
CIDR notation is a convenient way to write subnet masks instead of having to type/write, for example, 255.255.255.0 or any other subnet mask such as 255.255.0.0 etc. Instead you create a CIDR notation as per the examples above.
So what subnet mask does /16, /24, /26 etc refer to and how do we work out the subnet mask by looking at two digit numbers such as /24 /16 and so on? Well, each number refers to a different subnet mask. A few examples below,
/16 refers to: 255.255.0.0
/24 refers to: 255.255.255.0
/26 refers to: 255.255.255.192
To work out CIDR notation, we need to understand that IP’s are structured in numbers of either 0 or 1. Yes, may be confusing but let’s break this down further,
Let’s take subnet mask 255.255.0.0 as an example. IP addresses include 4 octets and each octet (under the hood) makes up 8 bits, so the above mask would look like this in binary,
Because the last two octets are not activated, we leave them as zero’s.
So how do we work out the CIDR notation from the above? count the 1’s. We have 8 1’s in the first octet and 8 1’s in the second, so that’s a total of 16, therefore, the CIDR range would be /16
Let’s try another one,
What is the CIDR notation for the above? count the 1’s?
Yes, you got it. It’s /24
You may be thinking how do I work out the number 255 and where does the number 255 come from? Yes we understand that 1 = activated and 0 = not activated, but how do we come to a number of 255?
First of all, we need to understand where 255 comes from and how it’s calculated. To work this out, we need to visit the binary table. The binary table starts with 1 and ends with the number 128 as below,
A task for you, what number do you get if you add all of the numbers above? 255, right?
So if we go back to the example from earlier (see below), 8 1’s in the first octet add up to 255 because we have activated all digits. The digits in the second octet have also been activate which total 255. The third and fourth octets have not been activated, therefore, they remain as zero’s.
The result is a /16 CIDR notation because we add up all the ones from octets one and two.
ok, so you now understand where the number 255 comes from. What about a mask of,
How would you work this out?
We need to revisit the binary table again, I have copied it below,
We use the binary table to retrieve the number of 192. Starting from the left of the binary table, we have 128 and we know that 128 on its own does not make up 192. However, if we add the numbers from the binary table 128 + the next number 64, we get 192, see below.
Therefore, we activate two digits in the fourth octet as per the below.
What is the CIDR notation for the above? add up the 1’s and you get a /26,
8 + 8 + 8 + 2 = 26
First octet: 255 – we add up all numbers from the binary table to get a maximum of 255
Second octet: 255 – we add up all numbers from the binary table to get a maximum of 255
Third octet: – we add up all numbers from the binary table to get a maximum of 255
Fourth octet: 192 – This time we only need to add the first two numbers from the binary table (128 +64), therefore activating two digits 11000000
I hope this helps. If you have any questions/feedback please feel free to comment below. Thank you 🙂