A Subnet Mask is a core networking concept that works in tandem with an IP Address. While an IP address identifies a device, the subnet mask determines how much of that IP address represents the network, and how much represents the specific host.
When a computer wants to send a packet, it uses its subnet mask to answer one critical question: "Is the destination IP address on my local network, or is it on a remote network?"
How a Subnet Mask Works
Like an IPv4 address, a subnet mask is a 32-bit number, typically written in dotted-decimal notation (e.g., 255.255.255.0). In binary, a subnet mask is always a contiguous string of 1s followed by a contiguous string of 0s.
- The
1s represent the Network Bits. - The
0s represent the Host Bits.
CIDR Notation
Network engineers rarely say "two-five-five dot two-five-five dot two-five-five dot zero". Instead, they use CIDR (Classless Inter-Domain Routing) notation, also known as slash notation. This simply counts the number of 1s in the binary subnet mask.
Common Examples:
- /24 (255.255.255.0): The most common mask for home and small office networks. The first three numbers (24 bits) are the network; the last number (8 bits) is the host. It provides 254 usable IPs.
- /16 (255.255.0.0): Used for larger enterprise networks. The first two numbers are the network; the last two are hosts. It provides 65,534 usable IPs.
- /30 (255.255.255.252): Used exclusively for point-to-point router links. It provides exactly 2 usable IP addresses.
Determining Local vs Remote
If PC-A (192.168.1.10 with mask 255.255.255.0) wants to ping 192.168.1.50, PC-A compares the network portions. Since both start with 192.168.1, PC-A knows the destination is on the local network and communicates directly using a switch.
However, if PC-A wants to ping 8.8.8.8, it sees the networks do not match. PC-A must forward this packet to its Default Gateway (the router) to handle delivery.
Simple Subnetting Example
Imagine a company is assigned the block 203.0.113.0/24 (254 IPs). Instead of putting all computers in one giant network, the network engineer divides it into two smaller subnets using a /25 mask (255.255.255.128).
- Subnet 1:
203.0.113.0/25(Hosts: .1 to .126) - Assigned to Sales. - Subnet 2:
203.0.113.128/25(Hosts: .129 to .254) - Assigned to HR.
This isolates the traffic and improves security. For deeper calculations, see Subnetting Basics.
Commands to View Subnet Masks
Windows
IPv4 Address. . . . . . . . . . . : 192.168.1.15
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Linux (CIDR Notation)
Modern Linux displays the subnet mask using CIDR notation directly attached to the IP address.
inet 192.168.1.15/24 brd 192.168.1.255 scope global eth0
Troubleshooting Incorrect Subnet Masks
A mismatched subnet mask is a classic, difficult-to-diagnose networking problem.
1. The "Too Small" Mask
Scenario: A router is configured as 192.168.1.1/24 (Mask: 255.255.255.0). A PC is statically misconfigured as 192.168.1.10/26 (Mask: 255.255.255.192). A server on the same physical switch is at 192.168.1.100/24.
Result: The PC cannot reach the server! Based on the PC's /26 mask, its local network ends at .62. The PC thinks the server at .100 is on a remote network and sends the traffic to the router instead of directly to the server. The router might drop it, causing a bizarre one-way communication failure.
2. The "Too Large" Mask
Scenario: A PC is misconfigured with a /16 mask (255.255.0.0) while the rest of the network is /24.
Result: The PC thinks a massive range of IPs are physically local to it. If it tries to reach an IP that is actually on the internet (e.g., 192.168.5.5, which might be a remote branch office), it will broadcast locally asking for it instead of sending the packet to the Default Gateway. The traffic will never reach the remote branch.
Quick Summary
- A subnet mask splits an IP address into a Network portion and a Host portion.
- It allows a computer to determine if a destination is local or remote (requiring Routing).
- /24 is CIDR notation for
255.255.255.0. - Mismatched masks on the same network will cause severe and confusing connectivity drops.