The Wayback Machine - https://web.archive.org/web/20250119102854/https://www.geeksforgeeks.org/role-of-subnet-mask/
Open In App

Role of Subnet Mask

Last Updated : 02 Jan, 2025
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

A subnet mask defines which part of an IP address identifies the network and which part identifies individual devices. It is an important tool used in networking to separate an IP address into two parts: the network portion and the host portion. By doing this it helps to determine which devices belong to the same local network and which devices reside on different networks. It supports efficient network organization, better control of data flow, and overall improved security and management of the network.

What is a Subnet Mask?

A subnet mask is a numerical tag that works alongside an IP address to determine which part of the address refers to the network and which part identifies individual devices (hosts) on that network. By applying a subnet mask it effectively splits the IP address into two sections: the network portion and the host portion. By setting all 0s for the host bits and all 1s for the network bits results in a 32-bit value known as a subnet mask and this process is called subnetting. “255” is always the address assigned to the broadcast address, while “0” is always the address assigned to the network address. The subnet mask cannot be assigned to the host because it is set aside for a specific purpose.

It helps organize large networks into smaller, more manageable subnetworks, improves the efficient use of IP addresses, and makes it easier to manage and secure your network. A common subnet mask example is 255.255.255.0, which indicates that the first three numbers identify the network, while the last number identifies hosts within that network.

Function of Subnet Mask

A 32-bit address that distinguishes the network address from the host address makes up the subnet mask. This indicates which part of the IP address belongs in the host section and which part belongs in the network section. The number of hosts that can be on the subnet depends on the values of the subnet mask. This comprises bits that are initialized to 1 for the network and 0 for the host. Routers and switches use it internally to send packets to the destination node along the associated local network connection.

Suppose we have a Class A network which 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 access to the whole network.

For this we need Subnetting i.e., dividing a huge network into smaller networks. Now every department will have their network. In the case of addressing without subnetting, the process of reaching an address is done by 3 steps –

  • 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 –

  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.

Subnetting

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.

Subnet Mask

Representation of Subnet Masks

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 and Subnet Matching

If the network id doesn’t matches with any of the subnet mask then the packet will be sent to default entry.

Default entry has network id as 0.0.0.0.

Routing Table

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.

How Does Subnetting Work?

Subnetting divides a large network into smaller sub-networks by modifying the subnet mask. This improves the management of IP addresses, reduces broadcast traffic, and increases network security by isolating different parts of the network. Subnetting also helps optimize the use of IP address space and improves troubleshooting and overall network performance.

For example, subnetting can organize devices into logical groups, such as separating a company’s departments into different subnets. This way, traffic within one department does not unnecessarily interfere with others, improving performance and security

Network Classes

The company in charge of overseeing the Internet, InterNIC assigns IP addresses. There are classes for these IP addresses. Classes A, B, and C are the most prevalent ones among them. Although they exist, end users do not use classes D or E. The default subnet mask varies for each address class. An IP address’s first octet can be used to determine its class. The ranges of Class A, B, and C Internet addresses are listed below, along with a sample address for each:

  • Class A networks have 0-127 as their first octet and utilize 255.0.0.0 as their default subnet mask. 10.52.36.11 is classified as a class A address. 10 its initial octet, falls between 1 and 126, inclusive.
  • Class B networks have 128–191 as their first octet and 255.255.0.0 as their default subnet mask. Address 172.16.52.63 belongs to the class B address set. Its initial octet is 172, spanning from 128 to 191, inclusive.
  • Class C networks have 192-223 as their first octet and utilize 255.255.255.0 as their default subnet mask.
Ranges of Classes

Ranges of Classes

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.

Advantages of Subnetting

  • It does this by sending out fewer broadcasts, which lowers network load.
  • It assists in getting around restrictions in a local area network (LAN), like the maximum number of permitted hosts.
  • Without needing to access the entire network, it enables users to join to a work network from their residences.
  • It keeps one network safe from another’s infiltration. For instance, no other department within an organization should be able to view the code created by the Developer department.
  • A higher network priority may be needed for some subnets than for others. For instance, a sales department might need to hold video conferences or webcasts.
  • If the network is tiny, maintenance is easy.

Disadvantages of Subnetting

  • Subnetting reduces the overall number of IP addresses in the network, yet it could necessitate purchasing extra hardware, like a router. Thus it could be very expensive.
  • Companies still assign address blocks in relation to classes, therefore it cannot alleviate the inefficiency.

Conclusion

Subnetting enhances network performance by reducing congestion, improving security, and making better use of available IP addresses. It allows network administrators to organize devices more effectively, isolate network segments for security, and control traffic flow. Although subnetting introduces complexity, it offers significant benefits in terms of network scalability and management.

Frequently Asked Question on Subnet Mask – FAQ’s

How is a subnet mask represented?

A subnet mask is a 32-bit value, often written in dotted decimal notation, like 255.255.255.0. The 1s in the mask represent the network and subnet portion, while the 0s represent the host portion.

How does subnetting help in network design?

Subnetting allows a large network to be split into smaller, more efficient subnets, reducing broadcast traffic and improving the overall speed and security of the network.

Can subnet masks have variable lengths?

Yes, subnet masks can have variable lengths, which is known as VLSM (Variable Length Subnet Masking). This allows more flexible allocation of IP address ranges.

Why is subnetting important for security?

Subnetting can isolate network segments, which helps prevent unauthorized access and limits the spread of network vulnerabilities or infections



Next Article
Article Tags :

Similar Reads

three90RightbarBannerImg