Lesson Contents
In this lesson we’ll take a look how to calculate subnets by playing with binary numbers. This lesson is important to understand how everything works “under the hood”.
Class C Subnetting
Let’s start with a simple class C network and play with some binary numbers:
192.168.1.0 (with the default subnet mask 255.255.255.0)
In binary it looks like this:
192 | 168 | 1 | 0 |
11000000 | 10101000 | 00000001 | 00000000 |
In my IPv4 Introduction I explained that a class C network has 3 bytes for the network part and one byte for hosts:
Network | Network | Network | Hosts |
192 | 168 | 1 | 0 |
The network device knows which part is the network part and host part because of the subnet mask. The default subnet mask for network 192.168.1.0 is 255.255.255.0.
Here’s what that looks like in binary:
IP address (decimal) | 192 | 168 | 1 | 0 |
IP address (binary) | 11000000 | 10101000 | 00000001 | 00000000 |
Subnet mask (decimal) | 255 | 255 | 255 | 0 |
Subnet mask (binary) | 11111111 | 11111111 | 11111111 | 00000000 |
The 1’s in the subnet mask indicate the network address part, the 0’s indicate the host part. Let me remove the decimal numbers so you can see the network address and subnet mask next to each other:
IP address | 11000000 | 10101000 | 00000001 | 00000000 |
Subnet mask | 11111111 | 11111111 | 11111111 | 00000000 |
In other words, the subnet mask tells us that the first 24 bits (192.168.1) are the network part and the remaining 8 bits (.0) are for hosts. From now on I will mark the “network part” in red so you can clearly see the seperation between the network and host bits.
Let’s write down these 8 host bits:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
What’s the highest value you can create with these 8 bits? Let’s set all of them to 1:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
128 + 64 + 32 + 16 + 8 + 4 + 2 +1 = 255
with 8 bits the highest value we can create is 255, does this mean we can have 255 hosts in this network? The answer is no because for every network there are 2 addresses we can’t use:
Network address: this is the address where all the host bits are set to 0.
192 | 168 | 1 | 0 |
11000000 | 10101000 | 00000001 | 00000000 |
Broadcast address: this is the address where all host bits are set to 1.
192 | 168 | 1 | 255 |
11000000 | 10101000 | 00000001 | 11111111 |
Alright so let’s take 255 – 2 = 253. Does this mean we can have a maximum of 253 hosts on our network?
The answer is still no! I messed with your head because the highest value you can create with 8 bits is not 255 but 256. Why? Because you can also use a value of “0”.
This means we can use 192.168.1.1 – 192.168.1.254 as IP addresses for our hosts.
Great! So now you have seen what a network looks like in binary, what the subnet mask does, what the network and broadcast addresses are and that we can fit in 254 hosts in this Class C network.
Now let’s say I don’t want to have a single network where I can fit In 254 hosts, but I want to have 2 networks? Is this possible? It sure is! Basically what we are doing is taking a Class C network and chop it in 2 pieces, and this is what we call subnetting. Let’s take a look at it in binary:
IP address (decimal) | 192 | 168 | 1 | 0 |
IP address (binary) | 11000000 | 10101000 | 00000001 | 00000000 |
Subnet mask (decimal) | 255 | 255 | 255 | 0 |
Subnet mask (binary) | 11111111 | 11111111 | 11111111 | 00000000 |
The subnet mask defines the size of the network so if we want to create more subnets, we’ll have to “borrow” bits from the host part.
For every bit you borrow you can double the number of subnets, by borrowing 1 bit we create 2 subnets out of this single network. There are 8 host-bits so if we steal one to create more subnets this means we have only 7 bits left for hosts. Let’s do this, here’s what the new subnet mask will look like:
255 | 255 | 255 | 128 |
11111111 | 11111111 | 11111111 | 10000000 |
The first 24 bits are the same and we borrow the first bit from the 4th octet. This one has a value of 128 so our subnet mask becomes 255.255.255.128.
So what do our new subnets look like? Let’s zoom in on the 7 bits that we have left for our hosts:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
N/A | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
We can’t use the first bit since it’s used for the network address now thanks to our subnet mask. What’s the largest decimal number we can create with these 7 bits?
64 + 32 + 16 + 8 + 4 + 2 + 1 = 127. Don’t forget that we start counting at 0 so in total we have 128 addresses.
Our original class C network has now been subnetted into two subnets that each have 128 addresses. What do the two subnets look like?
Let’s work it out in binary:
Subnet #1
We start with 192.168.1.0 and the subnet mask is 255.255.255.128:
IP address | 192 | 168 | 1 | 0 |
11000000 | 10101000 | 00000001 | 00000000 | |
Subnet mask | 255 | 255 | 255 | 128 |
11111111 | 11111111 | 11111111 | 10000000 |
Network address:
The network address has all host bits set to 0 so that’s why it is 192.168.1.0:
192 | 168 | 1 | 0 |
11000000 | 10101000 | 00000001 | 00000000 |
First usable host IP address:
The first usable host IP address is the one that comes after the network address, this will be 192.168.1.1:
192 | 168 | 1 | 1 |
11000000 | 10101000 | 00000001 | 00000001 |
Last usable host IP address:
The last IP address we can use for a host is the one before the broadcast address so this will be 192.168.1.126:
192 | 168 | 1 | 126 |
11000000 | 10101000 | 00000001 | 01111110 |
Broadcast address:
The broadcast address has all host bits set to 1 so the broadcast address we have is 192.168.1.127:
192 | 168 | 1 | 127 |
11000000 | 10101000 | 00000001 | 01111111 |
Subnet #2
The first subnet ended at 192.168.1.127 so we just continue with the next subnet at 192.168.1.128:
IP address | 192 | 168 | 1 | 128 |
11000000 | 10101000 | 00000001 | 10000000 | |
Subnet mask | 255 | 255 | 255 | 128 |
11111111 | 11111111 | 11111111 | 10000000 |
Network address:
The network address has all host bits set to 0 so that’s why it is 192.168.1.128:
192 | 168 | 1 | 128 |
11000000 | 10101000 | 00000001 | 10000000 |
First usable host IP address:
The first usable host IP address is the one that comes after the network address, this will be 192.168.1.129:
192 | 168 | 1 | 129 |
11000000 | 10101000 | 00000001 | 10000001 |
Last usable host IP address:
The last IP address we can use for a host is the one before the broadcast address so this will be 192.168.1.254:
192 | 168 | 1 | 254 |
11000000 | 10101000 | 00000001 | 11111110 |
Broadcast address:
The broadcast address has all host bits set to 1 so the broadcast address we have is 192.168.1.255:
192 | 168 | 1 | 255 |
11000000 | 10101000 | 00000001 | 11111111 |
That’s it! That’s the first network we just subnetted in 2 subnets and we found out what the network and broadcast addresses are, and what IP addresses we can use for hosts.
Let me show you another one, we take the same class C 192.168.1.0 network but now we want to have 4 subnets. For every host-bit we borrow we can double the number of subnets we can create, so by borrowing 2 host bits we can create 4 subnets.
What will the new subnet mask be? Let’s take a look at it in binary:
255 | 255 | 255 | 192 |
11111111 | 11111111 | 11111111 | 11000000 |
Calculate it from binary to decimal: 128+64 = 192.
The new subnet mask will be 255.255.255.192. With this subnet mask we only have 6 host bits to play with.
Let’s write down the subnets…
Subnet #1
We start with 192.168.1.0 and the subnet mask is 255.255.255.192:
IP address | 192 | 168 | 1 | 0 |
11000000 | 10101000 | 00000001 | 00000000 | |
Subnet mask | 255 | 255 | 255 | 192 |
11111111 | 11111111 | 11111111 | 11000000 |
Network address:
The network address has all host bits set to 0 so that’s why it is 192.168.1.0:
192 | 168 | 1 | 0 |
11000000 | 10101000 | 00000001 | 00000000 |
First usable host IP address:
The first usable host IP address is the one that comes after the network address, this will be 192.168.1.1:
192 | 168 | 1 | 1 |
11000000 | 10101000 | 00000001 | 00000001 |
Last usable host IP address:
The last IP address we can use for a host is the one before the broadcast address so this will be 192.168.1.62:
192 | 168 | 1 | 62 |
11000000 | 10101000 | 00000001 | 00111110 |
Broadcast address:
The broadcast address has all host bits set to 1 so the broadcast address we have is 192.168.1.63:
192 | 168 | 1 | 63 |
11000000 | 10101000 | 00000001 | 00111111 |
Subnet #2
The first subnet ended at 192.168.1.63 so we just continue with the next subnet at 192.168.1.64:
IP address | 192 | 168 | 1 | 64 |
11000000 | 10101000 | 00000001 | 01000000 | |
Subnet mask | 255 | 255 | 255 | 192 |
11111111 | 11111111 | 11111111 | 11000000 |
Network address:
The network address has all host bits set to 0 so that’s why it is 192.168.1.64:
192 | 168 | 1 | 64 |
11000000 | 10101000 | 00000001 | 01000000 |
First usable host IP address:
The first usable host IP address is the one that comes after the network address, this will be 192.168.1.65:
192 | 168 | 1 | 65 |
11000000 | 10101000 | 00000001 | 01000001 |
Last usable host IP address:
The last IP address we can use for a host is the one before the broadcast address so this will be 192.168.1.126:
192 | 168 | 1 | 126 |
11000000 | 10101000 | 00000001 | 01111110 |
Broadcast address:
The broadcast address has all host bits set to 1 so the broadcast address we have is 192.168.1.127:
192 | 168 | 1 | 127 |
11000000 | 10101000 | 00000001 | 01111111 |
Subnet #3
The second subnet ended at 192.168.1.127 so we just continue with the next subnet at 192.168.1.128:
IP address | 192 | 168 | 1 | 128 |
11000000 | 10101000 | 00000001 | 10000000 | |
Subnet mask | 255 | 255 | 255 | 192 |
11111111 | 11111111 | 11111111 | 11000000 |
Network address:
The network address has all host bits set to 0 so that’s why it is 192.168.1.128:
192 | 168 | 1 | 128 |
11000000 | 10101000 | 00000001 | 10000000 |
First usable host IP address:
The first usable host IP address is the one that comes after the network address, this will be 192.168.1.129:
192 | 168 | 1 | 129 |
11000000 | 10101000 | 00000001 | 10000001 |
Last usable host IP address:
The last IP address we can use for a host is the one before the broadcast address so this will be 192.168.1.190:
192 | 168 | 1 | 190 |
11000000 | 10101000 | 00000001 | 10111110 |
Broadcast address:
The broadcast address has all host bits set to 1 so the broadcast address we have is 192.168.1.191:
192 | 168 | 1 | 191 |
11000000 | 10101000 | 00000001 | 10111111 |
Subnet #4
The third subnet ended at 192.168.1.191 so we just continue with the next subnet at 192.168.1.192:
IP address | 192 | 168 | 1 | 192 |
11000000 | 10101000 | 00000001 | 11000000 | |
Subnet mask | 255 | 255 | 255 | 192 |
11111111 | 11111111 | 11111111 | 11000000 |
Network address:
The network address has all host bits set to 0 so that’s why it is 192.168.1.192:
192 | 168 | 1 | 192 |
11000000 | 10101000 | 00000001 | 11000000 |
First usable host IP address:
The first usable host IP address is the one that comes after the network address, this will be 192.168.1.193:
192 | 168 | 1 | 193 |
11000000 | 10101000 | 00000001 | 11000001 |
Last usable host IP address:
The last IP address we can use for a host is the one before the broadcast address so this will be 192.168.1.254:
192 | 168 | 1 | 254 |
11000000 | 10101000 | 00000001 | 11111110 |
Broadcast address:
The broadcast address has all host bits set to 1 so the broadcast address we have is 192.168.1.255:
192 | 168 | 1 | 255 |
11000000 | 10101000 | 00000001 | 11111111 |
There we go! We just chopped down our 192.168.1.0 class C network into 4 subnets! If you understand everything up to this point…great job! Does this look like a lot of work? Honestly…yes it is!
In the next lesson I will show you some tricks to calculate Class C, B and even A subnets without touching any binary numbers….and even better, you don’t have to write stuff down. You can do it off the top of your head.
The reason I don’t show you this right away is that you need to understand what is happening “under the hood” before you can apply some shortcuts.
Class B Subnetting
Okay so we have played enough with Class C networks, let’s try a Class B network. You’ll see that it’s exactly the same thing.
Let’s take the 172.16.0.0 Class B network with subnet mask 255.255.0.0 and create 2 subnets out of it:
IP address | 172 | 16 | 0 | 0 |
10101100 | 00010000 | 01100100 | 00000000 | |
Subnet mask | 255 | 255 | 0 | 0 |
11111111 | 11111111 | 00000000 | 00000000 |
If we want to create more subnets we need to borrow bits from the host part. For every bit you borrow you can double the number of subnets, by borrowing 1 bit we create 2 subnets out of this single network. Now the difference with a Class C network is that we have more host bits to play with, that’s all.
What will the new subnet mask be? Let’s take a look at it in binary:
255 | 255 | 128 | 0 |
11111111 | 11111111 | 10000000 | 00000000 |
As you can see the net subnet mask will be 255.255.128.0 and we have 7+8 = 15 host bits left to play with. How “big” are these 2 subnets? Well we have 15 bits so let’s take a look
N/A | 16384 | 8192 | 4096 | 2048 | 1024 | 512 | 256 | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
N/A | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
16384 + 8192 + 4096 + 2048 + 1024 + 512 + 256 + 128 + 64 + 32 + 16 + 8 + 4 + 2 +1 = 32767.
Don’t forget about the 0! So the highest value you can create with 15 bits is 32768.
If you want to know how many usable host IP addresses you have, you take 32768 – 2 (because of the network and broadcast address).
32768 – 2 = 32766 usable host IP addresses. That’s a lot of computers/laptops/servers!
A much faster way to calculate this is by using the “powers of 2” that I explained earlier:
2 to the power of 15 (or 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2) = 32768.
32768 minus 2 (network + broadcast address) = 32766.
Does this make sense to you? Good! Keep in mind that in the next lesson I will show you how to solve these subnetting questions without touching any binary, you just need to make sure you understand the math behind all this.
Let’s calculate what the subnets look like.
Subnet #1:
By applying the new subnet mask we only have 15 host bits to play with.
IP address | 172 | 16 | 0 | 0 |
10101100 | 00010000 | 00000000 | 00000000 | |
Subnet mask | 255 | 255 | 128 | 0 |
11111111 | 11111111 | 10000000 | 00000000 |
Network address:
The network address has all host bits set to 0 so that’s why it is 172.16.0.0.
172 | 16 | 0 | 0 |
10101100 | 00010000 | 00000000 | 00000000 |
First usable host IP address:
The first usable host IP address is the one that comes after the network address so this is 172.16.0.1.
172 | 16 | 0 | 1 |
10101100 | 00010000 | 00000000 | 00000001 |
Last usable host IP address:
The last IP address we can use for a host is the one before the broadcast address so this will be 172.16.127.254
172 | 16 | 127 | 254 |
10101100 | 00010000 | 01111111 | 11111110 |
Broadcast address:
The broadcast address has all host bits set to 1 so the broadcast address we have is 172.16.127.255.
172 | 16 | 127 | 255 |
11000000 | 10101000 | 01111111 | 11111111 |
Subnet #2
The first subnet ended at 172.16.127.255 so we just continue with the next available address which is 172.16.128.0.
IP address | 172 | 16 | 128 | 0 |
10101100 | 00010000 | 10000000 | 00000000 | |
Subnet mask | 255 | 255 | 128 | 0 |
11111111 | 11111111 | 10000000 | 00000000 |
Network address:
The network address has all host bits set to 0 so that’s why it is 172.16.128.0.
172 | 16 | 128 | 0 |
10101100 | 00010000 | 10000000 | 00000000 |
First usable host IP address:
The first usable host IP address is the one that comes after the network address so this is 172.16.128.1.
172 | 16 | 128 | 1 |
10101100 | 00010000 | 10000000 | 00000001 |
Last usable host IP address:
The last IP address we can use for a host is the one before the broadcast address so this will be 172.16.255.254
172 | 16 | 255 | 254 |
10101100 | 00010000 | 11111111 | 11111110 |
Broadcast address:
The broadcast address has all host bits set to 1 so the broadcast address we have 172.16.255.255.
172 | 16 | 255 | 255 |
10101100 | 10101000 | 11111111 | 11111111 |
Alright so we just subnetted this 172.16.0.0 class B network into 2 subnets, you are doing the exact same thing as before but now you have more bits to play with…
Class A Subnetting
Subnetting a class B network wasn’t that hard right? Let’s try a Class A network and see what happens:
Let’s take the 10.0.0.0 Class A network with subnet mask 255.0.0.0 and create at least 12 subnets out of it:
IP address | 10 | 0 | 0 | 0 |
00001010 | 00000000 | 00000000 | 00000000 | |
Subnet mask | 255 | 0 | 0 | 0 |
11111111 | 00000000 | 00000000 | 00000000 |
If we want to create more subnets we need to borrow bits from the host part. For every bit you borrow you can double the number of subnets (remember the “powers of 2” ?), by borrowing 4 bits we can create 16 subnets out of this single network. 3 bits would not be enough because we can only create 8 subnets then.
What will the new subnet mask be? Let’s take a look at it in binary:
255 | 240 | 0 | 0 |
11111111 | 11110000 | 00000000 | 00000000 |
As you can see the subnet mask will be 255.240.0.0 and we have 4+8+8 = 20 host bits left to play with.
How “big” are these 16 subnets? Well we have 20 bits so let’s just use the “powers of 2” to solve this question:
2 to the power of 20 = 1.048.576
If you want to know to know how many usable host IP addresses you have, you take 1.048.576– 2 (because of the network and broadcast address).
1.048.576– 2 = 1.048.574 usable host IP addresses. That’s lots and lots of computers/laptops/servers!
Let’s calculate what the subnets look like, I’m not going to do all of them, just 3 of them. By now you should be familiar what the math looks like
Subnet #1
By applying the new subnet mask we only have 20 host bits to play with.
IP address | 10 | 0 | 0 | 0 |
00001010 | 00000000 | 00000000 | 00000000 | |
Subnet mask | 255 | 240 | 0 | 0 |
11111111 | 11110000 | 00000000 | 00000000 |
Network address:
The network address has all host bits set to 0 so that’s why it is 10.0.0.0.
10 | 0 | 0 | 0 |
00001010 | 00000000 | 00000000 | 00000000 |
First usable host IP address:
The first usable host IP address is the one that comes after the network address so this is 10.0.0.1.
10 | 0 | 0 | 1 |
00001010 | 00000000 | 00000000 | 00000001 |
Last usable host IP address:
The last IP address we can use for a host is the one before the broadcast address so this will be 10.15.255.254.
10 | 15 | 255 | 254 |
00001010 | 00001111 | 11111111 | 11111110 |
Broadcast address:
The broadcast address has all host bits set to 1 so the broadcast address we have 10.15.255.255.
10 | 15 | 255 | 255 |
00001010 | 00001111 | 11111111 | 11111111 |
Subnet #2
The broadcast address of subnet #1 was 10.15.255.255 so our next subnet starts at 10.16.0.0
IP address | 10 | 16 | 0 | 0 |
00001010 | 00010000 | 00000000 | 00000000 | |
Subnet mask | 255 | 240 | 0 | 0 |
11111111 | 11110000 | 00000000 | 00000000 |
Network address:
The network address has all host bits set to 0 so that’s why it is 10.16.0.0.
10 | 16 | 0 | 0 |
00001010 | 00010000 | 00000000 | 00000000 |
First usable host IP address:
The first usable host IP address is the one that comes after the network address so this is 10.16.0.1.
10 | 16 | 0 | 1 |
00001010 | 00010000 | 00000000 | 00000001 |
Last usable host IP address:
The last IP address we can use for a host is the one before the broadcast address so this will be 10.31.255.254.
10 | 31 | 255 | 254 |
00001010 | 00011111 | 11111111 | 11111110 |
Broadcast address:
The broadcast address has all host bits set to 1 so the broadcast address we have 10.31.255.255.
10 | 31 | 255 | 255 |
00001010 | 00011111 | 11111111 | 11111111 |
Subnet #3
The broadcast address of subnet #1 was 10.31.255.255 so our next subnet starts at 10.32.0.0
IP address | 10 | 32 | 0 | 0 |
00001010 | 00100000 | 00000000 | 00000000 | |
Subnet mask | 255 | 240 | 0 | 0 |
11111111 | 11110000 | 00000000 | 00000000 |
Network address:
The network address has all host bits set to 0 so that’s why it is 10.32.0.0.
10 | 32 | 0 | 0 |
00001010 | 00100000 | 00000000 | 00000000 |
First usable host IP address:
The first usable host IP address is the one that comes after the network address so this is 10.32.0.1
10 | 32 | 0 | 1 |
00001010 | 00100000 | 00000000 | 00000001 |
Last usable host IP address:
The last IP address we can use for a host is the one before the broadcast address so this will be 10.47.255.254.
10 | 47 | 255 | 254 |
00001010 | 00101111 | 11111111 | 11111110 |
Broadcast address:
The broadcast address has all host bits set to 1 so the broadcast address we have 10.47.255.255.
10 | 47 | 255 | 255 |
00001010 | 00101111 | 11111111 | 11111111 |
Alright those are the first three subnets, we can keep going like this but I think you get the idea. It might be a good exercise for you to calculate subnet 4,5 and 6 perhaps.
I showed you how to do all of this in binary and by now you should have a good understanding how it works “under the hood”. In the next lesson I’ll show you how to do subnetting a whole lot faster, and even off the top of your head!
Hi Rene,
Very Good article for Beginners.
Thanks,
Srini
Hi,
Under Class A subnetting section, the subnet mask should be 255.240.0.0 instead of 255.0.0.0.
Typo I guess.
Hi Sirui,
I just glanced over it but couldn’t find that 225.0.0.0, where do you see it?
Rene
networklessons and Rene Molenaar = wonderful
Hello Rene, This is great work that you are doing and even if I find it difficult to grasp the concept, I have a feeling that something is happening to my understanding :). Your examples are clear to a point but when I try using my own values, ie other addresses I get lost rather fast :(.
For instance, I have the following address: 120.48.7.104 and 255.255.255.248. I am required to find out 1. Network address. 2.first and last usable addresses and the broadcast address. I figured out that the first address must be the following: 120.48.7.103 and 120.4.7.104 as
... Continue reading in our forum