What is a Subnet Mask?
A subnet mask is a 32-bit number used in IPv4 networking to determine which portion of an IP address refers to the network and which portion refers to the individual host (device). Every IPv4 address has an associated subnet mask that makes IP routing possible.
Without a subnet mask, a router or device cannot determine whether a destination IP address is on the local network (reachable directly) or on a remote network (must be forwarded to a gateway). The subnet mask answers this question by separating the IP address into two parts.
Binary Representation
At its core, a subnet mask is a 32-bit binary number consisting of a run of 1s followed by a run of 0s. The 1-bits indicate the network portion and the 0-bits indicate the host portion. For example:
11111111.11111111.11111111.00000000
└─────────── 24 ones ───────────┘└── 8 zeros ──┘This binary mask means the first 24 bits of any IP address identify the network, and the last 8 bits identify the host within that network.
Dotted-Decimal Notation
Because binary is hard to read, subnet masks are typically written in dotted-decimal notation — the same format as IPv4 addresses. Each 8-bit group (octet) is converted from binary to a decimal number:
| Binary Octet | Decimal Value |
|---|---|
| 11111111 | 255 |
| 11111110 | 254 |
| 11111100 | 252 |
| 11111000 | 248 |
| 11110000 | 240 |
| 11100000 | 224 |
| 11000000 | 192 |
| 10000000 | 128 |
| 00000000 | 0 |
So the binary mask above — 24 ones followed by 8 zeros — becomes 255.255.255.0 in dotted-decimal.
CIDR Notation
CIDR (Classless Inter-Domain Routing) notation is an even more compact way to express a subnet mask. Instead of writing the full mask, you simply write the number of 1-bits (the prefix length) after a slash:
192.168.1.0/24 ← IP address + prefix length
↑
24 bits = network portionThis is exactly equivalent to 192.168.1.0 with subnet mask 255.255.255.0. CIDR notation is standard in modern networking, cloud platforms (AWS, GCP, Azure), and all network documentation.
Network vs Host Bits
Applying a subnet mask to an IP address involves a bitwise AND operation. The result identifies the network address — the base address of the subnet that all hosts share:
IP address: 11000000.10101000.00000001.01100100 (192.168.1.100)
Subnet mask: 11111111.11111111.11111111.00000000 (255.255.255.0)
─────────────────────────────────────
Network addr: 11000000.10101000.00000001.00000000 (192.168.1.0)The broadcast address is found by setting all host bits to 1:
Broadcast: 11000000.10101000.00000001.11111111 (192.168.1.255)The usable host range is everything between the network address and broadcast address: 192.168.1.1 through 192.168.1.254 — giving 254 usable hosts.
Common Subnet Masks
| CIDR | Subnet Mask | Usable Hosts | Common Use |
|---|---|---|---|
| /8 | 255.0.0.0 | 16,777,214 | Class A (ISP blocks) |
| /16 | 255.255.0.0 | 65,534 | Class B (large orgs) |
| /24 | 255.255.255.0 | 254 | Class C (home/office) |
| /28 | 255.255.255.240 | 14 | Cloud VPC subnets |
| /30 | 255.255.255.252 | 2 | Point-to-point links |
| /32 | 255.255.255.255 | 1 | Single host route |
How to Calculate a Subnet Mask
You can calculate a subnet mask manually by following these steps:
- Decide on the CIDR prefix length (e.g.
/24). - Write 32 binary bits: place 1s for the first N bits (the prefix length), then 0s for the remaining bits.
- Group the 32 bits into four 8-bit octets.
- Convert each octet from binary to decimal.
Alternatively, use our free netmask calculator — enter any IP address and CIDR prefix and it instantly computes the subnet mask, network address, broadcast address, wildcard mask, host range, and more.