Role of Subnet Mask - GeeksforGeeks

26 May, 2020
Suppose we have a Class A network that means we have 16 million hosts in a network. The task we have to do is:
Maintenance of such a huge networkSecurity for the network – For example, we have 4 departments in a company and all of the 4 departments need not access the whole network.
Maintenance of such a huge network
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 –
Identification of the networkIdentification of the hostIdentification of the process
Identification of the network
Identification of the host
Identification of the process
In case of addressing with subnetting, the process of reaching an address is done by 4 steps –
Identification of the networkIdentification of the subnetIdentification of the hostIdentification of the process
Identification of the network
Identification of the subnet
Identification of the host
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.
Computer Networks
GATE CS
Computer Networks
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Advanced Encryption Standard (AES)
Intrusion Detection System (IDS)
Introduction and IPv4 Datagram Header
Secure Socket Layer (SSL)
Cryptography and its Types
ACID Properties in DBMS
Types of Operating Systems
Normal Forms in DBMS
Page Replacement Algorithms in Operating Systems
Cache Memory in Computer Organization