In our previous interview-related question we talked about VPC design, logging system design, monitoring system design, page fault, etc. In this article, we are going to talk about how to calculate how many usage IPs are there in a /24 CIDR.
What is a CIDR?
CIDR stands for classless inter-domain routing. This is a set of rules to assign IP addresses. As you must be aware there can be a total of 4,294,967,296 [2^32] different IPs addresses but there are lot more devices than that. With help of CIDR you can easily reuse the IP addresses.
Every IP has two parts network address and host address.
The network address tells about the network and the host address tells about the devices to which that IP is assigned.
So for any device in a network, the network address is fixed, just the host address part of the IP changes.
So if the question is how many usable IPs are there in /24 CIDR, it means that first 24 bit of the IP is fixed for network and only 32-24 =8 bits of IPs are there to be assigned to different machines.
32 - 24 = 8 2^8 = 256 2 ips are reserved for network address and broadcast Address 256-2 = 254
This answer can vary from cloud to cloud as they can have different use cases of these IPs.
So the answer to the question in 2 ^ x -2 is the CIDR given is /x
If you like the article please share and subscribe.