Role of Subnet Mask (original) (raw)
Last Updated : 2 Jan, 2026
A subnet mask is a 32-bit number used with an IP address to divide it into two parts:
- the network ID, and
- the host ID.
In a subnet mask:
- Binary 1s represent the network portion of the IP address.
- Binary 0s represent the host portion.
The subnet mask helps a device determine whether another device is on the same local network or on a different network, which in turn decides whether communication is direct or must go through a router.
**For example:

Role of Subnet Mask
Subnet masks help divide a large network into smaller logical networks called subnets, which improves network efficiency, security, and performance by reducing broadcast traffic and enabling better network management.
Function of Subnet Mask
- Separates an IP address into network ID and host ID.
- Divides a large network into smaller subnets for better organization.
- Improves network efficiency, security, and manageability by reducing unnecessary traffic.
- Helps routers determine whether a packet should be forwarded locally or to another network.
Why Use a Subnet Mask?
Consider a Class A network, which can support approximately 16 million hosts. Managing such a large network as a single unit is impractical and introduces several challenges:
- Maintenance becomes difficult due to the large number of connected devices.
- Security risks increase, as all devices share the same network.
For example, in an organization with multiple departments, allowing every department access to the entire network is neither efficient nor secure.
**Solution: Subnetting
Subnetting addresses these issues by dividing a large network into smaller, manageable sub-networks called subnets using a subnet mask. Each department can be assigned its own subnet, which:
- Improves security by isolating departments
- Enhances network efficiency by reducing unnecessary traffic
- Simplifies network management
In a network without subnetting, identifying a device involves three steps:
- Identification of the network
- Identification of the host
- Identification of the process
When subnetting is applied, address identification becomes more structured and involves four steps:
- 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.

Representation of Subnet Masks
Class C Network: 200.1.2.0/24 i.e. divided into 4 subnets.
- Borrow 2 bits from the host part.
- Subnet mask: 255.255.255.192
- Binary: 11111111.11111111.11111111.11000000
Subnet Matching (Bitwise AND):
IP Address: 200.1.2.20 → 11001000.00000001.00000010.00010100
Subnet Mask: 255.255.255.192 → 11111111.11111111.11111111.11000000
Result: 200.1.2.0 → 11001000.00000001.00000010.00000000
So, IP 200.1.2.20 belongs to subnet 200.1.2.0/26.
**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.

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.
Network Classes
The Internet Assigned Numbers Authority (IANA), through InterNIC, manages the allocation of IP addresses.
To simplify addressing, IP addresses are divided into five classes (A–E):
- **Class A, B, C: Commonly used by end users.
- **Class D: Reserved for multicast.
- **Class E: Reserved for experimental purposes.
Each class has a default subnet mask, and the first octet (first 8 bits) determines the class.

Range of Classes
Read more about classful IP addressing.
**Advantages of Subnetting
- **Reduces Congestion: Limits broadcast traffic, improving network performance.
- **Efficient IP Usage: Allocates IPs based on need, avoiding wastage.
- **Enhanced Security: Isolates sensitive data within specific subnets.
- **Departmental Segmentation: Prioritizes traffic for specific teams or services.
- **Scalable & Organized: Makes network expansion easier and manageable.
**Disadvantages of Subnetting
- **Fewer Usable Addresses: Network and broadcast IDs reduce host capacity.
- **Higher Hardware Costs: Routers or Layer-3 devices are often required.
- **Complex Setup: Needs careful planning and technical expertise.
- **Compatibility Issues: Legacy devices may not support modern subnets.