In this post I am going to explain what is IP subnetting and how it is done. Subnetting is used to divide a network into two or more segments of networks. Subnetting involves breaking of the available IP address range into different networks as per requirement. There are two main types of subnetting i.e. subnetting based on number of networks required and subnetting based on number of hosts required per network. You figure out the subnet mask through subnetting which will be then applied in configuring the routers and hosts on your network. Lot of subnetting calculators are available which do the calculation for you but learning it is essential if you are planning to take cisco certifications like CCENT and CCNA.
Before getting started, I would like to talk about the structure of IP address and subnet mask. Each ip address consist of 4 octets i.e. four sets of 8 bit each. Each octet can represent a value of min. 0 (00000000) to max. 255 (11111111). All the four octets can have any value between 0 to 255. A 0 present in the last octets (e.g. 192.168.10.0) indicates or identifies the network segment. A 255 in the last octet (e.g. 192.168.10.255) is usually the broadcast IP address for the network. An address ending in 0 or 255 cannot be used to assign to a host. However, this is not always the case in IP subnetting.
A subnet mask defines the network part and the hosts part in an IP address. For example, the subnet mask for class C ip addresses (255.255.255.0) indicates that the first 3 octets in the address are used to indicate the network and the last octet identifies the host from an IP address. When the network is divided, the "hosts part" of the subnet mask is modified according to number of networks or hosts per network desired.
It is recommended to have basic knowledge of binary conversion and computer networking before going ahead. The examples I will show below are specific to class C networks, however, the same concept can be extended to class A and B as well.
Subnetting based on number of networks
Consider a scenario, you have been given an IP address range (say 192.168.1.0 - 192.168.1.255). And you are assigned to divide this range into 10 networks and to figure out the subnet mask. The steps you will follow are as follows:
1. Convert the number of networks required to binary and find out the number of bits.
In this example, we have 10 networks. Its binary equivalent is 1010 which can be represented by 4 bits. Therefore, 4 bits are required to represent number of networks (which is 10).
2. Reserve bits in the subnet mask and find out new subnet mask
The original subnet mask of class C network is 255.255.255.0. Lets represent it in binary.
11111111.11111111.11111111.00000000
Now, in the above step, we found out that 4 bits are required to represent networks. Hence, in the above subnet mask, we convert 4 host bits to network bits (remember that all 1's represent host bits and all 0's represent network bits.)
11111111.11111111.11111111.11110000
Notice that we converted leftmost host bits to network bits. Now this is the subnet mask required, in binary. Converting it back to decimal,
255.255.255.240 (decimal of 11110000 is 240)
3. Find out the increment and corresponding network ranges
Let's consider the binary form of subnet mask again.
11111111.11111111.11111111.11110000
To find out the increment, we consider only the octet in which the last network bit i.e. 1 lies. Here it is the last octet.
11110000
Now we find out the place value of last "1". Since it is at 5th position from right hand side, its place value becomes 2^(5-1) = 16. (this is equivalent to making all other bits except last network bit "0" and converting back to decimal).
We've got 16 as the increment. This increment is used to find the starting address of each network range. In our case, the starting address of each network range will be 192.168.1.0, 192.168.1.16, 192.168.1.32, 192.168.1.48 and so on...
And the corresponding network ranges will be
192.168.1.0 - 192.168.1.15
192.168.1.16 - 192.168.1.31
192.168.1.32 - 192.168.1.47
192.168.1.48 - 192.168.1.63
and so on...
Here, the starting address of each range will become the network identifier and last address of the range will become broadcast address for that segment. e.g. in the first range, 192.168.1.0 is identifier and 192.168.1.15 is the broadcast address.
Subnetting based on number of hosts
Let's say we have been given the same IP address range (192.168.1.0-192.168.1.255) and now we're asked to divide this range into segments of 20 hosts/network irrespective of number of networks that will be created. The steps that we'll follow now are a little different -
1. Convert the number of hosts required to binary and find out the number of bits.
Here, we have 20 hosts per network. 20 can be represented in binary as 10100. So, 20 can be represented in binary with 5 bits.
2. Reserve the bits in subnet mask and find out new subnet mask
Class C subnet mask in binary form is
11111111.11111111.11111111.00000000
Here since we are concerned with number of hosts, we have to reserve host bits i.e. zeroes. The host bits are always reserved from the right hand side of the last octet.
11111111.11111111.11111111.000"00000"
Here the 5 bits (quoted) will be saved or reserved for the hosts and rest of them will be used for network (i.e. turning them to "1").
Hence the subnet mask becomes
11111111.11111111.11111111.11100000
Decimal representation : 255.255.255.224 (decimal of 11100000 is 224).
3. Find out the increment and corresponding network ranges
Increment can be found out by the similar method as last example. By considering the last bit of the network bits
11111111.11111111.11111111.11100000
Calculating place value of the highlighted bit, we get 32 (2^5).
Therefore, the starting address of each thus formed network range will be incremented by 32. The starting addresses will be
192.168.1.0, 192.168.1.32, 192.168.1.64, 192.168.1.96, 192.168.1.128 and so on...
The network ranges thus formed are
192.168.1.0 - 192.168.1.31
192.168.1.32 - 192.168.1.63
192.168.1.64 - 192.168.1.95
so on...
and again, the starting and ending addresses of each range will be identifiers and broadcast addresses respectively.
Well, i'll conclude here for now. In the next article I will describe reversing the subnet mask and talk about bit notation.
Thanks for reading :)