Mastering Subnet Mask and Subnetting: A Comprehensive Guide
Subnet Mask
The subnet mask is a 32-bit number, which tells about which is the network portion and which is the host portion of an IP address. As we know from classful IP addresses, that is the network portion and the host portion. But in the case of subnetting, we don’t know about the network and host portion. For this reason, we are using a subnet mask. It will consist of either continuous ones or continuous zeros,
E.g. class a subnet mask is 11111111. 00000000. 00000000. 00000000
An IP address of class A is 10.0.0.0 255.0.0.0
10.0.0.0 is a Class A network and 255.0.0.0 is its subnet mask.
Subnetting means the subdivision of a network. Subnetting subdivides a larger network into smaller networks;
Why We Use Subnetting
The answer is the shortage of IP addresses. If a company reserves any classful IP network, then it will reserve the whole of that network. Similarly, if any other company wants only one IP address in the classful network, it will also reserve another full network which will be a waste of IP addresses.
For example, if a person got the IP 192.168.1.1 255.255.255.0, in 192.168.1.0 network, then there is a need for only IP and he is wasting 256-1=255, so he has wasted 255 IP addresses in one network.
When the use of the internet started becoming popular in 1990, IP addresses were close to running out. Similarly, At that time, it was seen that the growth of the internet would stop. To overcome this problem, there were some solutions in which subnetting was one of them. So there was a solution that divided a larger network into smaller ones and controlled the wastage of IP addresses.
The second one was NAT, while the third one was classless IP addressing. We divided iP addresses into classes, e.g. class A, class B, class C, class D, and class E. Dividing an IP address into classes was a waste of IP addresses. So they decided that the IP address would not be divided into classes and the IP address would not relate to any class. There will be no boundary of a class.
Advantages of Subnetting
Division of a local network
A greater number of networks
Simplified addressing
Better security
Smaller collision and broadcast domain
Enhance management
Good administration
How to do subnetting
Suppose there is an IP address, 192.168.1.0 255.255.255.0
Then write its subnet mask in binary form
1111 1111. 1111 1111. 1111 1111. 0000 0000
We divided the subnet into two parts, the network portion and the host portion. 1 represents the network portion while 0 represents the host portion. So, There are 24 bits of network and 8 bits of host.
The number of hosts in this IP is 2n, put n=8 because there are 8 zeros which represent the host portion, so 28=256.
The 256 hosts are bigger, which will create greater collision and broadcast domain. So we will try to decrease this network into a smaller one by borrowing some host bits into network bits according to our needs. As there are Three usable classes in IP addresses, we are going to take the first Class network in the subnetting.
Class C
Suppose we take one bit from the host portion and add it to network bits as
11111111. 11111111. 11111111. 00000000
11111111. 11111111. 11111111. 10000000
We borrowed one bit in the last octet, so the number of networks and hosts are below according to the formula:
Finding the total number of networks = 2n
Finding the total number of hosts per network = 2n-2
First, find the total number of networks.
As we borrow only one bit, so the value of n=1, put it in the formula,
21=2*1=2, so the total number of networks will be Two.
While
The total number of hosts = 2n-2,
As the total number of zeros in the last octet is 7, so put n=7,
27-2= 2*2*2*2*2*2*-2= 128-2 = 126, the total number of hosts per network = 126.
As 27 =128 in the host portion, 128 is called block size, so the block size of each network is 128 means 128 + 128 = 256, and each network will contain 128 host IDs.
As we have two networks,
So 1st network = 192.168.1.0 255.255.255.128
2nd network = 192.168.128.0 255.255.255.128
So finding the network ID, 1st host IP, last host IP, and broadcast IP in 1st network
Note:- How did 128 in the subnet come, what is the reason beyond 128,
128 64 32 16 8 4 2 1 2n where n= 0, 1,2,3,4,5,6,7
1 0 0 0 0 0 0 0
As only one bit is on and all the other bits are off (zero) only takes 128,
192.168.1.0 255.255.255.128 OR 192.168.1.0/25
Network ID = 192.168.1.0 255.255.255.128
1st host IP = 192.168.1.1 255.255.255.128
Last host IP = 192.168.1.126 255.255.255.128
Broadcast IP = 192.168.1.127 255.255.255.128
Now take the 2nd network and find its network ID, 1st host IP, last host IP, and broadcast IP.
192.168.1.128 255.255.255.128 OR 192.168.128.0/25
Network ID = 192.168.1.128 255.255.255.128
1st host IP = 192.168.1.129 255.255.255.128
Last host IP = 192.168.1.254 255.255.255.128
Broadcast IP = 192.168.1.255 255.255.255.128
Two questions arise,
1st question, why put minus two (-2) in finding hosts
2nd question is why we put 128 in the subnet mask.
So
1st question is, why do we put minus two (-2) in finding the host formula,
The answer is, that in every network, we waste two host IPs.
One IP is network ID which we can’t assign to any host and the 2nd is broadcast ID which we also do not give this ID to any host.
The 2nd question is why we put 128 in the subnet mask.
The answer is, that if we borrow one bit from the host part, then the subnet mask will be 128 and its CIDR notation will be /25 in class C.
Similarly, if we borrow two bits from the host portion, then the subnet mask will be 128+64=192, and its CIDR notation will be/26 in Class C, according to the below table.
If we borrow two bits from the host portion, then 2n = 22 = 2*2 = 4 networks,
We will make 4 networks while remaining hosts, 8-2 = 6 bits for hosts, put n=6 in the hosts’ formula, To find the number of hosts in a network = 2n-2 = 26-2= 62 hosts.
Total number of networks = 4, total number of hosts = 62 hosts.
The block size is 26 = 64, the block size is 64, while the total network is 4, so 64*4 = 256, and each network will contain 64 hosts.
By taking 1st network of 192.168.1.0/26
192.168.1.0 255.255.255.192 OR 192.168.1.0/26
Note:-
How 192 in the subnet mask come here we also know that we took 2 bits from the host.
Ans:-
128 64 32 16 8 4 2 1 2n where n= 0, 1,2,3,4,5,6,7
1 1 0 0 0 0 0 0
[So 128+64=192]
Network ID = 192.168.1.0 255.255.255.192
1st host IP = 192.168.1.1 255.255.255.192
Last host IP = 192.168.1.62 255.255.255.192
Broadcast IP = 192.168.1.63 255.255.255.192
1st Network 1st network = 192.168.1.0/26 192.168.1.0 255.255.255.192 or 192.168.1.0/26 Network ID = 192.168.1.0 255.255.255.192 1st host IP = 192.168.1.1 255.255.255.192 Last host IP = 192.168.1.62 255.255.255.192 Broadcast IP= 192.168.1.63 255.255.255.192 | 2nd Network 2nd network = 192.168.1.64/26 192.168.1.64 255.255.255.192 or 192.168.1.64/26 Network ID = 192.168.1.64 255.255.255.192 1st host IP = 192.168.1.65 255.255.255.192 Last host IP = 192.168.1.126 255.255.255.192 Broadcast IP= 192.168.1.127 255.255.255.192 |
3rd Network 3rd network = 192.168.1.0/26 192.168.1.128 255.255.255.192 or 192.168.1.128/26 Network ID = 192.168.1.128 255.255.255.192 1st host IP = 192.168.1.129 255.255.255.192 Last host IP = 192.168.1.190 255.255.255.192 Broadcast IP= 192.168.1.191 255.255.255.192 | 4th Network 4th network = 192.168.1.192/26 192.168.1.192 255.255.255.192 or 192.168.1.192/26 Network ID = 192.168.1.192 255.255.255.192 1st host IP = 192.168.1.193 255.255.255.192 Last host IP = 192.168.1.254 255.255.255.192 Broadcast IP= 192.168.1.255 255.255.255.192 |
If we take 3 bits from the host portion, then what will be the total networks, and how many total host IDs?
192.168.1.0 255.255.255.0
Taking its masks
11111111. 11111111. 11111111. 00000000
11111111. 11111111. 11111111.11100000
192.168.1.0/27, /27 means that we took 3 bits from the host portion, so a formula is 2n, put n=3, 23=2*2*2 = 8, the total number of networks will 8 while finding the total number of hosts,
Number of zeros in host portion = 5
Formula for finding a host in a network = 2n-2, put n=5, 25-2=30,
There will be a total number of hosts in a network = 30 hosts.
Finding 1st network IDs
192.168.1.0 255.255.255.224
Network ID = 192.168.1.0 255.255.255.224
1st host ID = 192.168.1.1 255.255.255.224
Last host ID= 192.168.1.30 255.255.255.224
Broadcast ID= 192.168.1.31 255.255.255.224
For simplification, take all the 8 networks in a single table
1st Network 1st network = 192.168.1.0/27 192.168.1.0 255.255.255.224 or 192.168.1.0/27 Network ID = 192.168.1.0 255.255.255.224 1st host IP = 192.168.1.1 255.255.255.224 Last host IP = 192.168.1.30 255.255.255.224 Broadcast IP= 192.168.1.31 255.255.255.224 | 2nd Network 2nd network = 192.168.1.32/27 192.168.1.32 255.255.255.224 or 192.168.1.32/27 Network ID = 192.168.1.32 255.255.255.224 1st host IP = 192.168.1.33 255.255.255.224 Last host IP = 192.168.1.62 255.255.255.224 Broadcast IP= 192.168.1.63 255.255.255.224 |
3rd Network 3rd network = 192.168.1.64/27 192.168.1.64 255.255.255.224 or 192.168.1.64/27 Network ID = 192.168.1.64 255.255.255.224 1st host IP = 192.168.1.65 255.255.255.224 Last host IP = 192.168.1.94 255.255.255.224 Broadcast IP= 192.168.1.95 255.255.255.224 | 4th Network 3th network = 192.168.1.96/27 192.168.1.0 255.255.255.224 or 192.168.1.96/27 Network ID = 192.168.1.96 255.255.255.224 1st host IP = 192.168.1.97 255.255.255.224 Last host IP = 192.168.1.126 255.255.255.224 Broadcast IP= 192.168.1.127 255.255.255.224 |
5th Network 5th network = 192.168.1.128/27 192.168.1.128 255.255.255.224 or 192.168.1.128/27 Network ID = 192.168.1.128 255.255.255.224 1st host IP = 192.168.1.129 255.255.255.224 Last host IP = 192.168.1.158 255.255.255.224 Broadcast IP= 192.168.1.159 255.255.255.224 | 6th Network 6th network = 192.168.1.160/27 192.168.1.160 255.255.255.224 or 192.168.1.160/27 Network ID = 192.168.1.160 255.255.255.224 1st host IP = 192.168.1.161 255.255.255.224 Last host IP = 192.168.1.190 255.255.255.224 Broadcast IP= 192.168.1.191 255.255.255.224 |
7th Network 7th network = 192.168.1.192/27 192.168.1.192 255.255.255.224 or 192.168.1.192/27 Network ID = 192.168.1.192 255.255.255.224 1st host IP = 192.168.1.193 255.255.255.224 Last host IP = 192.168.1.222 255.255.255.224 Broadcast IP= 192.168.1.223 255.255.255.224 | 8th Network 8th network = 192.168.1.224/27 192.168.1.224 255.255.255.224 or 192.168.1.224/27 Network ID = 192.168.1.224 255.255.255.224 1st host IP = 192.168.1.225 255.255.255.224 Last host IP = 192.168.1.254 255.255.255.224 Broadcast IP= 192.168.1.255 255.255.255.224 |
Class B Subnetting
The classful network of class B consists of 16 bits of network portion and 16 bits of host portion. But if we want to subdivide the classful class B network, then 1st take one IP address of class B as 172.16.0.0 255.255.0.0,
The subnet mask of the class B network
11111111. 11111111. 00000000. 00000000
Network portion = 16 1’s
Host portion = 16 zeros
So borrow one bit from the host portion as
11111111. 11111111. 00000000. 00000000
11111111. 11111111. 10000000. 00000000
We took one bit from the host portion and On it, so the formula for finding the network IDs, 2n, put n=1, 21= 2*1= 2, so the total number of network = 2 networks
While the number of host ID,
As we took 1 bit from the host portion, so total number of host bits = 16-1=15 bits
Formula for finding number of hosts = 2n – 2, put n=15, 215 -2 = 32768-2=32766
Total number of host IDs = 32766
172.16.0.0 255.255.128.0 or 172.16.0.0/17
Take 1st network
Network ID =172.16.0.0 255.255.128.0
1st Host ID = 172.16.0.1 255.255.128.0
Last Host ID = 172.16.127.254 255.255.128.0
Broadcast ID = 172.16.127.255 255.255.128.0
While the 2nd network 172.16.128.0 255.255.128.0
Network ID = 172.16.128.0 255.255.128.0
1st Host ID = 172.16.128.1 255.255.128.0
Last Host ID = 172.16.128.254 255.255.128.0
Broadcast ID = 172.16.255.255 255.255.128.0
This time if we borrow two bits from the host portion. The classful B network subnet mask is below.
11111111.11111111. 00000000.00000000
11111111. 11111111. 11000000. 00000000
Number of network = 2n, put n=2, 22= 2*2 =4,
Total number of hosts = 16-2= 14, put n=14 in formula = 214–2= 16384,
1st network
172.16.0.0 255.255.192.0 or 172.16.0.0/26
172.16.0.0 /26
Network ID = 172.16.0.0 255.255.192.0
First Host ID = 172.16.0.1 255.255.192.0
Last Host ID = 172.16.63.254 255.255.192.0
Broadcast ID = 172.16.63.255 255.255.192.0
Taking 2nd Network
Network ID = 172.16.128.0 255.255.192.0
First Host ID= 172.16.128.129 255.255.192.0
Last Host ID = 172.16.91.254 255.255.192.0
Broadcast ID = 172.16.255.255 255.255.192.0
172.16.0.0255.255.0.0
The subnet is in binary form 11111111.11111111.00000000. 00000000
There are 16 bits for the network and 16 bits for the host portion.
Taking three bits from the host portion
Take three bits from the host portion of Class B. The classful B network subnet mask is below 11111111. 11111111. 00000000.00000000
11111111. 11111111. 11100000. 00000000
Number of network = 2n, put n=3, 23= 2*2*2 =8,
Total number of host bits = 16-3= 13, put n=13 in formula = 213–2= 8192-2,
So the total number of hosts per network is 8190
1st Network 1st Network = 172.16.0.0/19 172.16.0.0 255.255.224.0 or 172.16.0.0/27 Network ID = 172.16.0.0 255.255.224.0 First Host ID = 172.16.0.1 255.255.224.0 Last Host ID = 172.16.31.254 255.255.224.0 Broadcast ID = 172.16.31.255 255.255.224.0 | 2nd Network 2nd Network = 172.16.32.0/19 172.16.32.0 255.255. or 172.16.32.0/27 Network ID = 172.16.32.0 255.255.224.0 First Host ID = 172.16.32.33 255.255.224.0 Last Host ID = 172.16..62 255.255.224.0 Broadcast ID = 172.16.32.63 255.255.224.0 |
3rd Network 3nd Network = 172.16.64.0/19 172.16.64.0 255.255.224.0 or 172.16.64.0/27 Network ID = 172.16.64.0 255.255.224.0 First Host ID = 172.16.64.1 255.255.224.0 Last Host ID = 172.16.95.254 255.255.224.0 Broadcast ID = 172.16.95.255 255.255.224.0 | 4th Network 4nd Network = 172.16.96.0/19 172.16.96.0 255.255.224.0 or 172.16.96.0/27 Network ID = 172.16.96.0 255.255.224.0 First Host ID = 172.16.96.1 255.255.224.0 Last Host ID = 172.16.127.254 255.255.224.0 Broadcast ID = 172.16.127.255 255.255.224.0 |
5th Network 5th Network = 172.16.128.0/19 172.16.128.0 255.255.224.0 or 172.16.128.0/27 Network ID = 172.16.128.0 255.255.224.0 First Host ID = 172.16.128.1 255.255.224.0 Last Host ID = 172.16.159.254 255.255.224.0 Broadcast ID = 172.16.159.255 255.255.224.0 | 6th Network 6th Network = 172.160.0/19 172.16.160.0 255.255.224.0 or 172.16.160.0/27 Network ID = 172.16.160.0 255.255.224.0 First Host ID = 172.16.160.1 255.255.224.0 Last Host ID = 172.16.191.254 255.255.224.0 Broadcast ID = 172.16.191.255 255.255.224.0 |
7th Network 7th Network = 172.16.192.0/19 172.16.192.0 255.255.224.0 or 172.16.192.0/27 Network ID = 172.16.192.0 255.255.224.0 First Host ID = 172.16.192.1 255.255.224.0 Last Host ID = 172.16.223.254 255.255.224.0 Broadcast ID = 172.16.223.255 255.255.224.0 | 8th Network 8th Network = 172.16.224.0/19 172.16.224.0 255.255.224.0 or 172.16.224.0/27 Network ID = 172.16.224.0 255.255.224.0 First Host ID = 172.16.224.1 255.255.224.0 Last Host ID = 172.16.255.254 255.255.224.0 Broadcast ID = 172.16.255.255 255.255.224.0 |
Class A Subnetting
There are 8 bits for the network portion and 24 bits for the host portion in the Class A network. If we divide the Class A network into small classes then from the previous method, we will borrow bits from the host portion.
Suppose the IP address of class A is 10.0.0.0 255.0.0.0,
The subnet mask of the class B network
11111111. 00000000. 00000000. 00000000
Network portion = 8 1’s
Host portion = 24 zeros
So borrow one bit from the host portion as
11111
111. 00000000. 00000000. 00000000
11111111. 10000000. 10000000. 00000000
Class A One-Bit Subnetting
We took one bit from the host portion and On it, so the formula for finding the network IDs, 2n, put n=1, 21= 2*1= 2, so the total number of network = 2 networks
While the number of host IDs,
As we took 1 bit from the host portion, so total number of host bits = 24-1=23 bits
The formula for finding number of hosts per hosts=2n –2, put n=23,
223-2=8388608-2=8388606
Total number of host IDs per network 8388606
10.0.0.0 255.128.0.0 or 10.0.0.0/9
1st network | 2nd network |
Network ID =10.0.0.0 255.128.0.0 1st Host ID = 10.0.0.1 255.128.0.0 Last Host ID = 10.127.255.254 255.128.0.0 Broadcast ID = 10.127.255.255 255.128.0.0 | Network ID =10.128.0.0 255.128.0.0 1st Host ID = 10.128.0.1 255.128.0.0 Last Host ID = 10.127.255.254 255.128.0.0 Broadcast ID = 10.127.255.255 255.128.0.0 |
Class Two Bits Subnetting
Borrow two bits from the host portion to the network portion.
11111111.00000000. 00000000. 00000000
To
11111111.11000000. 00000000. 00000000
Bits borrowed= 2 bits
Total number of networks= 2n,
Put n=2, 22=2*2 =4,
Total number of networks 4
While the total number of host bits is 24-2= 22, we did minus 2 because we borrowed two bits from the host portion.
The formula for finding the total number of hosts per network= 2n-2,
Put n=22,
222-2=4194304-2= 4194302
So the total number of hosts per network = 4194302
Suppose we have a class A IP= 10.0.0.0, then its subnet mask will 255.192.0.0 or 10.0.0.0/10
1st network 1st Network= 10.0.0.0/10 Network ID =10.0.0.0 255.192.0.0 1st Host ID = 10.0.0.1 255.192.0.0 Last Host ID = 10.63.255.254 255.192.0.0 Broadcast ID = 10.63.255.255 255.192.0.0 | 2nd network 2nd Network= 10.64.0.0/10 Network ID =10.64.0.0 255.192.0.0 1st Host ID = 10.64.0.1 255.192.0.0 Last Host ID = 10.127.255.254 255.192.0.0 Broadcast ID = 10.127.255.255 255.192.0.0 |
3rd network 3rd Network= 10.128.0.0/10 Network ID =10.128.0.0 255.192.0.0 1st Host ID = 10.128.0.1 255.192.0.0 Last Host ID = 10.191.255.254 255.192.0.0 Broadcast ID = 10.191.255.255 255.192.0.0 | 4th network 4th Network= 10.192.0.0/10 Network ID =10.192.0.0 255.192.0.0 1st Host ID = 10.192.0.1 255.192.0.0 Last Host ID = 10.192.255.254 255.192.0.0 Broadcast ID = 10.192.255.255 255.192.0.0 |
Class A 3 bits Subnetting
Class A network borrowing 3 bits from the host portion
11111111.00000000. 00000000. 00000000
11111111.11100000.00000000.00000000
3 bits borrowed
Total number of networks= 2n,
Put n=3, 23=2*2*2=8,
Total number of networks 8
While total number of host bits is 24-3= 21 because 3 bits are taken from the host part to the network portion for subnetting. The formula for finding the total number of hosts per network= 2n-2,
Put n=21,
221-2=2097152-2= 2097150
So the total number of hosts per network is 2097150
Suppose we have a class A IP= 10.0.0.0, then its subnet mask will be 255.224.0.0 or 10.0.0.0/11
1st Network 1st Network= 10.0.0.0/11 10.0.0.0 255.224.0.0 or 10.0.0.0/11 Network ID = 10.0.0.0 255.224.0.0 First Host ID = 10.0.0.1 255.224.0.0 Last Host ID = 10.31.255.254 255.224.0.0 Broadcast ID = 10.31.255.255 255.224.0.0 | 2nd Network 2nd Network = 10.32.0.0/11 10.32.0.0 255.224.0.0 or 10.32.0.0/11 Network ID = 10.32.0.0 255.224.0.0 First Host ID = 10.32.0.1 255.224.0.0 Last Host ID = 10.63.255.254 255.224.0.0 Broadcast ID = 10.63.255.255 255.224.0.0 |
3rd Network 3rd Network= 10.64.0.0/11 10.64.0.0 255.224.0.0 or 10.64.0.0/11 Network ID = 10.64.0.0 255.224.0.0 First Host ID = 10.64.0.1 255.224.0.0 Last Host ID = 10.95.255.254 255.224.0.0 Broadcast ID = 10.95.255.255 255.224.0.0 | 4th Network 4th Network= 10.96.0.0/11 10.96.0.0 255.224.0.0 or 10.96.0.0/11 Network ID = 10.96.0.0 255.224.0.0 First Host ID = 10.96.0.1 255.224.0.0 Last Host ID = 10.127.255.254 255.224.0.0 Broadcast ID = 10.127.255.255 255.224.0.0 |
5th Network 5th Network= 10.128.0.0/11 10.128.0.0 255.224.0.0 or 10.128.0.0/11 Network ID = 10.128.0.0 255.224.0.0 First Host ID = 10.128.0.1 255.224.0.0 Last Host ID = 10.159.255.254 255.224.0.0 Broadcast ID = 10.159.255.255 255.224.0.0 | 6th Network 6th Network= 10.160.0.0/11 10.160.0.0 255.224.0.0 or 10.160.0.0/11 Network ID = 10.160.0.0 255.224.0.0 First Host ID = 10.160.0.1 255.224.0.0 Last Host ID = 10.191.255.254 255.224.0.0 Broadcast ID = 10.191.255.255 255.224.0.0 |
7th Network 7th Network= 10.192.0.0/11 10.192.0.0 255.224.0.0 or 10.192.0.0/11 Network ID = 10.192.0.0 255.224.0.0 First Host ID = 10.192.0.1 255.224.0.0 Last Host ID = 10.223.255.254 255.224.0.0 Broadcast ID = 10.223.255.255 255.224.0.0 | 8th Network 8th Network= 10.224.0.0/11 10.224.0.0 255.224.0.0 or 10.128.0.0/11 Network ID = 10.224.0.0 255.224.0.0 First Host ID = 10.224.0.1 255.224.0.0 Last Host ID = 10.255.255.254 255.224.0.0 Broadcast ID = 10.255.255.255 255.224.0.0 |