Saturday, January 22, 2011

Retro Post: An Introduction to Subnetting

Back in about 2003/4 I wrote a tutorial on subnetting.  I posted it up on a couple forums that I frequented at the time and then forgot about it.  I came across it about again about a year ago, and then today I actually dug it up to reference it in a post I was making.

Since its mine, I decided that I would post it up here now.  I think it's fun to go back to when I was getting my start in Networking and see some of the sorts of things I wrote back then.  So without further ado, get into the time machine and enjoy this old, very basic tutorial.

I'm going to assume here that you already know how binary works, and can perform some simple conversion either in your head or on paper. I'm also assuming that you know the difference between a class A, B, and C IP address.

The purpose of a subnetting is to make more logical divisions (subnetworks) out of a given IP address range. In a class A network, there are 126 useable networks, and 16777214 hosts per network. Kinda ridiculous and definitely not very useful. To address this problem the practice of subnetting was put into use. Every host on every network must have an appropriate subnet mask or it can not communicated on the network. To acheive the additional networks, bits are 'borrowed' from the host portion of the address.

Looking at IP addresses in the dotted decimal format, the network vs. hosts bits are broken down like this:

class A -- N.H.H.H Class B -- N.N.H.H class C -- N.N.N.H

The network number for a network always has the hosts bits turned off (0). As well, the address for every host on the network is when all host bits are turned on (1).

So, let's take a look at what exactly an IP address is. An IP address is a 32 bit binary string that is used to identify a host on a network. For readability's sake, this string is commonly represented as a dotted decimal quad that looks something like:

But keep in mind, this is what it really looks like:


Well, this doesnt look fun at all now does it. That is what IP looks like to a router or a host, so we must too.

Now let's look at a default subnet mask for our above example class C IP address:

Which in binary is:


To get the network address from these two numbers, the numbers are AND'ed together






Convert this into our dotted decimal notation and we have:

This number is used by routing protocols to identify this network among other network on a LAN or WAN. But what does this all mean? This means that our example IP belongs to the 132nd host on the network it also means that there are a possible 254 hosts on that same network.

But, what if the subnetmask was not Let's say the subnet mask is instead. Performing the AND'ing again we get:






Whoa! In our dotted decimal that makes as the network number! So now our address is the 4th host on network, out of a possible 126. And because this is now a subnetted address, the network is actually the second of two subnetworks.

As mentioned above, a class C address uses the final 8 bits to represent the host portion of an address. With our example subnet of we borrowed 2 bits, giving us two usable subnets. The formula to figure out the useable hosts or subnets it to raise 2 to the number of bits available and minus 2 ((2^n)-2)). With our example we have:




Giving us 2 useable subnets (the first is the network number, the last is the broadcast, hence the minus 2. As well, when subnetting you may not borrow 1 bit, or leave 1 bit for the host portion. At least two bits must occupy either network or host portion at all times).

For the hosts we have 6 bits:




62 useable host addresses per subnet. Now wait a moment... With our default subnet we had one network with two hundred and fifty-four hosts, now we have two networks with sixty-two hosts per subnetwork? Where did the other 132 hosts addresses go?!?! This is the downside to subnetting. While you lose available host addresses, the benefits of subnetting far outweigh this and is well beyond how much detail I want to go into =Þ.

Let's looks at a little more complicated example. We want to find the network number, host number for this IP, total number of subnets, and total number hosts:



first we do a binary AND:






Into dotted decimal we have a network number of This means that our host is number 5520 on this network! To finish the question, it's a class A network so we borrowed 10 bits:



1022 Subnets

And we left 14 bits in the host portion:



16382 Hosts

Now that we can find a subnet, let's make some. Let's say we want to subnet the class B address of into a minimum of 325 subnetworks. Using the above formula:

2^-2 = 254 too low

(2^9)-2 = 512 OK

So if we are to borrow 9 bits then our subnet mask is But let's look at how we arrive at our network numbers by using binary again. We start with the address of, which gives the following meaning to the bits:


Because this is an assigned address, we cannot change the first two octets. knowing those are constant we have a subnet range of 172.15.0 - 172.15.255 . in binary this is:

172.15.00000000 - 172.15.11111111

To get get our subnetwork numbers we count up the subnetwork bits in binary one at a time:

Binary -- Decimal

172.15.000000000|0000000 -- (unusable)
172.15.000000001|0000000 --
172.15.000000010|0000000 --
172.15.000000011|0000000 --
172.15.000000100|0000000 --
172.15.000000101|0000000 --


172.15.111111011|0000000 --
172.15.111111100|0000000 --
172.15.111111101|0000000 --
172.15.111111110|0000000 --
172.15.111111111|0000000 -- (unusable)

And likewise, in any given subnetwork we count up each host bit to get the host numbers:

Binary -- Decimal

172.15.010101011|0000000 (Network)


172.15.010101011|111111 (Broadcast)

And that is how we subnet!

No comments:

Post a Comment