Before you start

**Objectives:** how to create smaller networks (subnets) from one larger network.

**Prerequisites:** you have to know how to convert numbers from binary to decimal and from decimal to binary. You have to know all the details about an IPv4 IP address.

**Key terms:** subnet, address, mask, hosts, network, octet, ip, broadcast, decimal, zeros, binary, class

### Usage

With subnetting we divide a larger network into smaller networks or subnets. Using one network we create separate subnets that are connected into a larger network. When we subnet a network, each network segment (subnet) has a different network address, which is also called a subnet address. The terms network and subnet are used interchangeably to describe a physical network segment with a unique network address. We create subnets to reduce congestion, collisions and processing load on routers and computers. We also use subnetting to efficiently use the available IP addresses.

Let’s take a look at an example. Let’s say that we have 1000 hosts on our network. Also, let’s say that we have a 172.16.0.0 address, and a subnet mask of 255.255.0.0. With this we could create one large network that has over 65,000 hosts on the network. If we create a single network with the default subnet mask to support our 1000 hosts, that means that we are wasting approximately 64000 addresses. That means that there are 64000 addresses that cannot be used. Also, if we pay for IP addresses, this would be even worse, because we would pay for all those addresses and not use them. To avoid this we need to have subnets.

### How to Create Subnets by Adding Full Octet

We create subnets by modifying the default subnet mask. In our example we have a class B address of 172.16.0.0. With the default subnet mask (255.255.0.0) we have a single network. To create additional subnets we use a larger subnet mask than the default. For example, let’s take a maks of 255.255.255.0 to create additional subnets.

172.16.0.0

255.255.255.0

With this mask we have subnets: 172.16.0.0, 172.16.1.0, 172.16.2.0, … , up to 172.16.255.0. Notice that in this case we changed the number in the third octet. From the subnet mask we know that he subnet address is the first three octets in the address. By varying the number in the third octet we create additional subnets. When it comes to number of hosts in a subnet, let’s take a look at one subnet. For subnet 172.16.0.0 we could have hosts from 172.16.0.1 to 172.16.0.254. This gives us a maximum of 254 hosts on each subnet, in this example. For our 1000 hosts we would need approximately 5 subnets. So in our case we would use subnets 172.16.0.0, 172.16.1.0, 172.16.2.0, 172.16.3.0, and 172.16.4.0 to support all our computers on our network. The rest of the subnets can be then used on other networks.

Let’s take a look at one more example. We got the following subnet address:

172.0.0.0

255.255.0.0

We could also subnet this address by adding one more 255 to the subnet mask, but what would be the subnets? Is the 172.1.0.0 subnet OK? No, it’s not OK, and that’s because we can only change the third octet (and fourth) in this case to create the subnets. That’s because we first got the 255.255.0.0 mask, and that means that we can’t change first two octets. In this case the possible subnets are 172.0.0.0, 172.0.1.0, 172.0.2.0, and so on up to 172.0.255.0.

### Classful vs Classless Address

If an IP address uses the default subnet mask, we call it a classful address. Classless IP address uses a custom subnet mask. We create classless IP addresses by modifying the length of the subnet mask. This is made possible by a feature called Classless Inter Domain Routing, or CIDR. With CIDR we can use Variable Length subnet masks, or VLSM. With VLSM we simply modify the length of the subnet mask in order to create subnets. With CIDR we can represent the subnet mask in a shorthand which identifies the mask. For example, we have an IP address of 172.16.10.10, and a custom subnet mask of 255.255.255.0. The subnet mask in binary form is: 11111111.11111111.11111111.00000000. Using the shorthand method we can represent the mask by simply counting the number of ones that are in the mask. Remember that a subnet mask must be a series of ones without any zeros, followed by a series of zeros. So in order to indicate the mask, we need to indicate the length of the subnet mask, or the number of one bits within the mask. In this case we have 24 ones, so we write /24 to indicate that mask.

Let’s take a look at another subnet mask. Let’s say that we have a subnet mask: 11111111.11111111.11111111.10000000, which is in decimal 255.255.255.128. In this mask we have 25 ones, so we write /25 to indicate this subnet mask. Another example is: 255.255.240.0, which is in binary: 11111111.11111111.11110000.00000000. This mask has 20 bits active, so we write /20 to indicate the subnet mask.

So the default subnet masks are /8 for class A (255.0.0.0), /16 for class B (255.255.0.0), and /24 for class C (255.255.255.0). If we work with classful addressing, we can assume the length of the subnet mask from the class. But because of how addresses work today classes are not typically used in identifying the subnet mask. And the default masks are typically not used either. We will rarely see a network that actually has a /8 subnet mask. Instead, we will likely see a class A address that uses a longer subnet mask.

### How to Create Subnets Using VLSM

Up to now we only modified the default subnet mask by filling an entire octet (we added 255). It is possible to create a subnet masks that do not use a full octet. When ever we have a full binary octet, we have a series of eight ones. If we have an empty octet, we have a series of zeros in our mask. It looks something like this.

255 | 255 | 255 | 0 |

11111111 | 11111111 | 11111111 | 00000000 |

Remember, whenever w have a full octet, we have eight 1 within that octet. In our previous examples, when we’ve wanted to create additional subnets we’ve simply filled one of the octets with a series of eight 1 within the subnet mask. Let’s now do another example in which we don’t use eight ones.

255 | 255 | 192 | 0 |

11111111 | 11111111 | 11000000 | 00000000 |

This time we used two ones, and six zeros in the third octet. The important thing to remember when creating a subnet mask is that we must have a series of all ones followed by a series of all zeros. Because of this fact, all subnet masks will have limited values. In fact, we can only have the following values within an octet of a subnet mask: 0, 128, 192, 224, 240, 248, 252, 254 and 255.

To get this numbers we simply convert each binary number into a decimal number. Remember that the subnet mask must have ones on the left hand portion, so the possible numbers in one octet are:

- 00000000 (which is 0 in decimal)
- 10000000 (which is 128 in decimal)
- 11000000 (which is 192 in decimal)
- 11100000 (which is 224 in decimal)
- 11110000 (which is 240 in decimal)
- 11111000 (which is 248 in decimal)
- 11111100 (which is 252 in decimal)
- 11111110 (which is 254 in decimal)
- 11111111 (which is 255 in decimal)

Now that we know these values, we have to know how many subnets and how many hosts on a subnet can we have. The number of subnets is **2 ^{(number of ones which we used to subnet our network)}**. For example, in case a) this is 2

^{0}, which is 1 subnet. In case b) this is 2

^{1}, which is 2. In case c this is 2

^{2}, which is 4. In case c) this is 2

^{3}, which is 8 subnets. In case d) this is 2

^{4}, which is 16 subnets, and so on. When it comes to the number of hosts per subnet, the number is

**2**. In case a) this is 2

^{(number of zeros)}-2^{8}-2, which is 254. In case b) this is 2

^{7}-2, which is 126. In case c) this is 2

^{6}-2, which is 62. In case d) this is 2

^{5}-2, which is 30, and so on. We subtract 2 because we have to reserve the network address and the broadcast address in every subnet. The first address in a subnet is the network (subnet) address. The last address in every address is a broadcast address. We also have to know the address of every subnet. To get that we have to know the step which we have to take to get to the next subnet. To determine the step to get to the next subnet, use the formula

**2**. So now that we know all those numbers, we can subnet our network more precisely. When subneting, we pay attention to the octet in which the change occurs. Let’s look at some examples.

^{(number of zeros in changing octet)}#### Example 1

**Question**: We have the following IP address and a subnet mask:

IP address: 192.168.1.0

Subnet mask: 255.255.255.0

Create four subnets. How many hosts per subet will we have? Write the network and broadcast address for every subnet. Write the first and last address that we can use for hosts on a subnet. Write subnets in short notation.

**Answer**: To create four subnets we have to add two ones in the fourth octet (because 2^{2}=4). The decimal notation for that subnet mask is 255.255.255.192. We use this mask for all our new subnets. Note that the change is in the fourth octet. We have 6 zeros in the changing octet which gives us 2^{6}-2=62 hosts per subnet. The step to get to the next subnet is 2^{6}=64.

The first subnet is 192.168.1.0, subnet mask is 255.255.255.192. In short we can write 192.168.1.0 /26. The “/26” tells us that we have 26 ones (binnary) in the subnet mask. The step to get to the next subnet is 64 (192.168.1.64), which means that the last address in the first subnet is 192.168.1.63 /26. This is the broadcast address in first subnet. The last address that we can use for our hosts is 192.168.1.62 /26.

The second subnet is 192.168.1.64 /26. First address that we can use for hosts is 192.168.1.65. The step to get to the next subnet is 64 (102.168.1.128), which means that the broadcast address for the second subnet is 192.168.1.127 (the last address in subnet). That gives us the last address that we can use for our hosts, which is 192.168.1.126.

So, the third subnet is 192.168.1.128. First address for hosts is 192.168.1.129. The next subnet is 192.168.1.192, so the broadcast address is 192.168.1.191. The last address for hosts is 192.168.1.190.

The fourth subnet is 192.168.1.192. First address for hosts is 192.168.1.193 and the last host address is 192.168.1.254. The broadcast address is 192.168.1.255.

#### Example 2

**Question**: The IP address is 172.16.0.0 and the subnet mask is 255.255.0.0. We have to have at least 400 hosts per subnet, and we have to have 3 different subnets. Write the first and the last host address in every subnet, number of possible host addresses, network and broadcaset address in every subnet. You can use the short notation if you wish.

**Answer**: In this case we have a lot of IP addresses which we can use. Since we only need about 1200 IP addresses, we can also preserve a lot of IP addresses. To get 400 addresses for hosts we have to use the formula. The 2^{8}-2 gives us only 254 addresses, which is not enough. The 2^{9}-2 gives us 510 addresses, which is more than enough. So we have to use 9 zeros in our subnet mask. This means that the change will be in the third octet, because the zeroes are always on the right side of the mask. The mask is 255.255.254.0, or in binary: 11111111.11111111.11111110,00000000, or /23 in short. The change is in the third octet, and there we have only one zero. Because of that the step to get to the next subnet is 2^{1}, which is 2 (172.16.2.0). So, the first subnet is 172.16.0.0. The first address for hosts is 171.16.0.1. The last address in the subnet is 172.16.1.255, and this is the broadcast address for our subnet. That gives us the last address which we can use for our hosts, and this is 172.16.1.254.

The second subnet is 172.16.2.0, the first address is 172.16.2.1, and the last host address can be 172.16.3.254. The broadcast address is 172.16.3.255.

The third subnet is 172.16.4.0, the first address is 172.16.4.1, and the last host address can be 172.16.5.254. The broadcast address is the 172.16.5.255.

This is it, that’s all that we need. The rest of the address is preserved. The next subnet is 172.16.6.0, but we don’t need it. Notice that we used only a small portion of the range. The only range that is taken is 172.16.0.0 /21 (255.255.248.0). So, we could use the 172.16.8.0 /21 network for something else. Also, the following networks are still free: 172.16.16.0 /20 (mask is 255.255.240.0), 172.16.32.0 /19 (mask is 255.255.224.0), 172.16.64.0 /18 (mask is 255.255.192.0), and 172.16.128.0 /17 (mask is 255.255.128.0).

#### Example 3

**Question**: The IP address is 10.0.0.0 and the subnet mask is 255.0.0.0. In the organization there will be 5 departments. In department 1 there will be 200 computers, in department 2 we will have 700 computers, in department 3, 30 computers, in department 4, 150 computers, and in department 5, 70 computers. Determine the subnets and save as many addresses as you can. Write all free subnets.

**Answer**: When calculating the subnets we always have to start from the largest subnet. In this case this is the subnet which will contain 700 hosts. The second is the one with 200 hosts, then 150, then 70, and then 30. Now, in total there is 1250 hosts in the organization. Let’s see how many zeros we have to have in our subnet mask to accommodate all those hosts. Let’s start with 10 hosts, so the formula is 2^{10}-2=1022. This is not enough, so let’s use 11. The formula is 2^{11}-2=2046. This is more than enough. So, in general we will use the network 10.0.0.0 /21 (mask is 255.255.248.0) to get all other subnets.

For the first subnet we have to have 700 hosts. To get that we have to have 10 zeroes in subnet mask, which will give us 1022 hosts. The mask is 255.255.252.0, or in binary: 11111111.11111111.11111100.00000000, or /22 in short. Notice that the change is in the third octet, so we will pay attention to it. In third octet we have two zeroes, so the step is 2^{2}=4. We will keep that in mind when we go to the next subnet. The first subnet is 10.0.0.0, and the first address which we can use for our hosts is 10.0.0.1. The last address in this subnet is 10.0.3.255, and this is the broadcast address. This is because the next subnet is 10.0.4.0, when we use the mask that we use. The last address that we can use for our hosts is 10.0.3.254.

So, we already mentioned that the next subnet is 10.0.4.0 /22, and we can use this subnet to accommodate all other hosts in our organization, but remember that we have to have different networks for different departments. Because of that, we will further subnet this network. The next subnet has to have at least 200 host, and for that we will use the 8 zeroes in our subnet mask. So, the subnet mask is 255.255.255.0 or /24 in short. As we said, the subnet is 10.0.4.0, the first host address is 10.0.4.1. The next subnet is 10.0.5.0, so the broadcast address is 10.0.4.255. The last host address is 10.0.4.254.

The next department has to have 150 computers, and for this we also have to use 8 zeroes in our subnet mast. So, the mask is again 255.255.255.0 or /24 in short. The subnet that we will use is 10.0.5.0, and the first address for hosts is 10.0.5.1, and the last is 10.0.5.254. The broadcast address is 10.0.5.255.

The next subnet that we can use is 10.0.6.0 /24. We will further subnet it to accommodate 70 and 30 hosts. For 70 hosts we will use the mask 255.255.255.128, which will give us 126 hosts on one subnet. So, the subnet is 10.0.6.0 /25, the first host address is 10.0.6.1 and the last is 10.0.6.126. The broadcast address is 10.0.6.127 (because the next subnet is 10.0.6.128).

For the last smallest department we have to have 30 host addresses. For that we will use 5 zeroes, so the subnet mask will be 255.255.255.224 or 11111111.11111111.11111111.11100000. We will use the next free subnet which is 10.0.6.128 /27. The first host address is 10.0.6.129. The change is in the fourth octet, and the step is 32. So the next subnet is 10.0.6.160. That means that the broadcast address is 10.0.6.159, and the last host address is 10.0.6.158.

The last thing we need to do is write down free subnets. Here we will start from smallest, so the first is 10.0.6.160 /27, then 10.0.6.192 /26, then 10.0.7.0 /24, then 10.0.8.0 /21, then 10.0.16.0 /20, then 10.0.32.0 /19, then 10.0.64.0 /18, then 10.0.128.0 /17, then 10.1.0.0 /16, 10.2.0.0 /15, 10.4.0.0 /14, 10.8.0.0 /13, and so on.

Remember that we can have varying lengths of subnet masks by partially filling an octet.

### Suppernetting

There’s another concept which is called supernetting. With supernetting we use a shorter mask to combine the subnet addresses into a larger address space. Supernetting takes combines multiple networks into one larger subnet address.

For example, let’s say that we have the following subnets: 192.168.1.0 /24, 192.168.2.0 /24 and 192.168.3.0 /24. The task is to combine them into one subnet in most efficient way. To do that we will use smaller subnet mask, which means that we have to use less ones in it. To cover our three subnets we will remove two ones from the mask. This will give us the step of 4, so we will be able to cover all IP address in the range. So, the subnet mask will be 255.255.252.0, or in binary 11111111.11111111.11111100.00000000, or /22 in short. That means that our network address is 192.168.0.0, and the first address that we can use for our hosts is 192.168.0.1. The next subnet is 192.168.4.0, so we know that the broadcast address is 192.168.3.255. Also, from this we know that the last address for our hosts is 192.168.3.254. As we see, with 192.168.0.0 /22 subnet, we cover all IP addresses in our existing subnets in this example.

### Remember

Subnetting is the process of taking a larger network address and creating smaller subnets using a longer subnet mask. Supernetting is the process of taking smaller network addresses and combining them into a larger address. We can use subnet masks that do not use an entire octet. Classful addresses are IP addresses that use the default subnet mask. Classless addresses are those that use a custom mask value to determine the subnet. Classless Inter-Domain Routing (CIDR) allows us to use variable length subnet masks (VLSM). If subnetting using VLSM is to complicated for you, you should be able to at least create subnets based on using a full octet mask. For example, to create subnets of a class B address using the class C subnet mask that uses 24 bits instead of the default 16 bits.