Subnets, Ho!
Wednesday, December 1st, 2004At Drewboy’s place today, tutoring in the noble art of subnetting. I am a geek, this is well established fact by now, so in the best traditional or nerds and geeks everywhere, I’m going to explain something to y’all whether you want to know it or not.
And God said unto Nigel and Tania ‘Go forth and multiply by binary bit powers’
The very basis of subnetting, as in almost anything to do with IP addressing, if Binary. Base 2 numbering at its finest. Converting between Base 10 (decimal, or everyday numbers as most know them) is surprisingly easy. Any Base 10 whole number can be converted to Binary using a simple sequence of divisions by 2.
Example
Since we’re working in whole numbers your divisions will either have a remainder of 1 or 0, this is what you use to define your Binary bit string.
210 in Binary
210 / 2 = 105 rem. 1
105 / 2 = 52 rem. 1
52 / 2 = 26 rem. 0
26 / 2 = 13 rem. 1
13 / 2 = 6 rem. 0
6 / 2 = 3 rem. 0
3 / 2 = 1 rem. 1
1 / 2 = 0 rem. 0
Can you see it? You divide by 2 as many times as you can, taking only whole divisions into account, until you divide by 2 and turn up a division answer of 0. There you stop. The remainders are your Binary number. So 210 in Binary is 11010010. Let’s try another one, a larger number this time
2365 in Binary
2365 / 2 = 1182 rem. 1
1182 / 2 = 591 rem. 0
591 / 2 = 295 rem. 1
295 / 2 = 147 rem. 1
147 / 2 = 73 rem. 1
73 / 2 = 46 rem. 1
46 / 2 = 23 rem. 0
23 / 2 = 11 rem. 1
11 / 2 = 5 rem. 1
5 / 2 = 2 rem. 1
2 / 2 = 1 rem. 0
1 / 2 = 0 rem. 1
so 2365 in Binary is 101111011101
Marvelous, eh?
Onwards into subnetting…
‘Why would you want to subnet?’, people may ask, ‘if a Class A private IP address provides for over 65 million useable IP addresses, why woud you bother?’. Well, true, it does, but the reasons for subnetting go far beyond this. Subnetting detracts from the number of available hosts, but allows you to have more than one network that acts totally independant of the others. It allows you to segment your network without any hardware, isolating sensitive equipment on its own network so that no one without proper authorisation can go through the routers to get to it.
OK then, so how do we go about subnetting? Well, first some basic principals of IP addresses need to be understood. IP addresses consist of four groups of decimal numbers seperated by dots. None of the numbers is below 0 or above 255. In Binary they consist of eight Binary numbers each. For this reason they are called octets. There are three classes of IP address, Class A, Class B and Class C (there are also Class D and E, but neither of these is subnettable). The first octet is what tells us what class we are in. If it is between 1 and 127 we’re in Class A, between 128 and 191 and we’re in Class B and between 192 and 223 we’re in Class C. Each of these classes has a default subnet mask, called the subnetless mask. For Class A it’s 255.0.0.0, for Class B it’s 255.255.0.0, and for Class C it’s 255.255.255.0. These masks form the basis of our subnetted masks. Anything set to 255 is totally given over to networks, anything set to 0 is available for us to subnet.
When we’re subnetting we borrow a certain number of bits from the host portion of the subnet mask and use them as part of the network portion. If we were working with the Class C IP address 192.168.0.0 we could borrow 4 bits from the hosts and create 16 extra networks. However the basis rule of subnetting, 2n - 2 ensures that only 14 of these new networks is useable (24 - 2 = 14). So we’ve borrowed four bits, and our default subnet mask in Binary which was 11111111.1111111.1111111.00000000 has changed to reflect this. It now reads 11111111.11111111.11111111.11110000
So now we have 4 ones where once we had 4 zeros, what does this mean to us? To us it means that we split our allowable bits where ones meet zeros. That last octet is, to us, 1111|0000.
The next step is to determine your new subnet mask. You’ve just added another four bits to it, so obviously you can’t have the same one as the default. In a Binary IP Octet there are 8 place values according to 20, 21, 22 and so on up to 7. 0 to 7, eight bits. In order from left to right (Binary works from right to left, but we read from left to right, so we’ll stick with that for now) these place values then become 128, 64, 32, 16, 8, 4, 2 and 1. So if we have ones under 128, 64, 32 and 16 then we have to add all of those up and detemrine the decimal number from them. So 128 + 64 + 32 + 16 = 240. So our new Subnet Mask is 255.255.255.240
Armed with this subnet mask we can then move on and work out some subnet addresses. All networks start at 0 when you’re working with the subnetless masks, and such is the case here. The first network starts at 0, but then where does our next network start? This,like the mask, is simple to work out. 0 through 255, the lower and upper limits of the IP Octet range, give us our answer. Between them is 256 numbers. If we subtract our new subnet mask, 240, from 256 we get the incrimental value of our subnets, 16. So 0 is our first network, 16 our next, 32 the third, 48 the fourth and so on until we reach 255. The 0, 16 and so on is our Network Number, the IP that defines the network we’re on, and so cannot be used to support a host. The same is true for the number before them, 15, 31, 47 and so on. These are the broadcast addresses for each of the networks. Messages sent to this IP are picked up by all hosts on the network. Since these two addresses are unusable this is where we get the -2 part of the Subnet rule 2n - 2. This rule leaves us with 14 useable hosts on each subnetwork.
Say our requirements call for the host range for the 2nd subnetwork and the 10th host on the 3rd, how would we get these? Easy too, the same way we got everything else. The host range is simply the first and last useable hosts on the specified network. So the second subnetwork, as previously stated, starts at 16, but we cannot use this, so our first useable host is 192.168.0.17. The last useable host is just as simple: if the next network is 32, then the broadcast of this one is 31 so the last useable host must be 30, or 192.168.0.30. So our host range for the second subnetwork is 192.168.0.17 - 30. The 10th host of the third subnetwork? If 32 is the third subnetwork address, then 33 must be the first useable host, so 10 on top fo that is 192.168.0.43, the 10th useable host.
It’s all simple once you know how. I doubt I’ve made the best explanation of it here, but I hope you can take something from this and learn it. Practice, practice, practice… that’s the key. Never stop practicing it and you’ll always have it there.