From that quick look, it should be clear that using 3 bits will meet our immediate needs – after all, this allows for 6 subnets, and we only need 3. I’m not saying this is the best answer to account for growth, but it will work for the time being. Using 3 bits to define our subnet mask gives us the custom subnet mask illustrated in the figure below.

Figure: Custom subnet mask supporting up to 6 subnets.

Notice that our custom subnet mask becomes 255.224.0.0. I simply converted the second octet from binary to decimal to get that value. But how do we know whether this custom mask supports enough hosts per subnet? Just look at how many host bits remain, according to the mask. In this case, the first 8 bits represent the network. The next 3 bits are used to define subnets. That leaves 21 bits for hosts – recall that the mask contains 32 bits in all. With 21 host bits, we can have 2^{21} – 2 hosts per subnet. Remember that the 2 bits are always subtracted when we calculate the number of available host addresses. Altogether, our 21 host bits provide an incredible 2,097,150 host addresses per subnet! If that seems like a bit much, not to worry. We can always “play” with the mask value to give us a subnet / host per subnet breakdown that better meets our requirements.

The table below outlines the custom values that are possible for an octet when it comes to subnet masks. Notice that all of the binary values simply add 1s in high order – the binary 1s must be contiguous in this way.

Bits Used | Binary Value | Decimal Value |

1 | 10000000 | 128 |

2 | 11000000 | 192 |

3 | 11100000 | 224 |

4 | 11110000 | 240 |

5 | 11111000 | 248 |

6 | 11111100 | 252 |

7 | 11111110 | 254 |

8 | 11111111 | 255 |

Since there are only eight custom values that can go into a mask, we are limited in terms of the number of subnets we can define. For example, consider a case where we need 17 subnets. How many bits would you use? Well, 4 would not be enough, since this provides only 2^{4}-2, or 14 subnets. The next choice is using 5 bits. Notice that this gives us 2^{5}-2, or 30 subnets. This is more than we need, but there isn’t anything else between these two values. Not to worry, though. Using 5 bits, we not only meet our immediate need, but also account for 13 additional subnets worth of growth! Again assuming a Class A address, this gives us the breakdown illustrated in the figure below.

Figure: Custom subnet mask to support up to 30 subnets with a Class A address.

Using 5 bits gives us a custom mask of 255.248.0.0 after we convert the mask back to dotted-decimal notation. To calculate the number of hosts per subnet, just take the remaining bits (8 are used to define the network, and 5 the subnets, which leaves 19 host bits), and do the calculation. 2^{19}-2 equals 524,286 hosts per subnet.