Subnetting is the process of dividing the larger network into smaller networks. A subnet or subnetwork is a part of network.
Why we need subnetting?
To reduce the wastage of IP address, or you can also say for effective utilisation of IP address. NAT and subnetting both are good solution for proper utilisation of IP address.
How to calculate available addresses or usable addresses?
This is very simple and easy calculation. To find out the total number of available addresses, first find how many host bits are there? Then use below formula to calculate total addresses
Total number of available addresses = 2^{hostbits} |
For example: Class A has 24 host bits, so total no. of available addresses = 2^{24}
Class B has 16 host bits, so total no. of available addresses = 2^{16}
Class C has 8 host bits, so total no. of available addresses = 2^{8}
Total Number of usable addresses =2^{hostbits} – 2 |
Now, many of you are curious to know why I subtract 2.
From total addresses we subtract 2 because first address is used as network address and last address is used as broadcast address, we can’t assign these two addresses to devices.
How to calculate number of subnets?
Number of subnets = 2^{X} where x =number of borrowing bits^{.} |
Que: How many subnets are available with the network 172.16.0.0/26?
Sol. Given Address belong to class B. and for class B prefix length is 16.
But, given prefix length is 26.
So, borrowed host bits = 26-16 = 10
Now, 2^{10} =1024 subnets
Type-1. Find the subnet ID
Que-1.Which subnet does host 172.16.26.127/21 belong to?
Steps to find out the subnet ID
- Perform decimal to binary conversion.
- Then, convert all host bits to zero.
- Now again perform the decimal conversion.
First Method:
Solution: Prefix length is 21, it means 21 network bits and rest 11 are host bits.
Step-1: 172. 16. 26. 127 (decimal Form of IP address)
- 00010000. 00011010. 01111111
Step-2: Put network bits as it is and convert all host bits to zero.
- 00010000. 00011000. 00000000
Step-3: Now perform binary to decimal conversion. First two octets are same put them as they are.
- 16. 24. 0/21 is the subnet Id.
Second Method:
Sol. Here, prefix length is 21 and total bits are 32 in IPv4, so host bits are 32-21= 11
Decimal form of IP 172.16.26.127, no need to convert all 4 octets to binary form.
As you can see host bits are only 11 that lie in last 2 octets (26.127).
All bits of last octet are host bits, so you can simply put it zero without any conversion.
Now you have to only convert the third octet (26) in binary form.
Decimal form 26
Binary form 00011010, (first five bits are network bits and last 3 bits are host bits).
Now convert host bits to zero.
Binary form: 00011000
Equivalent decimal form: 24
Now subnet id is 172.16.24.0/21
I solve this question by using two methods. To apply second method, you need to do lot of practice. Steps are same in both methods only unnecessary conversion is eliminated.
Que2. What subnet does host 192.168.5.57/27 belongs to?
Solution: Here, prefix length is 27 (network bits), rest 5 are host bits.
Step1: Perform decimal to binary conversion
- 168. 5. 57
- 10101000. 00000010. 00111001 (first 27 bits are network bits and last 5 bits are host bits).
Step2: Put network bits as they are and convert all host bits to zero.
- 10101000. 00000010. 00100000
Step-3: Now perform binary to decimal conversion.
There is no changes in first three octets, put them as they are initially in decimal form.
192.168.5.32 is the subnet Id.
Que3. What subnet does host 192.168.29.219/29 belongs to?
Solution: Here, prefix length is 29 (network bits), rest 3 are host bits.
Step1: Perform decimal to binary conversion
- 168. 29. 219
- 10101000. 00011101. 11011011 (first 29 bits are network bits and last 3 bits are host bits).
Step2: Put network bits as it is and convert all host bits to zero.
- 10101000. 00011101. 11011000
Step-3: Now perform binary to decimal conversion.
There is no changes in first three octets, put them as they are initially in decimal form.
192.168.29.216/29 is the subnet Id.
Que4: What subnet does host 172.21.111.201/20 belongs to?
Solution: Here, prefix length is 20 (network bits), rest 12 are host bits.
Step1: Perform decimal to binary conversion
- 21. 111. 201
- 00010101. 01101111. 11001001 (first 20 bits are network bits and last 12 bits are host bits)
Step2: Put network bits as it is and convert all host bits to zero.
- 00010101. 01100000. 00000000
Step-3: Now perform binary to decimal conversion.
There is no changes in first two octets, put them as they are initially in decimal form.
172.21.96.0/20 is the subnet Id.
Type-2 Find the prefix length
Que1. You have been given the 172.16.0.0/16 network. You are asked to create 80 subnets for your company’s various LANs. What prefix length should you use?
Solution: Total no. of subnets = 2^{X}
80 = 2^{X}
2^{6 }= 64 and 2^{7 }= 128 (64 is less than 80 so, here x = 7, borrowed bits from host bits). Hence, prefix length = network bits + borrowed host bits
= 16 + 7
^{ }prefix length = 23
Que2. You have been given the 172.18.0.0/16 network. Your company requires 250 subnets with the same number of hosts per subnet. What prefix length you should use?
Solution: Total no. of subnets = 2^{X}
250 = 2^{X}
2^{7 }= 128 and 2^{8 }= 256 ( 128 is less than 250 so, here x = 8, borrowed bits from host bits). Hence, prefix length = network bits + borrowed host bits
= 16 + 8
prefix length^{ } = 24 |
How to calculate network address and broadcast address?
To find the network address, all host bits are converted into 0 (zero).
To find the broadcast address, all host bits are converted into 1 (one).
Que1. PC1 has an IP address of 10.217.182.223/11.
Find out
- Network address
- Broadcast address
- First usable address
- Last usable address
- Number of host addresses
Solution: 1. First perform decimal to binary conversion
Decimal form of IP: 10 .217 .182 .223
Binary form: 00001010 .11011001 .10110110 .11011111
Now to find the network address convert all host bits into 0 (zero). As given IP has prefix length 11. It means 11 network bits and remaining (32-11 = 21) bits are host bits.
00001010 .11000000 .00000000 . 00000000
Now again perform binary to decimal conversion
10 .192 .0 .0
Network address = 10.192.0.0/11 |
- To find broadcast addressconvert all host bits to 1 (one).
Decimal form of IP: 10 .217 .182 .223
Binary form: 00001010 .11011001 .10110110 .11011111
Convert all host bits to 1
00001010 .11011111 .11111111 .11111111
Now perform binary to decimal conversion:
10 .223 .255 .255
Broadcast address = 10.223.255.255/11 |
- Find First usable address: The first address after the network address is known as first usable address.
Network address = 10.192.0.0/11
So, first usable address is 10.192.0.1/11
- Find last usable address: The address just before the the broadcast address is known as last usable address.
Broadcast address = 10.223.255.255/11
So, last usable address is 10.223.255.254/11
- Total Number of host addresses = 2^{hostbits}
Here, host bits are 21
So, total host addresses are = 2^{21}
Que- Represent /24 in decimal dotted form (subnet mask). Or what will be decimal dotted representation of /24?
Sometime this type of questions are directly asked by interviewer. I remember recently I gave 1 interview in which interviewer asked what will be the decimal dotted representation of /28?
So, now the thing is how to solve this type of question? Let me explain this.
For /24, many of you know the decimal dotted representation. But here I will tell you the step-by-step procedure, so that you can calculate subnet mask(decimal dotted representation) for any prefix length.
In IPv4, total bits are 32. / value represent number of network bits. So, in /24, we have 24 network bits and 8 host bits.
To calculate decimal dotted form, assign 1 (one) to all network bits and 0 (zero) to all host bits.
For /24
- 11111111. 11111111. 11110000
255.255.255.0 (decimal dotted form).
For /28 (28 network bits and remaining 4 are host bits)
- 11111111. 11111111. 11110000
255.255.255.240 (Decimal dotted representation)
Prefix Value (/ value) | Network bits | Host bits | Binary form (assign 1 to network bits and 0 to host bits) | Decimal dotted representation (subnet mask) |
/24 | 24 | 8 | 11111111. 11111111. 11111111. 00000000 | 255.255.255.0 |
/25 | 25 | 7 | 11111111. 11111111. 11111111. 10000000 | 255.255.255.128 |
/26 | 26 | 6 | 11111111. 11111111. 11111111. 11000000 | 255.255.255.192 |
/27 | 27 | 5 | 11111111. 11111111. 11111111. 11100000 | 255.255.255.224 |
/28 | 28 | 4 | 11111111. 11111111. 11111111. 11110000 | 255.255.255.240 |
/29 | 29 | 3 | 11111111. 11111111. 11111111. 11111000 | 255.255.255.248 |
/30 | 30 | 2 | 11111111. 11111111. 11111111. 11111100 | 255.255.255.252 |
/31 | 31 | 1 | 11111111. 11111111. 11111111. 11111110 | 255.255.255.254 |
/32 | 32 | 0 | 11111111. 11111111. 11111111. 11111111 | 255.255.255.255 |