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 0
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 01111111

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 10000000
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 10000000

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! Here is why:

  • 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 660 Lessons. More Lessons Added Every Week!
  • Content created by Rene Molenaar (CCIE #41726)

503 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 VJ,

    The 127.0.0.0/8 range is used for loopback addresses.

    127.0.0.0 is the network address and 127.255.255.255 is the broadcast address.

    You can ping any address in the 127.0.0.0/8 range except those two.

    Rene

  2. Hi Rene,

    What about the Range 0.0.0.0 ~0.255.255.255/8 ?? Please give a short defination of CIDR and VLSM . Is both are some ??

    br//
    zaman

  3. Hello Rahul

    You are correct that IP is a connectionless protocol. However the need to use TCP depends not on the connectionless nature of IP, but on the upper layer application being served. For web traffic, email or FTP for example, TCP (which creates sessions between hosts) must be used because the applications demand it.

    Other applications do not require the connection-oriented nature of TCP such as Voice and Video, which use RTP, or DNS which uses UDP. These layer 4 protocols do not create sessions nor do they provide any reliability.

    Some applications d

    ... Continue reading in our forum

  4. Hello Muhammad

    This is an excellent question and it shows that you are thinking deeply about these concepts, and that’s great. So, the IP protocol is a connectionless protocol. This does indeed mean that each packet is treated independently. In other words, each packet is sent and forgotten. There is no mechanism that will check to see if IP packets have arrived safely, in order and in a timely manner. (this is taken care of at higher layers of the OSI model, like TCP and Application)

    Now an IP packet can theoretically have a maximum size of just over 6500

    ... Continue reading in our forum

  5. Hello Francisco

    In general, it is best practice not to use routable IP addresses on the internal infrastructure. However, it is possible to use these addresses internally. In many cases you can get away with it and it will work fine. However, if a host on the inside is trying to reach a routable IP address of a web server on the Internet, for example, but that IP address also exists on the inside of the network, such a request will go to the inside address and not to the web server on the Internet.

    This is the primary reason for the segregation of IP address

    ... Continue reading in our forum

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