**Subnetting**

This is probably the most important section that needs to be memorized. In this section we will discuss subnetting and how we can use to break up our networks into groups. We already talked about how subnet masks are compared to IP addresses to define the network and host portion of the address. If we look at a default subnet mask for a class A address we get 255.0.0.0 which converted into binary is 11111111.00000000.0000000.000000 . If we compared it to the IP address 10.1.1.1 through binary ANDing we would get 10.0.0.0. This is defined as the network address and this address will always have all 0's in the host portion of the IP address.

We know that the network address is the address we get by doing a binary AND of the mask to the IP but there is another address that we must be conscious of and thats the broadcast address. The broadcast address is the last address in a subnet. When we discussed the network address we learned that when all of the host portion are 0's its considered the network address, well when all of the host portion are 1's then it is considered a broadcast address. Broadcasts are used to send messages to every device in a subnet. It is important to remember that neither the network or broadcast address can be used. This is an important thing to remember and I'll talk more about it throughout the rest of this section.

We know that the network address is the address we get by doing a binary AND of the mask to the IP but there is another address that we must be conscious of and thats the broadcast address. The broadcast address is the last address in a subnet. When we discussed the network address we learned that when all of the host portion are 0's its considered the network address, well when all of the host portion are 1's then it is considered a broadcast address. Broadcasts are used to send messages to every device in a subnet. It is important to remember that neither the network or broadcast address can be used. This is an important thing to remember and I'll talk more about it throughout the rest of this section.

## Subnetting a Class B Address

Lets take a look at a class B address, 172.16.1.1, with a subnet mask of 255.255.0.0. The first thing we can tell is that the first 2 octets are the network portion and the last 2 are the host portion. If we turn all the bits in the host portion off we get 172.16.0.0 which is the network address. If we turn on all the bits in the host portion we get 172.16.255.255 which is the broadcast address for that subnet. Like we discussed already, neither the network or broadcast address may be used in your network. So If you were addressing your devices you couldn't use 172.16.0.0 or 172.16.255.255 on any interface.

So far we have only discussed the default subnet mask for each class. Now we're going to discuss custom subnet masks. We'll continue using our last example of 172.16.1.1 but this time instead of using the default mask of 255.255.0.0 we're going to alter it. We alter the subnet mask by adding bits to it. For example 255.255.0.0 is 11111111.11111111.00000000.00000000 in binary, if we were to add 1 bit to the 3rd octet it would change the mask to 255.255.128.0. If we look at this in binary we get 11111111.11111111.10000000.00000000 and if we were to convert the 3rd octet into decimal we would get 128. What does this mask do? Well with what we already know if we did a binary ANDing of the subnet to the IP address it means that the network portion would get 1 more bit and the host portion would get 1 less, but actuality I've been lieing to you. When I said that there were 2 portions to an IP address I actually meant there are 3. The third portion is the subnet portion and I'll explain it in just a moment. So if we applied the 255.255.128.0 mask to the address what do we get?

Looks pretty similar to the last time we did a binary AND with the exception of the 3rd octet in the mask. That extra bit we turned on is known as the subnet portion of the address. The subnet portion will change depending on what subnet we are in. Currently we have been working with the subnet that starts with 172.16.0.0 which is the first subnet. Lets find the broadcast address of the first subnet. Well if we were to turn on all the bits in the host portion of the address we get 10101100.00010000.011111111.11111111 which converted into binary is 172.16.127.255. So we now know that 172.16.127.255 is the broadcast address for the 172.16.0.0 network with a 255.255.128.0 subnet mask. Notice that the subnet portion remains a 0. If we were to change the subnet portion to a 1 we would get 172.16.128.0 which translates to 10101100.00010000.10000000.00000000. Notice that the host portion is still all 0s, the only thing that has change is the subnet portion, this marks the beginning of the second subnet. Lets find the broadcast address of the second subnet. If we turn on all the host bits we get 10101100.00010000.11111111.11111111 which is 172.16.255.255. So the broadcast address for the 172.16.128.0 subnet is 172.16.255.255.

That's a lot of math to get through for subnetting, but there's a much easier way. I showed you this way to start with because this is whats happening behind the scenes and if you have any questions when it comes to subnetting then converting you IP and subnet mask to binary can help troubleshoot. As for the easy way, well lets take another example and go from there.

That's a lot of math to get through for subnetting, but there's a much easier way. I showed you this way to start with because this is whats happening behind the scenes and if you have any questions when it comes to subnetting then converting you IP and subnet mask to binary can help troubleshoot. As for the easy way, well lets take another example and go from there.

## Subnetting a Class C Address

We'll start this time with a class C address of 192.168.1.1 with a default mask of 255.255.255.0. This time instead of adding 1 bit, we will add 2. Adding 2 bits to the subnet mask gives us 255.255.255.192. There are a few formulas that we will use to find some key information. The information we need to find out is the number of subnets we are creating, the number of hosts that will fit in each subnet, and the range of addresses in each subnet. Lets go ahead and start with the number of subnets.

Well in our previous example we know that we created 2 subnets, and we know this because we went through the process of binary ANDing, but there is a simpler way. The following formula will give us the number of subnets we created, 2 to the power of the number of bits in the subnet portion of the address. Since we already know the previous example mask of 255.255.128.0 gave us 2 subnets lets go ahead and do our formula. The subnet portion of the address was the 1 bit we added to the 3rd octet, so 2^1 is 2 which is exactly how many subnets we created with it. Perfect, now let's calculate how many subnets we get with our new mask of 255.255.255.192. We added 2 bits to subnet mask which defines our subnet portion. So if we do 2^2 we get 4 subnets. Much easier than going through the long process of converting everything into binary.

Our next step is to find the number of hosts in each subnet. There is another formula that is similar to the last that we will use to find the number of hosts and that is 2 to the number of 0's in the subnet mask minus 2. In our subnet mask 255.255.255.192 there are 6 0's. If we plug this information into the formula we get 2^6 - 2 = 62. So each subnet can hold 62 hosts. Just a note, we subtract 2 at the end of the formula in order to account for the network and broadcast addresses that aren't useable.

The last thing we need to figure out is the range. This is the easiest thing to figure out, you simply take the number in the interesting octet in the subnet mask (the octet we are actually subnetting in) and subtract 256 by it. In our example we have 192 in the interesting octet, if we do 256 - 192 = 64. So our range of address are 64 addresses long.

Now that we have figured out our 3 important pieces of information what do we do with them? Well let's look at what we have. We know that we created 4 subnets each holding 62 hosts and each subnet has a range of address 64 addresses. Lets plug this information in and take a look at what we get. We'll start with the first subnet which is 192.168.1.0. Lets plug in our range of addresses which is 64, so our first subnet will start with 192.168.1.0 and end with 192.168.1.63.

Perfect, lets take a closer look at our first subnet. The first thing we see is that the first subnet contains 62 hosts which is what we calculated before. We know this because our address range is from 192.168.1.0 - 192.168.1.63, and if we subtract the network address (192.168.1.0) and the broadcast address (192.168.1.63) we get 62 addresses. The next thing we know is that there are 4 subnets, our first subnet ranges from 192.168.1.0 - 192.168.1.63. This means that our next subnet begins with the next IP address which is 192.168.1.64. If we count our address range we find that the second subnet ends with 192.168.1.127 (which is the broadcast address for the second subnet). Continuing, the logical next step is the next IP address after 192.168.1.128 which is our 3rd network address. Adding 64 addresses to this IP gives us 192.168.1.191 (broadcast address for subnet 3). The next address is the 4th and last subnet. It begins with 192.168.1.192 and ends with 192.168.1.255. This gives us 192.168.1.0, 192.168.1.64, 192.168.1.128, and 192.168.1.192 as our 4 network addresses. These addresses represent our 4 subnetworks. The following image illustrates the 4 subnets as well as their network and broadcast address.

## IP Subnet 0

There is a concept you should be aware of when subnetting however, and that's IP subnet 0. It used to be that the first and last subnet were not usable so in our last example the first and fourth octet wouldn't be usable giving us only 2 subnets. This is something to be very aware of during the CCNA examination. You can view whether or not ip subnet 0 is active by using the 'show running-configuration' command. This command will list 1 of 2 things, either ip subnet zero, or no ip subnet zero. If no IP subnet zero is displayed it means that you cannot use the first and last subnet. If ip subnet 0 is displayed in your running-config then you are allowed to use the first and last subnet.

## Subnetting a Class A Address

Lets do another example, but this time let's assume that ip subnet 0 is turned off. Lets do a class A address of 10.1.1.1. We will add a 5 bits to the default subnet mask creating a mask of 255.248.0.0. So the first thing we do is find the number of subnets we create. We do 2 to the number of bits in the subnet portion, so 2 to the 5th power - 2 (we subtract 2 since ip subnet 0 is turned on) and we get 30. So altogether we have 30 subnets. Next we need to find the number of hosts per subnet. To find this we do 2 to the number of 0's in the subnet mask minus 2. If we plug in the numbers we get 2^11-2 = 2046. So if IP subnet zero is off we have 30 subnets each with 2046 hosts per. Now lets find our range of addresses, we do 256-248 and we get 8.

So let's plug in all of this information. The first subnet is defined by the network address of 10.0.0.0 however since we are not able to use the first subnet due to the no ip subnet 0 command the first usable subnet is actually 10.8.0.0, if we add the address range, that gives us a broadcast address of 10.15.255.255 for the first subnet. This means that the second usable subnet begins with 10.16.0.0 and ends with 10.31.255.255. We're not going to go over every subnet as there are 30 of them. But the first usable subnets is 10.8.0.0 and the last usable subnet is 10.240.0.0. The first subnet that is unusable ranges from 10.0.0.0 to 10.7.255.255, the last unusable subnet ranges from 10.248.0.0 to 10.255.255.255.

## Subnetting a Class C Address

Let's go over one more example with our new way of defining subnets. Let's use another class C address, this time it will be 200.10.1.1. But this time let's add 3 bits to the default subnet mask of 255.255.255.0. This gives us a subnet mask of 255.255.255.224. This time let's assume IP subnet 0 is turned on. So the first thing we do is calculate the number of subnets, which we do with the formula 2 to the power of the number of bits in the subnet portion, or 2^3 = 8. So we get 8 subnets, now let's calculate the number of hosts per subnet. 2^5-2 = 30. So right now we have calculated that we have 8 subnets with 30 hosts a piece. The last piece of information we need to find out is the range of address, for that we do 256- 224 = 32. Perfect, so we have 8 subnets that hold 30 hosts each with a range of 32.

Our first subnet would begin with 200.10.1.0 ending with 200.10.1.31, the second subnet would begin with 200.10.2.32 and end with 200.10.2.63 and so on.

Our first subnet would begin with 200.10.1.0 ending with 200.10.1.31, the second subnet would begin with 200.10.2.32 and end with 200.10.2.63 and so on.

## Conclusion

So that takes us through subnetting, if we remember our 3 formulas we can subnet any address with ease. Honestly though the best way to subnet is to memorize each important fact about each subnet mask. The following image displays the # of subnets, # of hosts, and the range for each class B and C subnet mask.

I'll explain what CIDR is in the next session. If you can memorize this chart and be able to recreate it quickly and accurately it will be an invaluable tool for subnetting questions on the exam.