Role of Subnet Mask

Suppose we have a Class A network that means we have 16 million hosts in a network. The task we have to do is:

  1. Maintenance of such a huge network
  2. Security for the network – For example, we have 4 departments in a company and all of the 4 departments need not access the whole network.

For this we need subnetting i.e., dividing a huge network into smaller network. Now every department will have their own network .

In case of addressing without subnetting, the process of reaching an address is done by 3 steps –

  1. Identification of the network
  2. Identification of the host
  3. Identification of the process

In case of addressing with subnetting, the process of reaching an address is done by 4 steps –

  1. Identification of the network
  2. Identification of the subnet
  3. Identification of the host
  4. Identification of the process

Suppose we have a Class C network and we want to divide it into 4 subnets. To divide we need to choose 2 bits from the host part.



As the first and last IP addresses are reserved for network ID and directed broadcast address in every subnet, we have to reserve 8 IP addresses in this case.

A packet is received which has destination address -200.1.2.20 . Then how the router will identify that which subnet it belongs to . It’ll be done using Subnet Mask.

A subnet mask is a 32-bit number which is used to identify the subnet of an IP address. The subnet mask is combination of 1’s and 0’s. 1’s represents network and subnet ID while 0’s represents the host ID. For this case, subnet mask is,

11111111.11111111.11111111.11000000 
or
255.255.255.192 

So in order to get the network which the destination address belongs to we have to bitwise & with subnet mask.

    11111111.11111111.11111111.11000000
&&  11001000.00000001.00000010.00010100
-----------------------------------------------------
    11001000.00000001.00000010.00000000 

The address belongs to,

11001000.00000001.00000010.00000000 
or
200.1.2.0 

The internal router will forward the packet to the network through an interface . The interface will be identified by the routing table residing in the router.

Routing table :
If the network id doesn’t matches with any then the packet will be sent to default entry. Default entry has network id as 0.0.0.0.

In some cases the network id may match with two entries in the routing table, so here the interface having the longest subnet mask(more 1’s) is selected.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.