# [Networking] Select a mask so that there will be a specific number of subnets and hosts available

This is mainly a reminder for myself and for who is working with subnetting and with the always arising question about how to work with subnets design.

The question to answer today is: you are given a network and you are asked to find a netmask so that you will have a defined number of subnets and a minimum number of hosts available in each subnet.

Example: select a subnet mask for 10.0.0.0 so that there will be at least 16.000 subnets with at least 700 host addresses available on each subnet.

The calculation is very easy and without any further explanation let’s jump immediately on the steps to take.

- Starting with considering what is the network CLASS where your network belongs to.

We have to remember that for CLASS A we assume that first 8 bits of the network are fixed at 1 and unchangeable. For CLASS B 16 bits are fixed and for CLASS C the fixed bits are 24. So we will never touch these bit in our calculation. In my example we will consider then 10.0.0.0/8 as a starting point. Thinking in bit we will have:

.00000000.00000000.00000000** 11111111**

- Borrowing bits to calculate the netmask for the subnets.

The second step is to calculate how many bits of the network portion we are going to borrow moving them from 0 to one starting from the left most 0. The formula to use is the well known *2^n – 2 *where n is the number of bits to borrow from the network*. *In my example we need to have at least 16000 subnets. That means that we will need to isolate how many bits to move to 1 using the already mentioned formula * 2^n – 2*, where

**is calculated with a log base 2 of 16000 (you can use online calculators).**

*n*Now, log base 2 of 16000 brings as a result 13,965, so let’s round off to 14. Our formula is then complete and will be 2^14 – 2. We now know that we have to borrow 14 bits from the network:

.**11111111***11111111.111111*00.00000000

So, the netmask we need to use to have then available at least 16000 subnets from 10.0.0.0 is 255.255.252.0. With this network we can be also sure that each /22 network will have up to 1022 hosts available. Infact the bits available for hosts are 10 and using the formula 2^10 – 2 we obtain exactly 1022.