One of my most hated interview questions use to be “How many IPs in this subnet?”

January 13, 2011   

I use to hate this question. I was reading a post on Reddit about some guy that went through the programming interview at Facebook and it made me remember the simple interview question I always hated answering. It always went something like this

How many usable IPs in a /24

Ok that is an easy one.. 256-2=254 not a big deal.. next!

Then they would ask

How many usable IPs in a /28

That is what usually made me say “Networking is not really my strong point” Well got that one wrong.. So I went out to fix this many many years ago. Well there’s an easy step you can do in your head.

All subnets going up are half of the one below it. So your /24 would have 256 IPs in it. So it would go like this

/25 = 128
/26 = 64
/27 = 32
/28 = 16

So there was my answer 16 IPs and 14 are usable. Its really that easy to figure out. Anything between /24 and /32 is easy to figure out if you can easily do the math in your head like that. You can do the oppsite if they give you a /29

/32 = 1
/31 = 2
/30 = 4
/29 = 8

Now there is also a little math formula you can use also.

So back to our question.. If we want to know how many usably IPs in a /28. We would go like

2^(32-28) - 2

Which would be

(2^4) - 2 = 14

That broken down is like saying

(2*2*2*2) - 2 = 14

When you toss exponents in it gets a bit rough but its easier if they tell you.. So how many in a /20

(2^(32-20)) = 4096

We won’t worry about usable in this case because it depends how you will subnet it off.

comments powered by Disqus