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

Role of Subnet Mask

Last Updated : 11 Feb, 2024
Improve
Suggest changes
Post a comment
Like Article
Like
Save
Share
Report

The host or client address and the network or server address are the two parts of the IP address that are present on every computer device. Either a DHCP server or a human, using a static IP address, configures the IP addresses.

What is a Subnet Mask?

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. The IP address is divided into the host address and network address in this manner by the subnet mask. “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.

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 not access 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

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 utilise 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 utilise 255.255.255.0 as their default subnet mask.

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.

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.

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 organisation 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 improves performance by lowering network traffic and collisions. This gives the IT administrators complete control over data packet monitoring, router device enabling or updating, and network traffic reduction. In order for the routers to match data packets to the intended node and determine the optimal path for data transmission between the sender and recipient interface, the subnet mask addresses are required to distinguish between the host and network address.

Frequently Asked Question on Subnet Mask – FAQs

What is a Subnet Mask?

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.

How is a Subnet Mask represented?

The IP address’s 32-bit value is used to identify each octet. For instance, 255.255.255.0 is a typical Class C subnet mask because the last two bytes are all zeros and the first two bytes are all ones (network).

How does subnetting help in network design?

One purpose of a subnet is to reduce traffic by dividing a large network into a collection of linked, smaller networks. In this manner, traffic can move faster over networks by avoiding needless paths. The segmentation of a network address space, or subnetting, increases the effectiveness of address allocation.

Can subnet masks be variable in length?

Yes Subnet mask can be variable in length.

Why is subnetting important for security?

By quarantining infected areas of the network and making it more difficult for intruders to navigate an organization’s network, subnetting enables network managers to lessen hazards to the entire network.



Previous Article
Next Article

Similar Reads

Finding Network ID of a Subnet (using Subnet Mask)
In order to find network id (NID) of a Subnet, one must be fully acquainted with the Subnet mask. Subnet Mask: It is used to find which IP address belongs to which Subnet. It is a 32 bit number, containing 0's and 1's. Here network id part and Subnet ID part is represented by all 1's and host ID part is represented by all 0's. Example: If Network i
2 min read
How do You Calculate the Subnet Address from an IP Address and Subnet Mask?
Answer: To calculate the subnet address from an IP address and subnet mask we first convert both into its binary form and perform the bitwise AND operation between IP address and subnet mask.Subnet MaskThe subnet mask of a network is the number in which all the network bits are set to 1 and all host bits are set to 0. Subnet ID or Subnet AddressThe
2 min read
Fixed Length and Variable Length Subnet Mask Numericals
Before starting off with this article make sure you know the basics of Subnetting and Classless Addressing. 1. Fixed-Length Subnet Mask : When a block of addresses is divided into subnets all having an equal number of addresses, the type of subnetting is said to be Fixed Length Subnetting. The subnet masks used here will be the same for all the sub
5 min read
C Program to find IP Address, Subnet Mask & Default Gateway
Terminology IP Address : An IP address, short for Internet Protocol address, is an identifying number for a piece of network hardware. Having an IP address allows a device to communicate with other devices over an IP-based network like the internet. Subnet mask: A subnet mask is a 32-bit number used to differentiate the network component of an IP a
2 min read
Is 255.0.255.0 a Subnet Mask?
Answer: No, 255.0.255.0 is not a valid subnet mask.Subnet masks are comprised of a series of consecutive binary 1s followed by binary 0s, indicating the network portion and the host portion of an IP address, respectively. In the case of 255.0.255.0: The binary representation is 11111111.00000000.11111111.00000000.This subnet mask separates the IP a
1 min read
How to Calculate a Subnet Mask from IP Address?
Answer: Calculate a subnet mask from an IP address by determining the number of network bits based on the subnet size and converting them to binary.To calculate a subnet mask from an IP address, you first need to understand subnetting and binary conversion. Determine Subnet Size Decide on the desired subnet size, typically represented as a CIDR not
2 min read
How do I Find Subnet Mask for an IP Address?
Answer: By checking the network configuration settings on your device or by using command-line tools like ipconfig (Windows) or ifconfig (Linux/macOS).To find the subnet mask for an IP address, several methods are available depending on your device's operating system or network tools. Network SettingsOn Windows, macOS, or Linux, access the network
1 min read
What is Subnet Mask for the 255.255.255.248?
Answer: The address 255.255.255.248 is itself a subnet mask for the /29 CIDR address.The 255.255.255.248 has no subnet mask as it itself is a subnet mask. It can be subnet mask of Class A, Class B or Class C address. In CIDR representation it is the subnet mask of /29 networks. Below table represents the number of network, subnets and hosts in diff
2 min read
Why is Subnet Mask Size Crucial in Network Subnetting?
Answer: Subnet mask size is important in network subnetting as it determines IP address allocation and defines network boundaries for better management, security, and routing optimization.Below are the reasons specify why the subnet mask size is important in network subnetting. Address AllocationThe subnet mask actually determines the size of the s
2 min read
Virtual Length Subnet Mask (VLSM ) in IP Networking
VLSM is an IP routing technique that is applied for optimal use of the available Internet Protocol address space. Specifically, with the virtue of CIDR (Classless Inter-domain Routing), the IP address space is segmented into variable-size subnets against the obscured of the actual number of hosts within each subnet. Typically, such a strategy cause
9 min read
Article Tags :
three90RightbarBannerImg