Someone Somewhere said:

The subnet mask expands to binary (in some systems it's written as the number of bits in a row set to one, e.g. 255.255.255.0 would be /24).

255.255.255.0 becomes 11111111 11111111 11111111 00000000. As you can see, the first 24 bits are set to one. If a bit is set to one, the bits in the address must match.

$addresses = 2^$zeroes, or $zeroes = log(2)$addresses.

Note that you need to round up to the next power of two, e.g. 512 addresses (with 510 hosts, because of excluding the 0 and 255 addresses.

If you were using an address of e.g. 192.168.0.xxx, valid addresses would be 192.168.0.1 to 192.168.1.254, with a mask of 255.255.254.0 - a /23 subnet.

Hi, Thanks for your reply... but I am not understanding your formula of $addresses = 2^$zeroes, or $zeroes = log(2)$addresses.

I understand how a subnet mask works, how to find the ranges, etc. I just need to know how to figure out the mask when given a number of hosts.

Can you show me visually how you came up with 512 (- 2, of course) and how the mask comes out to be 255.255.254.0?