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:
CIDR (AWS)
CIDR (AWS)
They basically help you to define IP address range. Let me give you some examples.
  • AA.BB.CC.DD/32 == one IP
  • 0.0.0.0/0 == all IPs
  • But for a range, 192.168.0.0/26: 192.168.0.0 - 192.168.0.63 (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.):
  • 255.255.255.0 - 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: https://ipaddressguide.com/cidr
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: 10.0.0.0 - 10.255.255.255 (10.0.0.0/8)
  • AWS’s default: 172.16.0.0 - 172.31.255.255 (172.16.0.0/12)
  • Home Networks: 192.168.0.0 - 192.168.255.255 (192.168.0.0/16)
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?
Karn
By Karn

I am a final-year engineering student at BIT Mesra. I live in New Delhi, type a lot, shower often, learn quickly, strive to put others first, and live my life for Scarlett Johansson. I wish I could dance.

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