How To Calculate a TCP-IP Subnet Mask

Melanie Gross
Sep 3, 2011
Network, Tutorials

If you’re a network administrator, chances are at some point you may need to set up a number of different networks on your IP range. In order to do this, you will need to know how to create different subnets.

There are two main things to remember when trying to calculate subnets. The first is that that default subnet for a range is This subnet, that we all recognize gives you one network with 255 different addresses from 1 to 255. Fairly easy stuff so far. The second thing to remember is the formula needed to calculate a new subnet. For this we have to go back to basics and remember that the number 255 is made up in binary of 8 bits. To get the number 255, all those 8 bits would be set to 1, each one representing a number in decimal in the following sequence. (1, 2, 4, 8, 16, 32, 64, 128). If you add all these numbers together you get 255.


In order to create our subnet mask we need to “borrow” a certain number of bits from our host address. The host address is the last number in the group of four that makes up our subnet. So in the subnet, the 0 is the host address.

We can use the formula (2^n – 2) to figure out how many networks we can make by borrowing certain number of bits. Lets say for example we wanted to make six networks; we would need to borrow 3 bits, because (2^3 – 2 = 6). So we take the three bits from the left of our binary sequence and add them together. (128 + 64 + 32 = 224). So the subnet we need to use for our 6-network system is

Now we’ve calculated our subnet, the next thing we need to do is work out the ranges of our new networks. This is a fairly easy thing to do if you remember one rule. The lowest number in the bits we borrowed from our host address is our guide. In this case, the bits we borrowed were 128, 64 and 32. The lowest of these is 32, so this is our guide number we’re going to use to set up our network ranges.

What you want to do is start off with your guide number, and that gives you the first address of our first network. For example - To get the starting address of the second network, you just add on 32. So the second network will begin at Keep adding the number 32 to find the other network starting points, and you’ll end up with this network address range map:

  • Network 1: –
  • Network 2: –
  • Network 3: –
  • Network 4: –
  • Network 5: –
  • Network 6: –

Note that you cannot use the first 32 or last 32 addresses of the entire 255 address range, (unless you’re using specific equipment that allows it). And there you have it, we’ve calculated our subnet mask, and we’ve worked out the ranges our networks will use. Remember the formula (2^n – 2) and your binary numbers, and you’ll be able to work out any configuration of subnets and networks.


Previous Post: «
Next Post: «


  1. siHensem said on June 9, 2013 at 4:02 am

    Thank you very much….

  2. uzma said on March 1, 2013 at 12:23 am

    Thanks so much you explained in such simple way thanks a ton.

  3. Seguradone said on February 12, 2013 at 11:10 pm

    This is a good article, but it is wrong (when calculating the subnet), the formula (2^n – 2) is used to calculate how many hosts a subnet can contain. For the subnet it is only 2^n. Look for it in cisco, or in online subnet mask calculators. For example: the last octet contains 3 ones (binary), so 2^3 = 8 (this is right), but the example here shows 6, which is wrong.

    1. james said on August 5, 2014 at 11:21 am

      i thought it was always minus 2 for broadcast and network address?

      1. david said on November 18, 2014 at 11:27 pm

        It is minus two to find out how many hosts are available.

  4. Shan said on December 28, 2012 at 10:57 pm

    Thank you you are the only person i could understand

  5. mak said on December 11, 2012 at 7:10 am

    clear explanation. thanks

  6. Anonymous said on December 4, 2012 at 10:03 am

    thanks your notes helped me

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.