We’re going to figure out how to solve this very common interview question.
The first question I get when I ask people this question is:
What’s a netmask?
A netmask is a 32-bit binary mask used to divide an IP address into subnets and specify the number of hosts available on the network. Essentially they are used to create small subnetworks out of an already existing network. This is great for dividing a corporate network up into smaller subnetworks for partitions such as different departments.
Next let’s answer this question with a real life interview questions.
How many IP addresses does a network w/ a netmask of /24 have?
This question can’t be answered right away because you first have to have an idea of the IP Class with which we are dealing with.
/24 is a tricky one because anything over /23 can be IPv4 or IPv6.
We need to figure out what the subnet mask is for the subnet we’ve been given. Let’s look at this CIDR table here. We see that we have the subnet mask of:
255.255.255.0
This is a Class C IP and we have 3 used segments. So the number of bits we have used is 2³ = 8 bits. Now we have some information to work off of and can figure out the answer to the question — how many IP’s can you create off of the netmask?
Next, we need to figure out the number of working hosts that we have. We can do this by computing as follows:
N = 2⁸-2 = 254 — We take off two because we have a broadcast and a network ID that we can’t assign to a laptop, per say.
So the scope of the question changes to now be “how many useable IP addresses can we generate off of the netmask?” and we can see that we can see that a network with a netmask of /24 has 254 unique IP addresses.