# Calculating Subnets and CIDR Quickly

**Author:** HollyGraceful **Published:** 06 August 2021 **Last Updated:** 03 November 2022

A friend of mine mentioned recently that he has to work out subnet masks in his head for an exam and commented in reality he’d just use a subnet calculator. Whilst this is probably true, there’s a quick trick that might help if you’re calculating subnets under duress. This isn’t a full write up and offers no real explanation of why it works, it’s just pointing out a trick you may have missed which might come in handy one day!

Most people know the following to be true:

CIDR Mask IPs/24 255.255.255.0 256

If you’re comfortable with this then notice that as you add one to your CIDR, your available hosts in your range halves. Also you can work out the last octet of the mask by taking the previous octet value and adding the new available hosts to it.

So to move from /24 to /25 we half the previous available hosts 256 and get 128 (shown below in blue). To get the last octet we take the previous the last octet, 0, and add the new available hosts to it, 128, giving 128 in total (highlighted). So the next item in the list becomes:

CIDR IPs Mask/24 256 255.255.255.0 /25 128 255.255.255.128

We can carry this on further down the table performing the same halving and adding steps:

CIDR IPs Mask/24 256 255.255.255.0 /25 128 255.255.255.128 /26 64 255.255.255.192 /27 32 255.255.255.224 /28 16 255.255.255.240 /29 8 255.255.255.248 /30 4 255.255.255.252 /31 2 255.255.255.254 /32 1 255.255.255.255

Easy…

...but what if we want to move up the list instead? Well the maths still holds we just double the available hosts, but to work out the next step in the mask you simple find what your current third octet value is and take the next value up from the sequence. So the sequence is:

255, 254, 252, 248, 240, 224, 192, 128, 0.

So we’re currently at /24 and trying to work out what /23’s mask would be, well the third octet is at 255 so we use the next value which is 254, highlighted below!

CIDR IPs Mask/23 512 255.255.254.0 /24 256 255.255.255.0

But how can I possibly remember the sequence? I hear you cry. Simple, you don’t have to. You already worked it out when you did /24 to /32 (I highlighted it in the full table of /24 to /32 above). So now you can continue this pattern up from /23 as far as you’d like to go, like this:

CIDR IPs Mask/20 4096 255.255.240.0 /21 2048 255.255.248.0 /22 1024 255.255.252.0 /23 512 255.255.254.0 /24 256 255.255.255.0 /25 128 255.255.255.128 /26 64 255.255.255.192 /27 32 255.255.255.224 /28 16 255.255.255.240 /29 8 255.255.255.248 /30 4 255.255.255.252 /31 2 255.255.255.254 /32 1 255.255.255.255

### TL;DR

So all you have to remember is that single seed line:

CIDR Mask IPs/24 255.255.255.0 256

Then you can very quickly calculate the next line up or down! For IPs you just half as you go down or double as you go up – as you can see with the pink values above. For octet value you simply add the current IP value to the previous octet value, highlighted above. Unless you’re moving up then you just follow the pattern set for /24 to /32.

Well…jot it down, it might help one day!

But wait! If you need details like network ID, first host and broadcast address – that’s easy too!

That's it!