Had a math test relating to subnet masks, subnets and hosts today. I did study a great deal yesterday, I had a solid 2 hour stretch that allowed me to tear into chapter 2 of my Server 2003 Infrastructure book. I took my time about it and made sure I understood the formulas presented to me, but there was a problem. The book has an excellent formula for calculating the number of hosts per subnet, but not the number of subnets. And most of the questions wanted to know number of subnets. I drew a total fucking blank on most of the test. Not good. It was open book & open computer, but I resisted the temptation to punch the numbers into a subnet calculator on the Internet. Instead, I wanted to figure out for myself how to calculate that shit out. I came across a nice equation that does subnets rather easily. S (for # of subnets) = (# of total possible hosts (Based on class)) --------------------------------------------------------- (# of desired hosts rounded up the the nearest exponent of 2) So say you have a class C address (Default subnet mask is 255.255.255.0) and you want 64 hosts on each subnet. The number of total possible hosts for a C address is 2^8, because only 8 bits are left off for the host IDs. 2^8 = 256. I'm not gunna knock 2 off of that because it fucks with the equation, I know about default gateways and broadcast IDs and crap. Anyhow, so you get this: S = 256/64 = 4 subnets So you get 4 subnets with 64 (62) hosts each. Then, I invented a handy little chart that makes things even easier. To figure out the value of the last octet in decimal from this crap, consider that .128 is the first subnet mask you come across. .128 is half of 256, and allows for two subnets, and has the first bit turned on for the network ID. It's next partner in crime down the list is .192, with 4 subnets available for use and 2 bits on. I noticed a pattern. .128 is 1 bit on for 2 subnets (128 hosts each) .192 is 2 bits on for 4 subnets (64 hosts each) .224 is 3 bits on for 8 subnets (32 hosts each) .240 is 4 bits on for 16 subnets (16 hosts each) .248 is 5 bits on for 32 subnets (8 hosts each) .252 is 6 bits on for 64 subnets (4 hosts each) .254 is 7 bits on for 128 subnets (2 hosts each) .255 is 8 bits on for 256 subnets (1 host each) You can figure out the decimal subnet mask aswell as the / notation mask with this. Say it's a class B address with 3 extra bits on. Class B starts at /16 so you add 3 to make it /19, and your decimal is 255.255.224.0. Class A starts at /8 and Class C starts at /24 - multiples of 8 because of your 8 bits in each octet. Ohyeah, the formula I was using for hosts: C = 2^(32-n) - 2. n is the number of bits on with the slash notation, so like /22 would yield C = 2^10 - 2 = 1022 hosts. I had to modify this formula when he started specifying classes, because 2^(32-11) for a class C gives a lot of big numbers. I'm not sure I got that part right, I used my best judgement so we'll see how it goes. |