# how to find a minimum number of host bits needed? [duplicate]

let's say I have 200.35.1.0/24 network block. I need to address 20 hosts on each subnet. How do I specify the minimum number of host bits that are required?

First, you have to add 2 addresses to the number of hosts you want. These are for network and broadcast addreses (therefore, for 20 hosts you get 20+2=22)

Second, convert this number to the binary (22d = 10110b)

Now, count how many bits you used and that's your answer (in this case, it will be 5 bits, so 32-5=27 bits for network) Your subnets will be then 200.35.1.0/27, 200.35.1.32/27, 200.35.1.64/27, and so on..

Alternatively, you can use some network subnet calculator, most of them allow you to choose or enter number of hosts per subnet (always choose closest bigger number by at least 2 hosts, as I said in 1st step). Example of such calculator is http://www.subnet-calculator.com/

• I just went to your site, so I input 30 for "hosts per subnet" and the answer is in "subnet bits" or is it "mask bits" because that has 27 in it? Oct 13 '15 at 23:18
• What you are asking for is a bit uncommon, so to get number of subnet bits for hosts, you have to take maximum number of bits (32) and subtract the network bits (27 in this case), so u get 32-27 = 5. What you usually want, is the number of bits in network part of subnet mask or the subnet mask itself (mask bits or subnet mask field), because that is what you use for calculating subnets and what you enter into configurations usually (the exception is wildcard mask, but that is something else)
– Fuki
Oct 14 '15 at 8:18

I think everyone is everywhere of how to get the number of available hosts given a prefix length of a certain size, for example with an /24 IPv4 prefix, you have 32-24 = 8 bits for hosts, giving 2^8 = 256 hosts or 254 "usable" ones. This is usually taught in any networking class or explanation of subnetting.

The inverse of 2^x is log(x)/log(2) so to get the number of bits for 22 addresses, you just do:

``````log(22)/log(2) = 4.459
``````

Obviously you can't do decimal prefix length so you have to round that up to the closest integer, which is 5. You need 5 bits, or 32-5 = 27, i.e. a /27 network!

• it's 22 adresses (for 20 hosts, +2 for broadcasts/reserved) Nov 25 '15 at 12:19
• @OlivierDulac are you commenting that I used the word "hosts" and not addresses? I edited to say "addresses" instead. If not, I don't understand what you mean. I did the calculations for 22..
– kll
Nov 27 '15 at 0:01
• yes it was so that one don't forget that with N adresses you can have at most N-2 hosts (as you need to reserve the one with all bits set at 0, and the other with all bits at 1, for broadcasts/reserved routing needs) (which you now say more clearly. good edit) Nov 27 '15 at 8:28

With a class C to get hosts, I count from 128 backwards cutting it in half each step. So 128, 64, 32. It has to be 32 hosts because half of 32 is 16, not enough for 20. That's 3 bits borrowed. That is from a standard /24 to a /27. The networks are added by starting with 2 and doubling them, so 2, 4, 8 which gives you 8 nets for 3 bits borrowed. I made a video for my class that shows you how to make an easy to remember cheat sheet, that helps you understand the basic concept of subnetting a class C network. https://www.youtube.com/watch?v=zqH0COM81Qc