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

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.

About mike
Currently works for Recurly as a Senior Linux Admin. He has a wonderful wife Thanuja and 2 great children (Anusha and Brandon). His major side project is Photoblog.

  • X

    I found this to be easy once I fully understood what I was doing. We know that an subnet has 32 bits, that never changes, there is a relationship between hosts and networks.. so when someone says how many IP’s in a /25 for instance just do this. 32 – 25 = 7 bits. now count (use your fingers if you choose) starting with 2 doubling the last number always. In this example we would count like this, 2, 4, 8, 16, 32, 64, 128. This is 7 bits. There are 128 IP’s in a /25 and 126 useable. Conversely there are 2 networks. If you try another say /18 we do this 32-18=14 bits. Get out your fingers and toes lets start . 2, 4, 8, 16,32,64,128,256,512,1024, 2048, 4096, 8192, 16384. There are 16384 ip’s. the subnet in this example is each subnet has 32bits in 4 octets so 255= 8 bits, so an 18 bit subnet is 255 (8 bits). 255(8bits). 192 (2bits). 0. = subnet is that equals 4 networks with 16384-2 hosts per network. See simple.

    • Tik

      Thanks to ‘x’ – that is really helpful!

    • Taha Hussain

      You’re awesome! Thanks

  • Muzaffar Mahmood

    Thanks ‘X’. That’s really very easy method to understand IPs.