What is subnetting?
Subnetting is a very logical mathematic concept where you divide large computer networks into smaller ones. This allows computer networks to have multiple IP addresses and to communicate directly through routers, switches, hubs, and wide area networks (such as companies with multiple locations). At home, you probably wouldn't have a need to subnet, but if you are in a company or school where there are multiple offices or campuses, then you would need to.
If you have a block of IP addresses that you have purchased from your ISP (Internet Service Provider), and you have 90 computers between two offices that you need to assign IP addresses, Subnetting would be the process you would use to organize the networks so that they could all communicate.
If one office has 30 hosts (hosts are computers, printers, servers, cell phones, or anything else that a human would interact with in everyday office life) and the other office has 60 hosts, here is how you would set up the network so that both offices could communicate with each other:
The network and usable numbers
The IP address block that we purchased from our ISP is 184.108.40.206. Because we have 90 hosts, we purchased a block of 128 IP addresses. This means we can use that block starting at 220.127.116.11 and the last number we can use is at 18.104.22.168 (it doesn't end at 128 because the number 0 is the first number and it counts as one). The following chart is going to help with explaining how we come up with the subnet mask:
mask: 128 192 224 240 248 252 254 255
--- --- --- --- --- --- --- ---
hosts: 128 64 32 16 8 4 2 1
Notice that on the bottom row, going from right to left, every number goes up by the power of two. Next, notice that every number on the bottom row, if added to the number directly above it, is equal to 256. 2^0=1, 2^1=2, 2^2=4, etc.
If you take that table and put the exact same table to the right - three times, then you have the graphical version of a subnet mask. All of the numbers in the bottom row add up to 255. If you were to use binary to write out the number 255, it would be 8-bits. That is, 11111111. If you were to take away six bits from the right, you would have 64 - it would look like this: 11000000.
Subnetting in binary
A subnet mask of 255.255.255.255 (which would consist of only one host on the whole network) would look like this in binary: 11111111.11111111.11111111.11111111
If you had 64 hosts on the network, including the network ID and the broadcast IP, you would get rid of (or turn off) the numbers smaller than 64 on the table. In binary, if you want to "turn off" something, you would change it to a 0. So - using the table, you can see that 64 is equivalent to the mask of 192. Since we don't have less than 64 hosts, we don't need the numbers to the right of 64. Therefore, we can 0 out all the numbers to the right of 64. Now our subnet mask looks like this: 11111111.11111111.11111111.11000000 - this equals 255.255.255.192. Notice that there are 26 binary digits turned on (remember 1 = on), and there are 6 turned off. This means that you are in a 26-bit network - this is displayed as 22.214.171.124/26.
What you will never see
You will never see a subnet mask of 255.255.255.198 or any other number that does not end with a number on the top row of the chart. This is just another part of the logic of the network engineers who created this whole scheme of numbers. Also, if you create a network, you will always use the amount of hosts that are on the table as well. Keep in mind that you always need to add two to the amount of hosts you need because you need room for the subnet ID and broadcast address. The amount of available hosts will be 2^6-2 (6 is indicating the amount of bits borrowed - in the example above, the 6 zero's are the bits borrowed).
Because we have 60 hosts on one subnet and 30 on the other (as mentioned at the top of the page), we would still use a block of 64 for the 60 hosts. We would use a block of 32 for the 30 hosts. We would do this because that is how networks are set up. In some cases, an ISP may give you other random numbers, but if we go by the book, we don't do random numbers. We only do block sizes that are listed on that chart above.
The formula in more detail
There is a formula for subnetting that you can use in place of binary or charts. Remember the "power of two" that I mentioned above? If you have 30 hosts, and you know you need to round up to 32 to make room (as described in the above paragraph), you would use the formula 2^5 (2 to the power of 5 = 32). If you go back to the chart and, from the right, count to 32 (starting at 2, not 1 - because this is the power of two which wouldn't start at one), you would get 5! You had to get rid of 5 numbers to get to the number 32. If you were to use binary, the number 32 would be 11100000 - notice there are 5 zero's?
If I was to wright out the whole subnet mask, you would have 255.255.255.224 (remember that the mask above the hosts on the chart is what you use in correlation to the hosts. If you didn't have the chart, you could subtract 32 from 256 and you would still have 224. Or, for the 60 hosts (rounded up to 64), you could subtract 64 from 256 and you would get 192.
Putting the numbers together
Now that you know how to write 64 and 32 in binary, look at how many 1's are in each. 64 has two 1's and 32 has three 1's. If you were to write out the whole subnet mask for 64, you would see twenty-six 1's: 11111111.11111111.11111111.11000000. This is a 26-bit subnet. If we were to tell another person how big our subnet was, we could tell him or her that the first block is 126.96.36.199/26 (you would call that a "slash 26 subnet" - or, as my instructor called it, a "wack 26 network") and they would know there were 62 or less hosts on the network - plus the subnet ID of 0 and the broadcast of 63. They would immediately know what the subnet mask was 255.255.255.192.
Once we have used all 64 hosts on that network, we will have used 188.8.131.52 through 184.108.40.206 (pay attention to the 4th octet - that is the number after the 3rd dot. For the other 30 hosts, we would just continue on - starting at 220.127.116.11 and stopping at 18.104.22.168. Our hosts can use the numbers 65 through 92 (remember 64 is reserved as the subnet ID and 93 is the broadcast).
If you write out the binary for 32 hosts, you have 11111111.111111111.11111111.11100000. This is a 27-bit subnet. We would write the network as 22.214.171.124/27 if we were starting the last number. This means the subnet mask for the 32 hosts is 255.255.255.224.
Now you also would have two routers to join these networks if they were at different campuses. You would connect the routers via a point-to-point connection. This basically means that the routers have a small subnet of their own. Because there are two routers, and because we follow the rule of "leave room for two more," we will create a block of 4 for the routers to join. Since we have a block of 128 IP address (from the very beginning where we had 90 hosts - which means we have to use a block of 128), we still have room. In the chart below, I will simply add the routers to the bottom line.
The network plan
Here is a chart with the subnets that we just planned out:
Hosts Subnet Subnet Mask Usable IP Range Subnet ID Broadcast
64 126.96.36.199/26 255.255.255.192 188.8.131.52-62 0 63
32 184.108.40.206/27 255.255.255.224 220.127.116.11-92 64 93
4 18.104.22.168/30 255.255.255.252 22.214.171.124-96 94 97
Putting the network together
Now that we have planned out the network, all we have left to do now is configure the devices accordingly. See the image below (created with Cisco's Packet Tracer - if this is not allowed by some licensing, let me know and I will create the image some other way):