Subnetting And Subnet Mask Tutorial With Example

Greetings!
We have recently published 100+ articles on android tutorials with kotlin and java. If you need, you may visit Android Tutorial for beginners page. You can also check Kotlin Tutorial for beginners. Also, if you are interested in content writing, you can mail us at tutorialwing@gmail.com.

In this tutorial, we will study about subnetting, along with the advantages and disadvantages of subnetting. We will study various types of masks and how to find the Subnet ID and network ID. To gain a stronger hold, we will also look at the various possible questions on subnetting.

In previous tutorial, we have studied about classful addressing. Checkout this post if you are not familiar with the classful addressing because we are going to use the terms related to it in this article.

What is Subnetting?

– Dividing a network into smaller parts for effective utilization of IP addresses is known as subnetting.

Tutorialwing Subnetting Tutorial With Example of Subnetting

Subnetting

Advantages of subnetting:

– Maintaining a large network is a tedious task and thus it is preferable to divide the network into smaller parts.
– Security to subnet can be provided from another network.

Disadvantage of a Subnet:

– In order to connect to a process we need to connect to follow the following path:
        Network => Subnet => Host => Process instead of Network => Host => Process
Thus, maintaining a subnet is an overhead.
– There is a loss of IP addresses after subnetting since each subnet requires one IP address for Subnet ID and the other for Subnet DBA.

Calculation of Subnet ID:

Bitwise AND operation of IP Address and Subnet Mask gives Subnet ID.

For example: if IP Address = 200.1.2.36, Subnet Mask = 200.1.2.240 . Then, Subnet ID will be AND operation of 200.1.2.36 and 200.1.2.240

BITWISE AND

200.1.2.00100100
200.1.2.11110000
= 200.1.2.00100000 (200.1.2.32)

So, Subnet ID is (200.1.2.32)

Let’s take an example of Subnetting –

Assume a Class C network with IP Address 200.1.2.0
Therefore, Total no of available host addresses = $256 (2^8)$
Out of these two are unavailable as one address is reserved for Subnet ID and the second address is reserved for the Subnet DBA.
Let’s divide the network into two equal parts.
Now, both the subnets get 128 addresses each.

Tutorialwing Subnetting Example of Subnetting Tutorial With Example

Subnetting Example

About image depicts how the network will be divided into two equal parts.



Various models of questions possible on Subnetting:

Model 1:

Subnet mask is given. Calculate no of Subnet masks and no of hosts in subnet.

Question 1.
In a class C, if a subnet mask is 255.255.255.244, then calculate the
(i) No of subnets
(ii) No of hosts in each Subnet

Solution:
(i) Convert the decimal no. IP Address to binary no IP address.
11111111.11111111.11111111.11100000
Now, Since this is a Class C network, default network mask is 11111111.11111111.11111111.00000000
Therefore, three 1 bits in the last octet contribute to the subnets.
The total no of Subnets = $2^3$
The point worth noting is that out of these 8 addresses one address is reserved for the network ID and one more address is reserved for the subnet mask. Thus, we need to subtract two addresses.
Total possible subnets= 8-2 = 6

(ii) Now the remaining 5 bits contribute to the hosts. Here also, two addresses are reserved. One for the Subnet Id and the other for network mask. Therefore, out of the total that we get we need to subtract 2 addresses.
Total no of hosts = $2^5 – 2 = 30$

Model 2:

IP Address and subnet Mask are given, calculate Subnet ID.

Example 1
IP Address = 200.1.2.34 and Subnet Mask = 200.1.2.240. Then, calculate Subnet ID.

Solutions:
As we already know, Subnet ID can be calculated by AND operation of IP Address and Subnet mask given. So,

Bitwise AND of 200.1.2.34 and 200.1.2.240 is –
200.1.2.00100010
200.1.2.11110000
= 200.1.2.00100000 (200.1.2.32)

So, Subnet ID = 200.1.2.32

Model 3:

IP Address and Subnet Mask are given, Calculate Subnet no. and Host no.

Example:
IP Address = 200.1.2.39, Subnet Mask = 200.1.2.240
Calculate:
(i) Subnet no.
(ii) Host no.

Solution –
We can calculate Subnet ID by AND operation of IP address and Subnet Mask. So,
BITWISE AND
200.1.2. 00100111
200.1.2.11110000
= 200.1.2.00100000 (200.1.2.32)

So, Subnet ID = 200.1.2.32

(i) Since there are 4 ones in the fourth octet, no. of hosts = $2^4 – 2 = 14$
Most significant 4 bits in fourth octet show subnet no. since the subnet mask has 4 1s. Therefore, Subnet no. = 0010 = 2
(ii) No. of hosts = $2^4 – 2 = 14$
Least significant 4 bits in fourth octet show host no. since the subnet mask has 4 0s. Therefore, Host no. = 0111 = 7

Model 4:

IP Addresses and Subnet Mask is given, identify the IPs belonging to the same network.

Example:
(i) IP Address 1 – 201.15.16.99
(ii) IP Address 2 – 201.15.16.109
(iii) IP Address 3 – 201.15.16.118
(iv) IP Address 4 – 201.15.16.129
Subnet Mask: 255.255.255.224

find whether IPs belong to the same network?

=> Solution 1: BITWISE AND of all the IP addresses one by one with the Subnet Mask to get the Subnet IDs. Whichever IP Addresses have the same subnet Id will belong to the same subnet.

=> Solution 2:
On expanding the subnet in binary format: 11111111.11111111.11111111.11100000
We observe that first three bits in the last octet represent the no of subnets. Thus we expand the IP addresses individually to check the first three bits of the last octet. The IP addresses which have the same first three bits in the last octet represent the same subnet and thus belong to the same subnet.
(i) IP Address 1 – 201.15.16.01100011
(ii) IP Address 2 – 201.15.16.01101110
(iii) IP Address 3 – 201.15.16.01110100
(iv) IP Address 4 – 201.15.16.10000001
(i), (ii), (iii) have the same first three bits in the last octet. And thus belong to the same subnet.

Model 5:

DBA is given, identify the suitable subnet mask

Example:
DBA of subnet – 199.89.99.31. Which of the following is a suitable subnet mask:
(i) 255.255.255.192
(ii) 255.255.255.240
(iii) 255.255.255.128
(iv) None

Solution: This is solved using hit and trial method.
If we expand the subnet in binary notation: 199.89.99.00011111
For the option to be correct there should be at least 4 1’s in the subnet mask in the MSB of the last octet.
Thus, option (ii) is correct.

Model 6:

Subnet Mask is given, identify the suitable DBA

Question:
If subnet mask is 255.255.255.240, which of the following is suitable DBA?
(i) 201.15.3107
(ii) 201.15.31.15
(iii) 201.15.31.63
(iv) None

Solution: If we expand the subnet mask 255.255.255.11110000
Thus, four bits are assigned to the subnets i.e. 1-15 subnets are possible. Thus in the given options we check if the first four bits give 1-15 and the last four bits should be 1. If not it is not a valid DBA. Thus, answer (iii) is correct.

Model 7:

A company require 60 hosts. What is the best possible subnet mask?

Solutions:
We do this by hit and trial method.
If we consider 6 bits in the LSB of the last octet we get $2^6 = 64$ IP Addresses out of which 2 are reserved.
Thus, the best possible subnet mask
= 11111111.11111111.11111111.11000000 (Host bits are 0 in the subnet mask)
= 255.255.255.192

This was all about subnetting. In the next tutorial, we glance upon Variable Length Subnet Masking.
[latexpage]

Support Us

If you like Tutorialwing and would like to contribute, you can email an article on any educational topic at tutorialwing@gmail.com. We would love to publish your article. See your article on Tutorialwing and help others with your knowledge. Follow Facebook, LinkedIn, Google+, Twitter, Youtube for latest updates.
Greetings!
We have recently published 100+ articles on android tutorials with kotlin and java. If you need, you may visit Android Tutorial for beginners page. You can also check Kotlin Tutorial for beginners