What is a Subnet Mask?
Subnet masks explained: how they divide networks and how to calculate them.
A subnet mask is a 32-bit number that splits an IP address into two parts: the network portion, which identifies the network, and the host portion, which identifies a specific device on that network. It is the mechanism that lets your computer decide whether another device is on the same local network or somewhere beyond the router.
The mask works by performing a bitwise AND operation against the IP address. Every bit set to 1 in the mask claims a bit of the address for the network; every bit set to 0 leaves room for hosts. 255.255.255.0 — the most common home-network mask — claims the first three octets for the network and leaves the last octet for up to 254 devices.
What is a subnet mask?
A subnet mask is a 32-bit value, usually written in dotted-decimal notation just like an IP address, such as 255.255.255.0. It travels alongside every IP address on a network and defines how much of that address identifies the network versus the device.
Together, an IP address and a subnet mask define a subnet — a single broadcast domain where devices can talk to each other directly through a switch without involving a router. The mask is what draws the boundary between "local" and "remote".
How do subnet masks divide networks?
When your computer wants to send a packet to another IP address, it ANDs both its own address and the destination address with the subnet mask. If the resulting network portions match, the destination is local and the packet goes directly to it. If they differ, the packet is handed to the default gateway (your router) to be forwarded elsewhere.
Take 192.168.1.20 with mask 255.255.255.0. The mask claims the first 24 bits, so the network is 192.168.1.0 and the host portion is 20. Any address from 192.168.1.1 to 192.168.1.254 shares the same network portion and is reachable directly. 192.168.2.5 has a different network portion, so traffic to it must leave through the router.
CIDR notation explained
CIDR (Classless Inter-Domain Routing) notation is a compact way to write a subnet mask as a slash followed by the number of network bits. /24 means the first 24 bits are the network portion — the same as 255.255.255.0. /16 is 255.255.0.0, and /8 is 255.0.0.0.
The number after the slash directly controls the size of the network. Each bit you subtract from the prefix doubles the number of networks you can create while halving the hosts in each: /24 gives 254 host addresses, /25 gives 126, /26 gives 62, and so on. CIDR replaced the older classful system (Class A, B, C) because it lets administrators carve networks to the exact size they need instead of being forced into three fixed sizes.
Common subnet masks and what they mean
255.255.255.0 (/24) is the workhorse of home and small office networks: one network with up to 254 usable hosts. Two special addresses are reserved — the network address itself (host bits all zero) and the broadcast address (host bits all one) — which is why the usable count is 254 rather than 256.
Larger masks shrink the host space: 255.255.255.128 (/25) splits a /24 into two networks of 126 hosts each. Going the other way, 255.255.0.0 (/16) supports over 65,000 hosts on a single network, which is why enterprises and cloud providers use it internally. A mask of 255.255.255.255 (/32) matches exactly one address and is used for host routes.
How to calculate subnets
Subnet calculation starts with the mask. Convert it to binary and count the 1 bits to get the prefix length; the remaining 0 bits define the host space. The number of usable hosts is 2 to the power of the host bits, minus 2 for the network and broadcast addresses. For /26: 6 host bits gives 64 minus 2, so 62 usable addresses.
To split a network into smaller ones, borrow bits from the host portion. Borrowing 2 bits from a /24 creates four /26 subnets: 192.168.1.0, 192.168.1.64, 192.168.1.128, and 192.168.1.192. The block size is 256 minus the subnet's last octet value — in this case 64 — and each subnet reserves its first and last address, leaving 62 usable hosts per subnet.