View profile

CIDR, Private IP vs Public IP - Software Shots - Issue #3

CIDR, Private IP vs Public IP - Software Shots - Issue #3
By Karn • Issue #3 • View online
Hello! It’s 3 AM, technically on a Saturday and I just raised a code review at my work and came back to write this off. Hope you guys like it. Also enjoy the bullet points in this digest. 😛 😝

Last year I had an opportunity to sit for a Hackerrank test for CRED as an SRE Intern. The only question I got was find the number of IPs in a CIDR range. Only python was allowed. Me being a noob at the time, imported the ipaddress module and solved it in 2 minutes. But I regretted the fact that I actually didn’t know the significance of it. So let’s understand it together.
Classless Inter-Domain Routing (CIDR)
Pronounced as SYDER. Just for my brain’s sake, I won’t go out of IPv4. Okay so if you have ever tried deploying your website or an API on some cloud provider (AWS/GCP/Azure etc), you must have encountered these:
They basically help you to define IP address range. Let me give you some examples.
  • AA.BB.CC.DD/32 == one IP
  • == all IPs
  • But for a range, - (64 IPs)
Understanding CIDR
It has two components:
  • The base IP. (XX.XX.XX.XX)
  • The subnet mask (/26)
The base IP represents an IP contained in the range, whereas the subnet mask defines how many bits can change in the IP.
Subnet Masks
The subnet mask can take two forms. Exempli Gratia (e.g.):
  • - This is probably less common.
  • /24 - More common and easier to read.
The subnet masks basically allows part of the underlying IP to get additional next values from the base IP.
  • /32 allows for 1 IP bit to change = 2^0
  • /31 allows for 2 IP = 2^1
  • /30 allows for 4 IP = 2^2
  • /29 allows for 8 IP = 2^3
  • /16 allows for 65,536 IP = 2^16
  • /0 allows for all IPs = 2^32
Obviously, you don’t need to memorize all that. Just train your brain to subtract from 32 with whatever is after the slash. You get the number of bits that can be changed. Raise it to the power of 2. These many number of IPs belong to the range.
Anyways, when in doubt:
Private vs Public IP (IPv4)
The IANA (Internet Assigned Numbers Authority) established certain block of IPv4 addresses for the use of private (LAN) and public (Internet) adresses.
Private IP can only allow certain values:
  • Big Networks: - (
  • AWS’s default: - (
  • Home Networks: - (
All the rest of the IP on the internet are public IP.
Okay now I am actually, sleepy. Let me know if these small software shots help you in anyway. Thanks! Good night. 👻
Did You Have a Look at X?
Software Life Cool shit
Mute the group, we post at odd hours. We’re also looking for a better name for the group.
Also, I have a decent website where I blog sometimes:
Did you enjoy this issue?
By Karn

I build and create things. As of now, I work as a Software Engineer at SendX/SendPost.

If you don't want these updates anymore, please unsubscribe here.
If you were forwarded this newsletter and you like it, you can subscribe here.
Powered by Revue
Gyan Karn, Delhi, India - 110039