# Binary, Subnetting, and Summarization.

Before we continue looking at routing and routing protocols I want to go back to IP addresses and dive deeper, this stuff is important when you want to understand routing! Before we start calculating subnets and talk about IP addressing, let’s first check out some basics of binary calculations. We are all used to work with decimal numbers where we count from 1 till 10. This is easy because we have 10 fingers so we don’t have to count off the top of our head.

In the binary system, we only work with 0 or 1. 0 = Off

1 = On The bit on the far left side is called the most significant bit (MSB) because this bit has the highest value. The bit on the far right side is called the least significant bit (LSB) because this one has the lowest value. So how do we convert decimal numbers into binary? Let me show you an example: If we want the decimal number “0” in binary this means we leave all the bits “off”.

Let’s take the number 178 and turn it into binary, just start at the left and see which bits “fit in” to make this number. 128 + 32 + 16 + 2 = 178. Just one more! Let’s turn 255 into binary. 128 + 64 + 32 + 16 + 8 + 4 + 2 +1 = 255

As you can see 255 is the highest decimal number you can create when you have 8 bits to play with.

As you can see, whenever you add a bit, the decimal value doubles. For example: 2,4,8,16,32,64,128,256,512,1024,2048 and so on. This is called the “powers of 2”.

Before we start calculating subnets, the first thing we need to do is take a look at what subnets and IP addresses are.

This is a good moment to create your own “cheat sheet” . Take a piece of paper and write down the 8 bits for yourself.

An IP address is a numeric value that you configure on every device in a network, think about computers, laptops, servers but also networking equipment like routers, firewalls and switches. The IP address identifies every device with a “unique” number. Devices within the

same IP subnet are able to communicate without using a router. Let’s take a look at some of the terminology you might encounter when we talk about IP addresses:

IP addresses are 32 bits, divided in 4 “blocks” also known as 4 bytes or octets. Every byte has 8 bits. 4×8 = 32 bits.

There are many ways to write down an IP address: Decimal is what we are used to work with, as this is the way you normally configure an IP address in operating systems like Microsoft Windows, Linux or most networking equipment. Hexadecimal you won’t see often but for example you might encounter this in the windows registry.

IP addresses are hierarchical unlike non-hierarchical addresses like MAC-addresses. This has some advantages, you can use a lot of IP addresses (with 32 bits the biggest number you

can create is 4.3 billion or to be precise 4,294,967,296). The advantage of having a hierarchical model is needed for routing, imagine that every router on the planet would need to know every IP address on the planet. Routing wouldn’t be very efficient that way… A better solution is a hierarchical model where we use “network”, “subnet” and “hosts”.

Try to compare this to phone numbers: The complete phone number is 0031-013-1234567. IP addresses use a similar hierarchical structure.

IMPORTANT: every subnet has 1 network address!

The network address is a unique identification of the network. Every device within the same subnet shares this network address in its IP address, for example:

192.168.100.1

192.168.100.2

192.168.100.3

192.168.100. is the network address and .1, .2 and .3 are host addresses. The IP address will tell you in what subnet they are located. The network address has to be the same for all the hosts, the host part has to be unique. When the Internet was invented they created

different “classes” of networks each with a different size. At this moment there are 3 classes that are important to us: Class A:

Back to our network addresses, let’s take a look at Class A. The first bit always has to be a

1. This leaves us 7 bits to “play” with. The lowest value you can create by changing all bits to “0” is 0. By changing all 7 bits to “1” you get 127.

64 + 32 + 16 + 8 + 4 + 2 + 1 = 127.

As you can see the Class A range is between 0. and 127.

Class B:

For a class B network the first bit has to be a 1. The second bit has to be a 0. 128 + 32 + 16 + 8 + 4 + 2 +1 = 191

As you can see class B networks always start with 128. and the last network is 191. Class C:

For a class C network the first bit has to be a 1, the second bit a 1 and the third a 0. 128 + 64 = 192

128 + 64 + 16 + 8 + 4 + 2 + 1 = 223

As you can see Class B networks start at 192. and the last network is 223. Class D and E:

There is also a class D for multicast traffic which starts at 224. and ends at 239. Class E is for “research usage”. We are not going to use these classes for our binary calculations.

### Class A Addressing:

A class A network has 1 byte reserved for the network address which means the other 3 bytes are left for hosts. This means we have more than a couple of networks and every network can have a lot of hosts (how to determine how many hosts each network has we will see later!). If we look at the IP address 53.21.43.63 then “53” is the network address and “21.43.63” is the host address, all machines on this subnet will have the “53” as network address. ### Class B Addressing: A class B network has 2 bytes reserved for the network address which means the other 2 bytes are left for hosts. This means we have even more networks but fewer hosts per network compared to class A.

For example, 172.16.100.68, the network address is 172.16. and the host address is 100.68. ### Class C Addressing:

A class C network has 3 bytes reserved for the network address which means the other byte is left for hosts. Now we have a lot of networks but only a few hosts per network. Another example, 192.168.200.53, the network address is 192.168.200. and the host address is .53. Let’s take a Class C network and take a good look at it, so we can play around with binary numbers. For example: 192.168.1.0 In binary it looks like this:  In the previous chapter I explained that a class C network consists of 3 bytes for the network part, and one byte for hosts:

Now the question is…how does a network device know which part is the network-part, and which side is the host-part? Is it because it’s a Class C network? Is it some secret rule that everyone just knows about?

The answer is no, we use something called a subnet mask! For this network, it would be the following subnet mask:

255.255.255.0 Now what does this subnet mask exactly do? The word “mask” might tell you that it must mean that it’s hiding something…but that is not the case, and to show you the answer we have to look at some binary numbers:

The subnet mask will specify which part of the IP address is the network-part and which part is the host-part. The 1 means it’s the network-part, the 0 means the host-part. To clarify this let me just take the binary numbers. The subnet mask tells you the first 24 bits are the network-address and the 8 bits that are left we can use for hosts.

For our 192.168.1.0 example this means 24 bits are reserved for network and 8 bits are reserved for hosts.

Let’s write down those 8 host-bits:  What’s the highest value you can create with 8 bits? Let’s have a look: 128 + 64 + 32 + 16 + 8 + 4 + 2 +1 = 255

Cool! So now we know that 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:

1. Network address: this is the address where all the host bits are set to 0. 1. Broadcast address: this is the address where all the host bits are set to 1. IMPORTANT: The network address has all hosts bits set to 0! The broadcast address has all host bits set to 1!

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

Does this make your head spin? Let’s take a look at our 192.168.1.0 network in binary: The network address has all host bits set 0, so in decimal this is 0.

The broadcast address has all host bits set to 1, so in decimal this is 255.

This means everything in between we can use for hosts, 1 – 254 so that’s 254 valid IP addresses we can use to configure hosts!

IMPORTANT: don’t start counting at “1”, but start counting at “0”. The “0” is a valid number.

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:

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. There are 8 host-bits so if we steal one to create more subnets this means we have only 7 bits left for hosts.

What will the new subnet mask be? Let’s take a look at it in binary: The first 24 bits are the same so we only have to look at the 4th octet, let’s write down those bits:  Calculate it back to decimal and you’ll have 128. The subnet mask will be 255.255.255.128. The second question is, how “big” are these 2 subnets and how many hosts can we fit in?

We have 7 bits left so let’s do the binary to decimal calculation:

64 + 32 + 16 + 8 + 4 + 2 +1 = 127.

Don’t forget about the 0! Because we can use the 0 the highest value we can create with 7 bits is 128.

Our original class C network has now been divided in 2 subnets with a size of 128 each. So what will the network addresses of the 2 new subnets be? Let’s work this example out in binary:

Subnet #1:

By applying the new subnet mask we only have 7 host bits to play with. 192.168.1.0

255.255.255.128 The network address has all host bits set to 0, so the network address will be: 192.168.1.0 First usable host IP address: The first usable host IP address is the one that comes after the network address, so this will be: 192.168.1.1

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  The broadcast address has all host bits set to 1 so the broadcast address we get is: 192.168.1.127

Subnet #2:

The first subnet ended at 192.168.1.127 so we just continue with the next subnet at 192.168.1.128:

192.168.1.128

255.255.255.128  The network address has all host bits set to 0, so the network address will be: 192.168.1.128

First usable host IP address: The first usable host IP address is the one that comes after the network address, so this will be: 192.168.1.129

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 The broadcast address has all host bits set to 1 so the broadcast address we get is: 192.168.1.255 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 number of subnets you can create.

What will the new subnet mask be? Let’s take a look at it in binary: Calculate it from binary to decimal: 128+64 = 192. The new subnet mask will be 255.255.255.192 Subnet #1:

By applying the new subnet mask we only have 6 host bits to play with. 192.168.1.0

255.255.255.192 The network address has all host bits set to 0, so the network address will be: 192.168.1.0 First usable host IP address: The first usable host IP address is the one that comes after the network address, so this will be: 192.168.1.1

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 The broadcast address has all host bits set to 1 so the broadcast address we get is: 192.168.1.63 Subnet #2:

The first subnet ended at 192.168.1.63 so we just continue with the next subnet at 192.168.1.64:

192.168.1.64

255.255.255.192 The network address has all host bits set to 0, so the network address will be: 192.168.1.64 First usable host IP address:

The first usable host IP address is the one that comes after the network address, so this will be: 192.168.1.65 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  The broadcast address has all host bits set to 1 so the broadcast address we get is: 192.168.1.127

Subnet #3:

The second subnet ended at 192.168.1.127 so we just continue with the next subnet at 192.168.1.128:

192.168.1.128 255.255.255.192

The network address has all host bits set to 0, so the network address will be: 192.168.1.128 First usable host IP address:

The first usable host IP address is the one that comes after the network address, so this will be: 192.168.1.129 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 The broadcast address has all host bits set to 1 so the broadcast address we get is: 192.168.1.191 Subnet #4:

The second subnet ended at 192.168.1.191 so we just continue with the next subnet at 192.168.1.192:

192.168.1.192

255.255.255.192 The network address has all host bits set to 0, so the network address will be: 192.168.1.192 First usable host IP address:

The first usable host IP address is the one that comes after the network address, so this will be: 192.168.1.193 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 The broadcast address has all host bits set to 1 so the broadcast address we get is: 192.168.1.255 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!

You have probably seen enough binary numbers now, so let’s work some more with decimal numbers. We can do subnetting just by working with decimal numbers.

As you have seen in the binary examples, the rule of “powers of 2” is very useful. By taking an extra bit the decimal value doubles every time:

•  For every host bit you borrow the number of subnets you can create doubles.
• Every host bit left doubles the size of the subnet.

Instead of thinking/working in binary, we’ll start thinking in “blocks”.

Take this 192.168.1.0 network with subnet mask 255.255.255.0 as an example:

We know because the subnet mask is 255.255.255.0 we have 8 bits left, and with 8 bits the highest “number” we can create is 256.

128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255.

Don’t forget about the 0! The 0 is being used so the highest value you can create is 256. Visualize this as a block: We want to subnet our 192.168.1.0 network, so we’ll chop our “block” in 2 pieces. When we chop this block in 2, this is what we get: So now we created 2 subnets out of our Class C network. The next questions are:

• What are the network addresses?
• What is the subnet mask?
• What are the usable host IP addresses?

The network addresses we can write down, they are both blocks of “128”, we‟ll start at 192.168.1.0 and the 2nd subnet will be 192.168.1.128. From .0 – .127 = “128”.

Subnet #1: Network: 192.168.1.0

Subnet #2: Network: 192.168.1.128

The second question is, what are the broadcast addresses?

Well, we know that the broadcast address is the last address within a subnet, so we can just write those down now we know the network addresses:

Subnet #1: Network: 192.168.1.0

Subnet #2: Network: 192.168.1.128

The third question, what is the subnet mask? To solve this question I’ll teach you a new trick.

Take “256” minus “block size” will give you the subnet mask:

256 – 128 = 128.

The subnet mask will be 255.255.255.128

This is a trick to remember, I would write it down on your cheat sheet.

One question left; what are the usable host IP addresses?

•  The first usable host IP address comes after the network address.
• The last usable host IP address comes before the broadcast address.
• Everything in between is a usable host IP address.

Subnet #1: Network: 192.168.1.0

First Host: 192.168.1.1

Last Host: 192.168.1.126

Subnet #2: Network: 192.168.1.128

First Host: 192.168.1.129

Last Host: 192.168.1.254

That was a lot faster right? We just subnetted this Class C network, calculated the network address, broadcast address and the usable host IP addresses.

Once upon a time when the IP addressing scheme was invented, the people who developed this thought it would be enough to have 3 different classes as we have seen so far, class A,B and C networks. There were only 3 subnet masks:

Class A 255.0.0.0 16,777,216

Class B 255.255.0.0 65,536

Class C 255.255.255.0 256

These networks are also known as “classful networks”.

When the internet started growing rapidly at the beginning of the 90‟s this caused some problems. There were only 16,000 class B networks available which are used by a lot of medium-sized companies, imagine they only needed 1000 IP addresses this would mean about 15,000 IP addresses would be wasted. A class C would be too small because you only have 256 IP addresses, and taking a couple of class C networks is no scalable option.

The solution to this problem is Classless Inter-Domain Routing, in other words, we stop working with the classful networks and start working with classless networks.

Classless networks mean we don’t use the Class A, B or C networks anymore but are free to

use any subnet mask we like, and most often you will see this in a bit-notation. For example:

192.168.1.0

255.255.255.0

Is the same as 192.168.1.0 /24

Instead of writing down the full subnet mask we only specify how many bits the subnet mask is.

172.16.1.0

255.255.0.0

Is the same as 172.16.1.0 /16 10.0.0.0

255.0.0.0

Is the same as: 10.0.0.0 /8 One more:

172.16.1.64

255.255.255.192

Is the same as 172.16.64 /26

Here’s a little overview with the CIDR notation and the full subnet mask:

255.0.0.0 /8 255.128.0.0 /9 255.192.0.0 /10 255.224.0.0 /11 255.240.0.0 /12 255.248.0.0 /13 255.252.0.0 /14 255.254.0.0 /15 255.255.0.0 /16 255.255.128.0 /17 255.255.192.0 /18 255.255.224.0 /19 225.225.240.0 /20 255.255.248.0 /21 255.255.252.0 /22

255.255.254.0 /23

255.255.255.0 /24

255.255.255.128 /25

255.255.255.192 /26

255.255.255.224 /27

255.255.255.240 /28

255.255.255.248 /29

255.255.255.252 /30

Do you see the pattern here? The numbers are the same; it’s just a different octet you are playing with. For example, take a look at /11 or /19. 255.224.0.0 or 255.255.224.0. Or for example /18 or /26. 255.255.192.0 and 255.255.255.192.

I believe the CIDR notation is easier than writing down the complete subnet mask, saves some time. Unfortunately, on most operating systems and network equipment you still have to configure the full subnet mask instead of the CIDR notation. Until this chapter we have been subnetting using a „fixed size‟ for our blocks, so, for example, we took a 192.168.1.0 Class C network and divided it in 4 blocks:

Create 4 blocks out of it: Is this a really efficient way of creating subnets? Let’s say I have the following requirements:

– One subnet for 12 hosts. One subnet for 44 hosts.

– One subnet for 2 hosts (point-to-point links are a good example where you only need 2 IP host addresses).

– One subnet for 24 hosts.

I have 4 subnets so it’s no problem, but I’m still wasting a lot of IP addresses. If we use a block of 64 for our subnet where I only need 2 IP addresses I’m throwing 62 IP addresses away.

Now you might think why we could care about this because we are using a private network address (192.168.1.0) and we have plenty of space. This is true, try to think about this on a global scale with the Internet. We don’t want to throw away valuable public IP addresses. Let’s say I want to subnet my 192.168.1.0 network in the most efficient way, let’s take our requirements I just specified:

• One subnet for 12 hosts.
• One subnet for 44 hosts.
• One subnet for 2 hosts.
• One subnet for 24 hosts.

• What kind of subnets would we need to fit in these hosts? Let’s see: 12 hosts, the smallest subnet would be a block of 16.

• 44 hosts, the smallest subnet would be a block of 64. hosts, the smallest subnet would be a block of 4.

• 2
• 24 hosts, the smallest subnet would be a block of 32. We take our block of “256”:

And divide it with the blocks we just specified: We just saved ourselves some valuable IP addresses, now the next thing to do is answer the following questions:

•  What are the network addresses?
• What is the subnet mask?
• What are the usable host IP addresses?

Chopping a network into multiple subnets with different subnet masks is called variable-length subnet mask (VLSM).

When using VLSM, start with the biggest subnet first! Otherwise, you have overlapping address space. It’s a good idea to remember the idea of “blocks” because you will visualize the size of the subnets this way.

Subnet #1: Network: 192.168.1.0

Subnet #2: Network: 192.168.1.64

Subnet #3: Network: 192.168.1.96

Subnet #4: Network: 192.168.1.112

Subnet #5: Network: 192.168.1.116 (this is where the Free space starts) Let’s fill in the broadcast addresses:

Subnet #1: Network: 192.168.1.0

Subnet #2: Network: 192.168.1.64

Subnet #3: Network: 192.168.1.96

Subnet #4: Network: 192.168.1.112

Because we have different subnet sizes, we need to calculate the subnet mask for each subnet.

Subnet #1: Block size: 64

256 – 64 = 192 so the subnet mask is 255.255.255.192

Subnet #2: Block size: 32

256 – 32 = 224 so the subnet mask is 255.255.255.224

Subnet #3: Block size: 16

256 – 16 = 240 so the subnet mask is 255.255.255.240

Subnet #4: Block size: 4

256 – 4 = 252 so the subnet mask is 255.255.255.252

The only thing left to do is fill in the usable host IP addresses:

Subnet #1: Network: 192.168.1.0

First host: 192.168.1.1

Last host: 192.168.1.62

Subnet #2: Network: 192.168.1.64

First Host: 192.168.1.65

Last Host: 192.168.1.94

Subnet #3: Network: 192.168.1.96

First host: 192.168.1.97

Last host: 192.168.1.110

Subnet #4: Network: 192.168.1.112

First host: 192.168.1.113

Last host: 192.168.1.114

Here we go, we just subnetted our 192.168.1.0 by using VLSM.

Now you know how to create subnets out of networks but we can also do it the other way around. Multiple subnets can be combined into a single network. This is what we call summarization or sometimes people call it supernetting.

Let me give you an example, here are 4 subnets:

Subnet #1: 192.168.0.0 / 24

Subnet #2: 192.168.1.0 / 24

Subnet #3: 192.168.2.0 / 24

Subnet #4: 192.168.3.0 / 24 I can summarize these 4 subnets to a single entry:192.168.0.0 /22 How did I come up with this address? Let me show it to you in binary:

Above you see our 4 subnets in binary. The first 22 bits are exactly the same, only the last 2 bits of the third octet is different. So if I use the summary 192.168.0.0 /22 it will cover our 4 subnets. I added subnet #5 so you can see it is not covered by our summary since the 5th bit of the 3rd octet is different than the first 4 subnets.

When you convert /22 to a subnet mask you’ll end up with 255.255.252.0.

When we talk about routing and routing protocols I will show you why we use summarization. You don’t have to create summaries by looking at binary numbers, there’s an easier method. Here are the same subnets again:

Subnet #1: 192.168.0.0 / 24

Subnet #2: 192.168.1.0 / 24

Subnet #3: 192.168.2.0 / 24

Subnet #4: 192.168.3.0 / 24

As you can see we have 4 subnets, or when we speak in „blocks‟ it’s a block of 4. Take 256 – 4 = 252.

The subnet mask will be 255.255.252.0

Another way to look at it is by using the CIDR notation. You know a /24 is a „256‟ block. Using a /23 means you have 2x 256, and a /22 means you have 4x 256.

You can also visualize it like this: Let’s do another example, let’s say you want to summarize the following subnets: Subnet #1: 10.16.0.0 /16

Subnet #2: 10.17.0.0 /16

Subnet #3: 10.18.0.0 /16

Subnet #4: 10.19.0.0 /16

Subnet #5: 10.20.0.0 /16

Subnet #6: 10.21.0.0 /16

Subnet #7: 10.22.0.0 /16

Subnet #8: 10.23.0.0 /16

Let’s write these subnets down in binary first: Above you can see that the first 13 bits are equal for subnet #1 up to #7.

10.16.0.0 /13 is the summary that covers all these 8 subnets. Subnet #9 isn’t covered by our summary because the first 13 bits are different.

Of course, you can do it much faster without looking at the binary numbers:

That’s 8 subnets we want to summarize into 1 single entry, what will the CIDR notation/subnet mask be?

8 subnets that’s a „block‟ of 8. 256 – 8 = 248

The subnet mask will be 255.248.0.0

Or if you feel like just using the CIDR notation:

10.16.0.0 / 16 is one subnet.

10.16.0.0 / 15 are 2 subnets.

10.16.0.0 / 14 are 4 subnets.

10.16.0.0 / 13 are 8 subnets. So 10.60.0.0 /13 will be the answer to this question. You can also visualize it like this:

In the upcoming chapters, we will talk about routing and I will show you the advantage of using these summaries.

This is the end of the chapter. The key to binary and subnetting calculations is practice, practice, and practice! You need to be lightning fast at this when you do the CCNA exam. Just write down some random IP addresses with a random CIDR notation and see if you can answer the following questions: