Writing : 1 page Subnetting : 24 hours
Subnetting
Network administrators are usually granted with a range of IP Addresses they can assign to individual end hosts, intermediary hosts, and interfaces. It is the job of a network administrator to make a judicious use of these resources, especially in the light of shortages of IP addresses in IPv4. It is also important that these addresses are used consistently to help in the overall maintenance of the network.
Let us assume we are giving the following range of addresses with its prefix length: 172.16.94.0/23
The number above could be written in binary format as follows:
1010 1100 0001 0000 0101 1110 0000 0000 (IP address: 172.16.94.0)
1111 1111 1111 1111 1111 1110 0000 0000 (Subnet Mask: 255.255.254.0)
p = 23 (network bits) h = 9 (host bits)
The prefix length (p) indicates how many bits at the beginning of the IP address are used to describe the network in binary format (in our case p = 23). Because every IPv4 address is made out of 32 bits, the difference correspond to the number of bits left for hosts in the network (h, that in our case is h = 32-p = 32-23 = 9). The subnet mask is no other that an IP address that has all network bits set to one and all host bits set to zero in binary format. This number, written in decimal format, is the one we are used to see as the subnet mask when configuring a computer.
Under these conditions, the maximum number of possible host addresses in this network (M) is given by the following formula:
M = 2h – 2
2h is the number of possible hosts one could have with h binary digit positions, but we need to subtract 2 addresses because these are used for two equally important purposes: one to describe the network in general, and the other one to indicate the address where broadcast messages should be sent.
In our case, given that h is 9, the maximum number of possible host address is 29-2 = 512 – 2 = 510. If we plan to have a network with at most 510 hosts, we could start giving addresses from the allocated range as it is, without any further change.
In most cases, the maximum number of hosts is excessive for a single network. Having a large number of hosts in a network within the same subnet is a problem, mainly for two reasons: they share the same broadcast domain and the same collision domain. This means that all hosts in the subnet will receive copies of every message destined to only one of them (broadcast domain) and that every message must compete for access to the media with each one of the messages sent by any other host, because they are in the same collision domain. Having a smaller number of hosts in a subnet will be more efficient, because it
will avoid excessive repetition of messages being delivered unnecessarily to other hosts, and also will avoid the loss of performance inherent in a collision prone network with a lot of hosts.
Another reason for subnetting is that it allows a better organization and control of the hosts. Any range of addresses can be divided in sections based on geography (having all hosts in a geographical area sharing the same subnet), ownership (having all hosts belonging to a department, section, or group sharing the same net), and similar purpose (having all hosts that share the same task sharing the same net).
Subnetting is achieved by borrowing bits from the host bits, and using them as part of the subnet mask for the new subnets. Instead of the original IP address range with its own prefix length (p), we will get a set of subnets, each one with a continuous portion of the IP address range, and with a larger prefix length. If we borrow b bits from the host bits (h), the created subnets will have at least p+b network bits, and at most 2h-b-2 hosts.
Let us assume that the range that was given to us (172.16.94.0/23) needs to be subnetted to provide IP addresses for two large offices in separated geographical locations. The first location requires 40 IP addresses, while the second one requires 80 IP addresses. To connect both locations, each one has a router that is going to be connected with each other using a WAN connection. This linkage of the 2 routers also requires us to allocate a subnet capable to handle at least 2 host IP addresses for these two routers.
The most important rule to remember when subnetting an IP address range is that each resulting subnet should allow a maximum number of hosts that is a power of 2, including the network and broadcast addresses. We should also break the IP address range in a number of subnets that is a power of 2.
One could break an IP address range in various ways, but there are two standardized ways to do so that we need to understand: Fixed Length Subnet Masking (FLSM) and Variable Length Subnet Masking (VLSM).
Fixed Length Subnet Masking (FLSM)
The purpose of FLSM is to break the IP address range into subnets with equal maximum number of hosts. The process is as follows:
1. Find out how many bits from the original host bits are going to be borrowed to create subnets (b). Because every bit we borrow breaks the network in a number of subnets that are a multiple of 2, then if we borrow one bit, we would have 2 subnets (21), if we borrow two bits we would have 4 subnets (22), and so on. Select a number of borrowed host bits that will create a number of subnets that is bigger than or equal to the number of requested subnets.
In our example, we require 3 subnets. The smallest number that is power of 2 but that is bigger than or equal to 3 is 4 (3 < 4 = 22 = 2b). This means that we are going to borrow 2 host bits (b = 2) to increase the network bits of the subnets. The prefix length will now be 25 (p+b = 23+2), for each of the subnets. The maximum number of hosts in each subnet will be 126 (2h-b - 2 = 29-2 – 2 = 27 -2 = 126).
2. Find the maximum number of hosts needed per each subnet, by selecting the smallest power of 2 that is bigger than or equal to the number of required hosts plus 2. Select the biggest of these numbers.
In our example, we need 3 subnets with 40, 80 and 2 host addresses respectively. The smallest powers of 2 that are bigger than or equal to these numbers are 64, 128 and 4, respectively (64 = 26 >= 40+2, 128 = 27 >= 80+2, 4 = 22 >= 2+2). We select 128 = 27, the biggest of these numbers. If we subtract the network and broadcast addresses, the maximum number of hosts obtained in this step is 126 (126 = 128 – 2).
In order for FLSM to work, the maximum number of hosts we obtain in this step should be smaller or equal to the maximum number of hosts obtained in step 1. Luckily for us, in our example, this maximum number of addresses is the same in both steps. This indicates that our subnetting process using FLSM is possible. If the maximum number of hosts obtained in step 1 would have been smaller than the number found in step 2, it would mean that after borrowing bits from the host bits, there are not enough remaining host bits to give an IP address to every host in our subnets. This would make impossible to continue with FLSM, and a new form of subnetting should be devised, if at all possible.
3. Write a table that will have as many rows as the subnets you are creating, and that will have the following column headings:
Subnet #
Prefix Length
Subnet Mask
# Required
Hosts
Max # of
Hosts
Network Address
First Address
Last Address
Broadcast Address
The table should be filled row by row (subnet by subnet) with the following contents:
a. Subnet #: Write the subnet number. They should start at 0 and increase by one in every subnet that follows. Write also this number in binary format with b bits. It will be later used to create the IP addresses for the subnet.
b. Prefix Length: This is the new prefix length for the subnets. As indicated above this number is p+b, and it is the same for all subnets.
c. Subnet Mask: The IP address that is obtained by setting to one all network bits in the prefix length (b), and by setting to zero all other bits. This number should be presented in in decimal format.
d. # Required Hosts: The number of hosts originally required in each subnet.
e. Maximum # of Hosts: The maximum number of hosts available for every subnet (obtained from the formula 2h -2 = 232-(p+b) - 2 ).
So far, the table in our example will contain the following information:
Subnet # (binary)
Prefix Length
Subnet Mask # Required
Hosts Max # of
Hosts …
0 (00) 25 255.255.255.128 40 126 = 27 – 2 …
1 (01) 25 255.255.255.128 80 126 = 27 – 2 …
2 (10) 25 255.255.255.128 2 126 = 27 – 2 …
3 (11) 25 255.255.255.128 N/A 126 = 27 – 2 …
f. Network Address: This is the address that represents the subnet. In binary representation, it has the same p left bits as the original IP address range (given), followed by b bits with the subnet number, and followed by enough zeros to complete 32 bits of the IP address. Convert this number to decimal format for the table
g. Broadcast Address: This is the last column in the table, but calculating it before the others will help to complete the table faster. This address is reserved because it is used to broadcast a message to all hosts in the subnet. It is the last one on the range for a subnet. In binary representation, it has the same p left bits as the original IP address range (given), followed by b bits with the subnet number, and followed by enough zeros to complete 32 bits of the IP address. Convert this number to decimal format for the table. To check your calculations, please confirm that the broadcast address you obtained here is the same as adding the maximum number of hosts (column e) to the network address (column f) plus 1. Also, the Broadcast Address is the same as the Network Address of the following subnet minus one.
h. First Address: This is the first usable address network of the subnet. This is obtained by adding 1 to the Network address (column f).
i. Last Address: This is the last usable address network of the subnet. This is obtained by subtracting 1 to the Broadcast Address (column g).
In our example we were given the following IP address range:
1010 1100 0001 0000 0101 1110 0000 0000 (IP address: 172.16.94.0)
p = 23 (network bits) h = 9 (host bits)
For the Network Addresses, the subnets will keep the first p bits of this IP address range, will add b bits of their subnet number, and the remaining bits will be zero:
1010 1100 0001 0000 0101 1110 0000 0000 (Network address, subnet 0: 172.16.94.0)
1010 1100 0001 0000 0101 1110 1000 0000 (Network address, subnet 1: 172.16.94.128)
1010 1100 0001 0000 0101 1111 0000 0000 (Network address, subnet 2: 172.16.95.0)
1010 1100 0001 0000 0101 1111 1000 0000 (Network address, subnet 3: 172.16.95.128)
p = 23 (network bits) b = 2 (borrowed bits)
For the Broadcast Addresses, the subnets will keep the first p bits of this IP address range, will add b bits of their subnet number, and the remaining bits will be one:
1010 1100 0001 0000 0101 1110 0111 1111 (Broadcast address, subnet 0: 172.16.94.127)
1010 1100 0001 0000 0101 1110 1111 1111 (Broadcast address, subnet 1: 172.16.94.255)
1010 1100 0001 0000 0101 1111 0111 1111 (Broadcast address, subnet 2: 172.16.95.127)
1010 1100 0001 0000 0101 1111 1111 1111 (Broadcast address, subnet 3: 172.16.95.255)
p = 23 (network bits) b = 2 (borrowed bits)
The First Address of the subnets, are the Network addresses plus one:
1010 1100 0001 0000 0101 1110 0000 0001 (First address, subnet 0: 172.16.94.1)
1010 1100 0001 0000 0101 1110 1000 0001 (First address, subnet 1: 172.16.94.129)
1010 1100 0001 0000 0101 1111 0000 0001 (First address, subnet 2: 172.16.95.1)
1010 1100 0001 0000 0101 1111 1000 0001 (First address, subnet 3: 172.16.95.129)
(Add one)
The Last Address of the subnets, are the Broadcast addresses minus one:
1010 1100 0001 0000 0101 1110 0111 1110 (Last address, subnet 0: 172.16.94.126)
1010 1100 0001 0000 0101 1110 1111 1110 (Last address, subnet 1: 172.16.94.254)
1010 1100 0001 0000 0101 1111 0111 1110 (Last address, subnet 2: 172.16.95.126)
1010 1100 0001 0000 0101 1111 1111 1110 (Last address, subnet 3: 172.16.95.254)
(Subtract one)
With these calculations, the right side of the table should look like this:
Subne t #
… Max # Hosts
Network Address
First Address Last Address Broadcast Address
0 (00) … 126 172.16.94.0 172.16.94.1 172.16.94.126 172.16.94.127
1 (01) … 126 172.16.94.128 172.16.94.129 172.16.94.254 172.16.94.255
2 (10) … 126 172.16.95.0 172.16.95.1 172.16.95.126 172.16.95.127
3 (11) … 126 172.16.95.128 172.16.95.129 172.16.95.255 172.16.95.255
One drawback of FLSM is that is wasteful. In the example above, we are left with an unused subnet that can be used for further developments in the future, however, the third subnet is wasted, with a possible maximum of 126 hosts, but being used only by 2 hosts, the 2 routers. To improve in this allocation, one may try to select a different arrangement. Variable Length Subnet Masking (VLSM) was developed to provide the optimal allocation of IP addresses to subnets while minimizing its waste.
Variable Length Subnet Masking (VLSM)
VLSM will allocate to each subnet a number of hosts addresses that closely relates to the number each one originally requested. It does this by assigning blocks of variable lengths to each subnet, from the biggest to the smallest values requested. The process is as follows:
1. Sort the subnets by descending number of requested hosts.
In our example, we ordered the subnets by the following requested sizes: 80, 40, and 2.
2. Find the maximum number of hosts needed per each subnet, by selecting the smallest power of 2 that is bigger than or equal to the number of required hosts plus 2, in order. The power of 2 is the number of host bits needed per subnet (h). With these required host bits per subnet we calculate the number of borrowed bits per subnet (b) subtracting from 32 the original number of network bits and the host bits (b = 32 – p – h).
In our example, the 3 subnets with requested sizes of 80, 40 and 2 host addresses will require 7, 6 and 2 host bits, respectively, producing the following maximum number of hosts: 128, 64 and 4, respectively (128 = 27 >= 80+2, 64 = 26 >= 40+2, 4 = 22 >= 2+2). Their respective host bits are 7, 6, and 2, producing the following borrowed bits (b), in order: 2 (32-23-7), 3 (32-23-6), and 7 (32-23-2).
In order for VLSM to work, the addition of all the maximum number of hosts should be smaller than the number of hosts available in the originally IP address range. If not, it will not be possible to subnet using this method, because there are not enough addresses to grant. In our example, the addition of the maximum number of addresses is 196 (128+64+4). This is smaller
than the 512 addresses available in the original IP address range (2h = 29 = 512, the maximum number of hosts plus the original network and broadcast addresses). We will be able to use VLSM to subnet the IP address range.
3. Write a table that will have as many rows as the subnets you are creating, and that will have the following column headings:
Subnet #
Prefix Length
Subnet Mask
# Required
Hosts
Max # of
Hosts
Network Address
First Address
Last Address
Broadcast Address
The table should be filled row by row (subnet by subnet) with the following contents:
a. Subnet #: Write the subnet number. They should start at 0 and increase by one in every subnet that follows. This time the subnet # is referential, and it will not be used in calculations.
b. Prefix Length: This is the new prefix length for each of the subnets. This number is p+b, where b may be different in each subnet.
c. Subnet Mask: The IP address that is obtained by setting to one all network bits in the prefix length (p+b), and by setting to zero all other bits. This number should be presented in in decimal format, and it may be different for each subnet.
d. # Required Hosts: The number of hosts originally required in each subnet. If we are working correctly, this column should be in decreasing order of number of host requested.
e. Maximum # of Hosts: The maximum number of hosts available for every subnet (obtained from the formula 2h -2 = 232-(p+b) - 2 ). This number may be different for each subnet, but bigger than or equal to the number of required hosts (column d).
So far, the table in our example will contain the following information:
Subnet #
Prefix Length
Subnet Mask # Required
Hosts Max # of
Hosts …
0 25 = 23+2 255.255.255.128 80 126 = 27 – 2 …
1 26 = 23 +3 255.255.255.192 40 62 = 26 – 2 …
2 30 = 23+7 255.255.255.252 2 2 = 22 – 2 …
For the following columns one needs to go row by row to calculate the addresses correctly
f. Network Address: This is the address that represents the subnet. For the first subnet (first row), the network address is exactly the same one given originally. The network addresses for the following rows will be one number more than the broadcast address of the previous subnet (row).
g. First Address: This is the first usable address network of the subnet. This is obtained by adding 1 to the Network address (column f).
h. Last Address: This is the last usable address network of the subnet. This is obtained by adding the maximum number of hosts (column e) to the Network Address (column f).
i. Broadcast Address: This address is reserved because it is used to broadcast a message to all hosts in the subnet. It is the last one on the range for a subnet, and it is obtained by adding 1 to the last address of the subnet (column h). Once a broadcast address is determined for a subnet, the network address for the following subnet will be obtained by adding 1 to the Broadcast Address just evaluated.
The following subnets (rows) are evaluated in the same fashion.
In our example we were given the following IP address range:
1010 1100 0001 0000 0101 1110 0000 0000 (IP address: 172.16.94.0)
p = 23 (network bits) h = 9 (host bits)
For the first subnet we have a maximum of 126 hosts and its network address will be the same as the original IP address:
1010 1100 0001 0000 0101 1110 0000 0000 (Network address, subnet 0: 172.16.94.0)
1010 1100 0001 0000 0101 1110 0000 0001 (First address, subnet 0: 172.16.94.1)
1010 1100 0001 0000 0101 1110 0111 1110 (Last address, subnet 0: 172.16.94.126)
1010 1100 0001 0000 0101 1110 0111 1111 (Broadcast address, subnet 0: 172.16.94.127)
Our second subnet has a maximum of 62 hosts and its network address will be the broadcast address of the first subnet plus 1:
1010 1100 0001 0000 0101 1110 1000 0000 (Network address, subnet 0: 172.16.94.128)
1010 1100 0001 0000 0101 1110 1000 0001 (First address, subnet 0: 172.16.94.129)
1010 1100 0001 0000 0101 1110 1011 1110 (Last address, subnet 0: 172.16.94.190)
1010 1100 0001 0000 0101 1110 1011 1111 (Broadcast address, subnet 0: 172.16.94.191)
The third and last subnet has a maximum of 2 hosts and its network address will be the broadcast address of the subnet plus 1:
1010 1100 0001 0000 0101 1110 1100 0000 (Network address, subnet 0: 172.16.94.192)
1010 1100 0001 0000 0101 1110 1100 0001 (First address, subnet 0: 172.16.94.193)
1010 1100 0001 0000 0101 1110 1100 0010 (Last address, subnet 0: 172.16.94.194)
1010 1100 0001 0000 0101 1110 1100 0011 (Broadcast address, subnet 0: 172.16.94.195)
With these calculations, the right side of the table should look like this:
Subne t #
… Max # Hosts
Network Address
First Address Last Address Broadcast Address
0 (00) … 126 172.16.94.0 172.16.94.1 172.16.94.126 172.16.94.127
1 (01) … 62 172.16.94.128 172.16.94.129 172.16.94.190 172.16.94.191
2 (10) … 2 172.16.94.192 172.16.94.193 172.16.94.194 172.16.94.195
Guillermo Tonsmann Ph.D. April 2012