A Subnetting Tutorial
Posted 28 October 2012 - 08:52 PM
Okay, for the question "For the LANs attached to the branch routers, divide the address space 10.1.0.0/16 into four equal subnets" the answer is 10.1.0.0/18, 10.1.64.0/18, 10.1.128.0/18, and 10.1.192.0/18, okay?
Now here's a very in depth reason as to why, which I hope will answer some questions:
A bit is either a 1, or 0, okay? That's 2 possible combinations for each bit. You've heard that before.
Alright, so each number in an IP address can range from 0 to 255. Why? Well that's because a computer represents IP addresses as bits. For the computer to understand an IP address, each number in an IP address is represented by 8 bits and there are 4 total groups of numbers (XXX.XXX.XXX.XXX), for a total of 32 bits. (Remember the total, it will come back in a little while.)
Okay so this part is a little complicated but as was mentioned each bit as two possible combinations (0 or 1, off or on) so if we have 2 bits together then there are 4 possible combinations (00, 01, 10, 11) and if we have 3 bits together we have 8 possible combinations (000,001,010,011,100,101,110,111) and so on. Alright, so stay with me here: There is actually a pattern to the possible number of combinations. If you have 2 binary bits then the possible combinations are 2^2, or 4. The pattern could be stated as: two combinations to the power of how many bits there are (2^n), in this case 2. If you have 3 it's 2^3, which is 8.
So we said that each group in an IP address has 8 bits, right? Okay so the maximum number of combinations in each IP address group is 2^8 (two combinations times eight total bits) or 256, which is where the limit of 255 comes from. This is because, in computing, 0 is the first digit we count, instead of 1, so instead of being 1-256 it's 0-255. Just a little quirky, but you'll need to remember that.
And now we have another tricky part. When we as humans count we go 1,2,3,4,5,6,7,8,9 and then we restart at 0, but add one to the tens position to get 10. Then we go 11,12,13,14,15,16,17,18,19, start back over at 0 and add one more to the tens position to get 20. We work from right to left like this as numbers get larger (1000 = 999 + 1). We do something similar with IP addresses. For example, if we have an IP address of 0 0.0.255 (in bits: 00000000.00000000.00000000.11111111) and we then increase the address by 1, we start back over at 0 and add 1 to the next group to the left, getting 0.0.1.0 (in bits: 00000000.00000000.00000001.00000000), alright? Okay that means that the 1 in the second group represents ALL of the numbers in the first group. So if you follow me then the address 0.0.3.128 would mean we are on address number 3 * 256 + 129, or 897. We multiply 256 by 3 because of the 3 in the second group. The 3 in the second group represents 3 full groups of the first group and the maximum addresses we can have in group one is 256, remember? We then add 129 (because we started at 0, not 1) for our total of 897. So just remember that every increase by 1 in group two represents a full group one (0.0.1.0 = 0.0.0.255 + 1, in bits 00000000.00000000.00000001.00000000 = 00000000.00000000.00000000.11111111 + 1), and an increase by 1 in group three represents a full group two (0.1.0.0 = 0.0.255.255 + 1, in bits 00000000.00000001.00000000.00000000 = 00000000.00000000.11111111.11111111 + 1), and an increase by 1 in group four represents a full group three (220.127.116.11 = 0.255.255.255 + 1, in bits 00000001.00000000.00000000.00000000 = 00000000.11111111.11111111.11111111 + 1). I really hope that makes sense...
OKAY, SO! If you haven't fallen asleep yet or are still understanding me, this is where subnets come in. Subnets help us summarize and route addresses. In order to understand how this works we need to look at this on the bit level. Okay, say we have the address 192.168.0.11/18. With this information we can determine three things: one, the address of the host; two, the lowest address in the subnetted network; and three, the highest address in the subnetted network. Let's represent this as bits to understand why this works:
11000000.10101000.00000000.00001001 = 192.168.0.11
11111111.11111111.11000000.00000000 = 18 bit mask (there are eighteen 1s)
The way subnets function at the binary (bit) level is that wherever there is a 1, we can't touch, and wherever there is a 0, we have free reign. SO to determine the lowest possible address, we change the binary IP address to a 0 wherever there is a 0 in the binary subnet mask,
11000000.10101000.00000000.00001001 = 192.168.0.11 is the host
11000000.10101000.00000000.00000000 = 192.168.0.0 is the lowest address in this subnet, also known as the network address.
To find the highest possible address, we change the binary IP address to a 1 wherever there is a 0 in the binary subnet mask.
11000000.10101000.00000000.00001001 = 192.168.0.11 is the host
11000000.10101000.00111111.11111111 = 192.168.63.255 is the highest address in this subnet, also known as the broadcast address.
Remember: Both the network and broadcast addresses are unassignable. This reduces the total number of usable host IP addresses by two. To determine the number of usable hosts in a subnet we take the total number of bits in an IP address (32, as we mentioned before) and subtract the number of subnet bits (in this case, 18). So 32 - 18 is 14. Then we take 2 combinations per bit to the power of how many bits we have (2^n), just as we have done previously. So we have 2^14, which is 16384 addresses, but we have to subtract 2 for the network (lowest) and broadcast (highest) addresses in the subnet. We have a total of 16382 usable addresses.
Okay, so how do we translate subnet bits into a subnet mask address? Well we actually have to do some addition here because subnet masks work from left to right, instead of right to left as IP addresses do. So follow this sequence: 2^7 + 2^6 + 2^5 + 2^4 + 2^3 +2^2 + 2^1 + 2^0 for each of the subnet bits. Once we end the sequence we put a period and start over. Once we're out of bits we put 0s for the remaining groups. Let's try and find the mask of our 18 bits.
2^7 + 2^6 + 2^5 + 2^4 + 2^3 +2^2 + 2^1 + 2^0 = 255 . 2^7 + 2^6 + 2^5 + 2^4 + 2^3 +2^2 + 2^1 + 2^0 = 255 . 2^7 + 2^6 = 192 . 0
So our subnet mask is 255.255.192.0
Here's a picture that summarizes what I just attempted to explain. I hope it doesn't confuse you more:
Okay so back to the original question, if we are given 10.1.0.0/16 and told to split it into equal quarters then we need 4 subnets. So how many more subnet bits do we need to make 4 (remember 2^n)? Well we only need two more. That's a total of 18 subnet bits and our subnet mask is 255.255.192.0. Our usable networks are 10.1.0.0/18, 10.1.64.0/18, 10.1.128.0/18, and 10.1.192.0/18, which each have 16384 hosts.
That's probably a lot more than you need, but hopefully that explains a few things...?
Posted 28 October 2012 - 09:46 PM
X = 2^n - 2
Where X represents the number of USABLE hosts per subnet, and n represents the number of host bits needed to support this. From there I proceed to write the mask out in binary. So if I had a network that needed to support say 45 hosts max, I would substitute in values for n until I reached the nearest number greater than 45.
To save time...
2^6 - 2 = 62 which is the closest number of hosts to 45 whilst still being greater than 45
Knowing now that n = 6, I could then write out my mask in binary.
11111111.11111111.11111111.11000000 (The zeros representing host bits)
Translate that to dotted-decimal
And viola, a subnet mask.
Edit: This only works by the way if you're given the number of hosts the network needs to support, for other types of questions I have other methods, but Y0ungBra1n did a great job of explaining everything, so I'll probably not bother writing those out.
Edited by TheFunk, 28 October 2012 - 09:53 PM.
Posted 29 October 2012 - 02:00 PM
Posted 30 October 2012 - 01:13 PM
Subnetting Memory Stuff
Position 8 7 6 5 4 3 2 1
Value 128 64 32 16 8 4 2 1
Number 256 128 64 32 16 8 4 2
Subnet 10000000 128 Class A MSB 0 0 to 127.255.255.255
Bits 11000000 192 Class B MSBs 10 18.104.22.168 to 22.214.171.124
11100000 224 Class C MSB 110 192.0.0.0 to 126.96.36.199
BinRev is hosted by the great people at Lunarpages!