A subnet mask is a 32-bit number that divides an IP address into network ID and host ID.
- 1s represent the network portion.
- 0s represent the host portion.
It helps determine whether two devices are on the same local network or different ones.
For example:
Role of Subnet MaskSubnet masks help divide a large network into smaller sub-networks (subnets), improving network efficiency, security, and performance.
Function of Subnet Mask
- Separates network ID and host ID.
- Organizes networks into smaller subnets.
- Improves efficiency, security, and manageability of networks.
- Helps routers decide where to forward packets.
Why Use a Subnet Mask?
Suppose we have a Class A network which means we have 16 million hosts in a network. Managing such a large network becomes challenging due to:
- 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 access to the whole network.
Solution: Subnetting
Subnetting solves these problems by dividing a large network into smaller, manageable sub-networks (subnets). Each department gets its own subnet, improving security and efficiency.
Without subnetting, identifying a device requires three 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 –
- 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 ClassesRead more about classful IP addressing.
Advantages of Subnetting
- Reduces Congestion: Minimizes broadcast traffic, improving network speed.
- Efficient IP Allocation: Distributes IPs based on need, preventing wastage.
- Improved Security: Isolates subnets so sensitive data (e.g., developer code) stays protected.
- Departmental Segmentation: Allows priority handling for specific subnets (e.g., sales video conferencing).
- Supports Scalability: Makes it easier to expand networks while keeping them organized.
Disadvantages of Subnetting
- Reduced IP Address Space: Each subnet reserves addresses for network ID and broadcast, decreasing usable host addresses.
- Additional Hardware Costs: Often requires routers or Layer-3 devices to connect subnets, increasing expenses.
- Complex Configuration: Proper planning and subnetting design require technical expertise.
- Compatibility Issues: Older devices or legacy systems may not fully support subnetting schemes.
Explore
Computer Network Basics
Physical Layer
Data Link Layer
Network Layer
Transport Layer
Session Layer & Presentation Layer
Application Layer
Advanced Topics
Practice