Pawan Mishra
by Pawan Mishra
1 min read

Table of Contents

  1. IP Addresses
  2. CIDR Notation
  3. Subnets

IP Addresses


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


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: 172.198.0.0 - 172.198.0.31. 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 172.198.0.0/27. 255.255.255.224 is our subnet mask.

You can read more about CIDR notation here or you can see them in action here.

Subnets


ToDo