The Basics of IP Subnetting

by Mark Birchfield

To understand how subnetting works, you first must have a good basic understanding of IP addresses. An IP address is set of binary octets broken into quads. That definition may not have made any sense to you, so we will try it another way. An IP address follows what is called dotted octet notation. There are four sets of numbers in an IP address, and dots are used to separate them, for example, 192.168.0.1.

Let's go a bit further into the binary octet discussion. Binary numbers are broken down by what is known as positional notation, which works from right to left in increasing place values. Here is an example:

192.168.0.1 in binary octet form would be 11000000.10101000.00000000.00000001
Binary form of 192:
1     1    0   0   0  0  0  0 = 192
128  64   32  16   8  4  2  1   
(Hint: Add up the ones with the numbers below
them. First one equals 128, plus the second, which is 64. Added together
this equals 192.)
1     0    1   0   1   0  0  0 = 168
128  64   32  16   8   4  2  1
Binary form of 168 (Again, each 1 holds the value of the number below it.) 
0    0   0  0  0  0  0  0.  = 0 
128 64  32 16  8  4  2  1
0    0   0  0  0  0  0  1   = 1
128 64  32 16  8  4  2  1

So, 11000000.10101000.00000000.00000001 is the binary octet breakdown of 192.168.0.1. Believe it or not, this information actually is important.

Now, let's delve into the realm of subnet masks. The subnet mask is what actually will do all of the work of subnetting (read again, subnet mask). The subnet mask of an IP address is what tells the computer or router or whatever which part of your IP address belongs to your network and which part belongs to the hosts. Thus, a subnet mask of 255.255.255.0 tells your computer that the first three quads of your IP address belong to the network, and all of your hosts will be referenced with the last quad. This gives us a standard subnet mask of 255.255.255.0, with a possibility of 254 hosts in our network.

What? Even though I failed Algebra II, my math here does make sense. You are required to have a base network address and a broadcast address for every subnet. With the standard subnet mask and the default IP address in our example, the network address is 192.168.0.0 and the broadcast address is 192.168.0.255, which leaves us 192.168.0.1-254 for our hosts.

The basics are out of the way, so let's move on to the important stuff. How we subnet an IP range depends first on how large your assigned IP range is. If you are running a private network going through one static IP address, then your range is 192.168.xxx.xxx. In this case, there really is no reason to subnet unless you want to cut down on traffic and segment your LAN for whatever reason you feel is worth undertaking this task.

To begin, assume an IP address of 128.16.8.0 as a base. This is obviously a simplified example, but it's enough to convey the point of the exercise. Broken down into dotted octet notation, 128.16.8.0 is

10000000.00010000.00001000.00000000

The first step in subnetting is planning. How many hosts do you want per mask? Is there a chance that you may be expanding any or all of these subnets in the future? These are all things that have to be taken into consideration before you get set up everything, because the number of hosts you decide upon directly effects all the following steps. Say you want to have 20 hosts available per subnet. This means that you will need a minimum of 22 hosts, (remember, network address and broadcast have to be taken into account also). Let's zoom in on the last octet of our IP address.

0     0   0   0   0   0    0    0  (Remember this from above?)
128  64  32  16   8   4    2    1

So, if we want at least 22 hosts on each of our subnets, we are going to need the last five bits in our octet quad. This will give us a total available of 16+8+4+2+1 or 31 possible hosts, 29 if you don't count the network address and broadcast address. This leaves the first three bits of the octet for network addressing. This makes our subnet mask for the entire network 255.255.255.224. How did I come up with this? The positional notation values for the first three bits of our final octet, when added together, equal 224.

Network bits    Host bits
              |
128   64   32 |  16  8    4   2    1
              |
0       0     0  0   0    0   0    0            Network address for this subnet
                 0   0    0   0    1            IP Range of  128.16.8.0-31
                 0   0    0   1    0
                 0   0    0   1    1
                ....... and on till we get the numbers below
                 1    1   1    1   1    Broadcast address for this subnet
0       0     1  0   0    0   0    0            Network address for this subnet
                 0   0    0   0    1            IP Range of 128.16.8.32-63
                 0   0    0   1    0
                 0   0    0   1    1
                .......
                 1    1   1   1    1    Broadcast address for this subnet
0      1     0   0   0    0    0    0   Network address for this subnet
                 0   0    0    0    1   IP Range of 128.16.8.64-95
                 0   0    0    1    0
                 0   0    0    1    1
                .......
                 1    1   1    1    1   Broadcast address for this subnet
.............
.............
1      1     1   0   0    0   0   0             Network address for this subnet
                 0   0    0   0   1             IP Range of 128.16.8.224-255
                 0   0    0   1   0
                 0   0    0   1   1
                .......
                 1    1   1   1   1             Broadcast address for this subnet

Do you get the picture so far? Let's review. We have an IP address of 128.16.8.0. For our first subnet, we use a subnet mask of 255.255.255.224. This gives us hosts from 128.16.8.1 to 30, with 128.16.8.0 as the network address and 128.16.8.31 as the broadcast address. Our next subnet would be 128.16.8.32 with the same 31 hosts, including broadcast and network. The subnet following that would have an IP range of 128.16.8.64-95. The next would be 128.16.8.96-127, then 128-159, then 160-191, 192-223 and, finally, 224-255.

These results are a simplified example that doesn't include a lot of reasons why things happen. The following is an attempt on my part to explain how all this works. Your IP address and your subnet mask are bitwise "and"ed together (read boolean algebra). 0s hide the number, while 1s let it show through. The resulting binary number is the network address that falls out of the addition. Here's an example:

11000000.10101000.00000000.00000001     Network address (192.168.0.1)
11111111.11111111.11111111.11100000  +  Subnet Mask (255.255.255.224)
11000000.10101000.00000000.00000000     Network address (192.168.0.0 in this case)

This means anything to the right of the fourth bit in the final octet is a host address. This also means that the first three bits in the final octets are the network address. So, as outlined above, our first subnet would be 192.168.0.0-31. After that we would have to set the third bit from the left in the final octet, which changes the network address and results in our second subnet. :

11000000.10101000.00000000.00100000     Network address (192.168.0.32)
11111111.11111111.11111111.11100000  +  Subnet Mask (255.255.255.224)
11000000.10101000.00000000.00100000     Network address (192.168.0.32 in this case)

This breaks us down into the subnet IP range of 192.168.0.32-63. Are you catching on yet? Here is another quick example. In it, our next subnet would be what?

11000000.10101000.00000000.01000000     Network address (192.168.0.64)
11111111.11111111.11111111.11100000  +  Subnet Mask (255.255.255.224)
11000000.10101000.00000000.01000000     Network address (192.168.0.64 in this case)

which leaves 192.168.0.64-95 as our subnet IP ranges.

Hope I didn't confuse you terribly, but this is the main line of thinking for subnetting a network. Feel free to contact me with any questions. I might not be able to answer them off the top of my head, but I will do my best.

Load Disqus comments