A Simplified Approach to Understanding IP Addresses and Calculating CIDR Blocks

Hi there, my fellow tech-savvy human. If you are reading this it means you want to finally understand the whole concept of IP addresses, how to calculate them and how CIDR blocks work and you’re welcome. Without further delay, let’s get into it.

First-off,

What are IP addresses?

IP (Internet Protocol) addresses are UNIQUE numerical labels that are assigned to devices that are connected to the internet to allow those devices communicate with each other and to exchange data.

Typically, an IP address is like a house address, each one is unique to its vicinity and location.

We have two types of IP addresses:

IPv4 and IPv6

The IPv4 is a 32-bit address. It looks like this 192.0.24.1, while the IPv6 is written in hexadecimal notation e.g 2000:0ae8:75b2:0000:0000:4d6b:6052:6113

Our focus in this article is on the IPv4.

What is a CIDR Block?

CIDR stands for Classless Inter-Domain Routing and it is a range of IP addresses that can be used to identify a specific network or subnet.

How to calculate an IP address from a CIDR notation

152.122.65.80/21

This is what a typical IP address looks like. The numbers before the “/” is the IP address and the number behind is the CIDR notation. We are going to find for this CIDR block:

  • The Subnet Mask
  • The Network ID

  • The Broadcast ID

  • Usable IP’s

Let’s get started,

The IPv4 model works with the 32-bit system.

So the first thing you want to do is put this down somewhere (I usually make a rough sketch on a piece of paper).

Now a subnet mask is a 32-bit that is used to identify the network ID portion of an IPv4 address. It looks like this

An addition of 128, 64, 32, 16, 8, 4, 2, 1 will give you 255

Now, when you see an IP address like the one we have above with a /21, turn on 21 bits (literally write out 21 1’s in 8 places and replace what’s left of the 32-bit with 0’s).

Don’t loose me yet. Follow me.

Each complete bit is equal to 255 because you added the numbers in the chart.

To get the subnet mask of the IP address you do this

255.255.248.0 becomes the subnet mask.

To get the Network ID:

Now looking at the CIDR notation which is equal to the number of bits turned on our focus is on the 3rd octet which is .65 (11111000) the others are maxed out from the CIDR notation so they can’t be changed. To get the network ID, there is a simple approach to it. Still using the chart we drew up earlier, use 65 to subtract the different numbers that can be subtracted by 65 until you can’t subtract its remainder

So you have your value, next you multiply them both

This gives us 64. Another way i learnt to check what bit is on and let it align with the chart we drew earlier (see why that chart is important?) The second bit is on 01000000 and it corresponds with 64 on the chart. (Now if two bits were on you’d add the corresponding bits eg 00110000 this would be 32+16= 48. )

This leaves our Network ID at

152.122.64.0

To get the Broadcast ID:

So, I have been using this method called '“the magic number”. Recall the number of bits that were on 11111111.11111111.11111000.00000000

The third octet has 5 bits on, on the chart the 5th one is 8, this means our ID will go up in increments of 8.

Then do 64 (i.e the value you calculated for your network id) plus 8 (the number gotten after corresponding the last bit on in the octet you’re working on) -1 = 64 + 8 - 1 = 71

Hence, the Broadcast ID is

152.122.71.255

Recall that the first and second octet are all on meaning they are fixed and can’t be changed leaving your adjustable options to the third and fourth octet.

To get the Usable IP’s:

This part is easy because you have a network IP and a broadcast IP, so the usable IP’s are

152.122.64.1 - 152.122.71.254

(you don’t want to assign 0 and 255 to your network)

So there you have it! I came across this method after a long period of struggling with CIDR and IP calculations and it has been very easy. You can try it with different IP addresses and CIDR notations.

If you’re still doubting, you can run it across this MxToolbox subnet calculator I found.

It’s too good to be true!

See you in my next article. Toodles.

0
Subscribe to my newsletter

Read articles from Precious Nathan Nnorom directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Precious Nathan Nnorom
Precious Nathan Nnorom

Hello, I'm Nathan Precious Nnorom, a passionate and driven cloud engineer with a mission to make cloud computing accessible to everyone. With a strong focus on simplicity and clarity, I strive to break down complex cloud concepts into easy-to-understand language. As a cloud enthusiast, I have hands-on experience with Amazon Web Services (AWS), specializing in: CI/CD Pipelines Docker Bash Linux EC2 Lambda S3 CloudFormation CloudWatch IAM I'm dedicated to empowering non-technical individuals to understand and leverage the power of cloud computing. On this blog, I'll share my knowledge, experiences, and insights to help you navigate the world of cloud engineering with confidence. Let's simplify cloud together!