IP Addressing in Azure | Understanding CIDR and Subnet Mask Representation

When I was new to Infra Domain and had a Non- networking background, I always wondered how IP addressing worked. All those terms like subnetting and CIDR seemed like rocket science to me. So, this article is for those who would like to understand basic IP Addressing concepts, which will be necessary for understanding and implementing Virtual networks in Azure. So, Let’s start with the definition of IP Address, types of IP Address followed by CIDR and Subnet mask representation.

What is an IP Address?

IP stands for Internet Protocol. An IP Address is used as a unique identifier for a resource in a network or an organization. An IP address can be of the type IPV4 or IPV6. We will be discussing only IPv4 addressing in this article. IPv4 is the most widely used IP address across the globe. An IPv4 is a 32-bit address divided into four octets separated by a period (. dot), each octet carrying 8 bits.

Types of IP Address:

Public IP Address: An IP used over the internet, or you can say which is routable over the internet.

Private IP Address: An IP that is used within the private network(Intranet).

Private IP addresses are again divided into 3 different classes as below. I will show you how to calculate the no. of IP Addresses in the coming sections of the article.

. Class A  10.0.0.0/8 — 10.0.0.0 – 10.255.255.255 — Total of  16,777,216 IP Addresses

. Class B 172.16.0.0/12 — 172.16.0.0 – 172.31.255.255 — Total of 1,048,576 IP Addresses

. Class C 192.168.0.0/16 — 192.168.0.0-192.168.255.255 — Total of 65,536 IP Addresses

IP Addressing in Azure | Understanding CIDR and Subnet Mask Representation 1
IP Addressing in Azure | Understanding CIDR and Subnet Mask Representation

CIDR Block and IP address calculation

CIDR Stands for Classless Inter-Domain Routing can be defined as a method to calculate the no. of IP addresses and an efficient way of allocating IPs in the network. Let’s take a look at the below example for better understanding.

IP Addressing in Azure | Understanding CIDR and Subnet Mask Representation 2
IP Addressing in Azure | Understanding CIDR and Subnet Mask Representation

In the above example, you are given a CIDR Block 10.0.0.0/24 and asked to calculate the no. of IP Addresses.

Syntax of CIDR Block is IP address/Subnet mask. Therefore according to our example, the IP address is 10.0.0.0, and the Subnet mask is 24.

The formula to calculate the no. of IP Addresses is 2^n where n= 32 – subnet mask, 32 being the no. of bits in an IPv4 address.

Usable IP address Range

Now that we have a total number of IPs in a given CIDR block, we need to know the number of usable IP addresses. All of the IP addresses are not available to use. Formula to find no. Of usable IP’s is (2^n)-2. Considering the above example usable IP address range is 256-2 = 254 because the first IP of the range will be reserved as a Network address, and the last IP will be reserved as a Broadcast address by the system, and they cannot be used for devices.

In every IP Range, the ‘0’ address is assigned a network address, and the ‘255’ address is assigned as a Broadcast address. Going by our example, the Network address is 10.0.0.0, and the Broadcast address is 10.0.0.255. and the usable IP Address Range for hosts is 10.0.0.1 to 10.0.0.254.

Subnet Mask Representation

A subnet mask is a 32-bit number with 0’s and 1’s used to divide host and network bits. Host bits are set to 0, and network bits are set to 1. Using Host bits, you can also calculate the number of IPs and determine the IP range. In short, Subnet Mask can be helpful to find out the addresses in a particular network. Let’s consider our previous example and see how we can represent it using Subnet Ma.sk

IP Addressing in Azure | Understanding CIDR and Subnet Mask Representation 3
IP Addressing in Azure | Understanding CIDR and Subnet Mask Representation

In the above example, the Subnet mask is 24. So, we separate 24 = 8+8+8+0, dividing it by 8 since each octet is 8 bits. If the subnet mask is 27, then it will be 27=8+8+8+3. Now, we distribute the subnet mask across the address with 1’s where ever there are 8’s starting from left to right. In the above example, the First 3 octets are filled with 1’s because there are 8’s, and the last octet is filled 0’s because the last divided octet (8+8+8+0) from the subnet division is zero. Adding all the values where there is 1 in each octet (128+64+32+16+8+4+2+1 =255), the subnet mask would be 255.255.255.0

Let’s take another example for better understanding. In the below example, the subnet mask is 27, dividing it by multiples of 8 octet division is 8+8+8+3. Now, we distribute the subnet mask across the address with 1’s where ever there are 8’s starting from left to right, but in the last octet, we put 1’s only in the first three bits because the last octet division (8+8+8+3) is 3. Now add all the values with 1’s in each octet makes the subnet mask 255.255.255.224 because, in the last octet, there are only three 1’s and the values to be added are 128+64+32 = 224

IP Addressing in Azure | Understanding CIDR and Subnet Mask Representation 4
IP Addressing in Azure | Understanding CIDR and Subnet Mask Representation

Subnet Calculation

When you are building a network it is important to know how many subnets you would like to have depending on your requirement like with the available IP’s you might want to group/divide it by departments and apply different restrictions on each subnet and so on. There are many IP Addressing subnet calculators available online (I have placed a link below in Resources section) but I believe it is important to understand how we calculate this.

We have understood about Host bits and network Bits from Subnet Mask Representation section above. Now to calculate the no. of possible subnets the formula is again 2^n where n=borrow bits. Borrow bits are no. of 1’s in the last octet with 1’s. If the last or 4th octet has all zero’s then we go for the penultimate octet, if even that has all zero’s then we go for the one before that. Let’s take a look at some examples to understand the calculation better.

In the first example let’s consider CIDR block 10.0.0.0/27 and find the no. of possible subnets we can have. From the subnet mask representation below you can see that no. of 1’s in the last octet are 3 Therefore no. of borrow bits are 3 i.e. n=3 .

  • no. of possible subnets for a CIDR block = 2^n = 2^3 =8.
IP Addressing in Azure | Understanding CIDR and Subnet Mask Representation 5
IP Addressing in Azure | Understanding CIDR and Subnet Mask Representation

In the second example, lets consider 10.0.0.0/24 and try to find out the no. of subnets it can possibly have. You can see from the subnet mask representation below that we have all zero’s in the last octet. So, we considered the penultimate octet for borrow bits and the no. of borrow bits in this case are 8 so therefore:

  • no. of possible subnets for this CIDR Block = 2^n = 2^8 = 256

For Instance if we decide to go with 4 Subnets below is how the division will be.

Network AddressHost Address RangeBroadcast Address
10.0.0.010.0.0.1 – 10.0.3.254 10.0.3.255
10.0.4.010.0.4.1 – 10.0.7.254 10.0.7.255
10.0.8.010.0.8.1 – 10.0.11.254 10.0.11.255
10.0.12.010.0.12.1 – 10.0.15.254 10.0.15.255
IP Addressing in Azure | Understanding CIDR and Subnet Mask Representation
IP Addressing in Azure | Understanding CIDR and Subnet Mask Representation 6
IP Addressing in Azure | Understanding CIDR and Subnet Mask Representation

How is IP Addressing different in Azure?

IP Addressing is different in Azure when it comes to Usable IP Range. In Azure usable IP Range is (2^n) -5 instead of (2^n)-2. These 5 addresses are reserved for the below purposes. So, the usable IP’s in the range 10.0.0.0 – 10.0.0.255 would be from 10.0.0.4 – 10.0.0.254.

  • Zero IP – Network Address
  • First IP – DHCP Address
  • Second IP – Router Address
  • Third IP – Microsoft reserves it for future purposes.
  • Last (255) IP – Broadcast Address.

Understanding IP Addressing is important for implementing Azure Virtual Networks, which we will discuss in the next article. I hope you found this article useful 👍

Resources

Leave a Comment

Your email address will not be published. Required fields are marked *