Subnetting in Binary

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.

Every host bit you “borrow” doubles the amount of subnets you can create.

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.

The smallest subnet you can create has a subnet mask of 255.255.255.252. This subnet has only 4 addresses, one network address, one broadcast address and two valid host IP addresses. This subnet is ideal for point-to-point links where we only require two usable IP addresses.

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

We're Sorry, Full Content Access is for Members Only...

If you like to keep on reading, Become a Member Now!

  • Learn any CCNA, CCNP and CCIE R&S Topic. Explained As Simple As Possible.
  • Try for Just $1. The Best Dollar You’ve Ever Spent on Your Cisco Career!
  • Full Access to our 800 Lessons. More Lessons Added Every Week!
  • Content created by Rene Molenaar (CCIE #41726)
535 Sign Ups in the last 30 days
satisfaction-guaranteed

  • 100% Satisfaction Guaranteed!
  • You may cancel your monthly membership at any time.
  • No Questions Asked!

Tags:


Forum Replies

  1. Hi Rene,
    Very Good article for Beginners.

    Thanks,
    Srini

  2. Hi,
    Under Class A subnetting section, the subnet mask should be 255.240.0.0 instead of 255.0.0.0.
    Typo I guess.

  3. Hi Sirui,

    I just glanced over it but couldn’t find that 225.0.0.0, where do you see it? :slight_smile:

    Rene

  4.  

    networklessons and Rene Molenaar = wonderful

  5. 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

14 more replies! Ask a question or join the discussion by visiting our Community Forum