Fast IPv4 CIDR Subnetting Math: Calculating Subnets, Block Sizes, and Usable Hosts

Fast IPv4 CIDR Subnetting Math: Calculating Subnets, Block Sizes, and Usable Hosts

Here are some Classful Subnetting tricks that I learned while preparing for my CCNA Cert – I’m sure that brushing up on these can’t hurt anything.

Any time that you break these down you are subnetting  – so an example question would be if you have a subnet mask of 255.255.255.128 and you are subnetting 172.16.0.0

(A) How many subnets would you have? (B) What are the valid subnets? (C) How many hosts will be allowed?

The first part is easy – we know that 172.16.0.0/16 – has 16 whole bits free for subnetting. We need to know which bits we are going to use though.

How do we get this? – We derive this by looking at the amount of subnet bits we can use based on our mask so we count the extra bits by putting our subnet mask of 255.255.255.128 and convert it to a CIDR notation 255(8) . + 255(8). + 255(8). + 128(1) = 25

Now we subtract our subnet by the classful subnet and get:
25-16 = 9

So we use the following formula: 2^9 = 512

A. 512 valid subnets

Now the second part is a little harder. We use our magic formula of 256 – our decimal format. So for 255.255.255.128 we can subtract 256 by 255 for our third octet or we can just memorize that all bits and numbers can be used. What about the fourth octet? Same rules apply.  So 256-128 = 128 so we can use 172.16.0-255.0,128 – as our subnets.

B. 172.16.0 – 255.0, 128

Now the third part is easy again we take how many subnet bits we have, 25 and subtract it from 32 total IPv4 bits: 32 - 25 = 7 host bits.

Using powers of two for the 7 remaining host bits: 2^7 = 128 addresses per subnet.

We are still not finished though, we need to account for the broadcast address and the network address. These are two addresses so we do this:

cli
2^7 - 2 = 128 - 2 = 126

C) 126 Valid Hosts

 

 

 

 

>_ Engineering Discussion 4 Comments

+ Add Field Note ↓
  1. Adding the binary bit-boundary breakdown alongside the CIDR prefix table makes it much easier to explain why /30 point-to-point links waste two addresses compared to RFC 3021 /31 interconnects.

  2. Bookmarked for our NOC onboarding wiki. Having the usable host counts and subnet masks side by side is still the fastest way to double-check VLAN summaries during a change window.

  3. Clear and concise IPv4 reference. It would be great to see a follow-up comparing /64 and /127 IPv6 point-to-point allocation standards for spine-leaf fabrics.

  4. An impressive share! I have just forwarded this subnetting cheat sheet onto a colleague who is preparing for his CCNA and was struggling with /27 and /28 block boundaries. Thanks for putting this reference together!

Leave a Technical Comment

Share CLI tips, hardware notes, or questions below. Inline backticks (`command`) are supported.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Engineering Notes