Network & delivery
10 min readUpdatedWhat is a subnet mask? Net masks, CIDR notation and wildcard masks
Quick answer
A subnet mask, or net mask, is a 32-bit value that marks which bits of an IPv4 address identify the network and which identify the host. It is written like an address, for example 255.255.255.0, with all its one-bits on the left. A device ANDs its address with the mask to find its network, then decides whether a destination is local or must go to the router. CIDR writes the same mask as a prefix length, such as /24.
01What is a subnet mask?
A subnet mask tells a device how much of its IPv4 address is network and how much is host. Every bit set to 1 in the mask belongs to the network part, every 0 to the host part, and the ones always come first. 255.255.255.0 is 24 ones followed by 8 zeros: the first three numbers of the address name the network, the last one numbers the hosts on it.
The device uses the mask for one decision on every packet it sends. If the destination is in its own network, it delivers the packet directly on the local link; if not, it hands the packet to its default gateway. A wrong mask breaks exactly that decision, which is why the symptoms in the troubleshooting table at the end look so odd.
Subnetting was standardised in RFC 950 in August 1985. Subnet mask, netmask and net mask all mean the same thing: ifconfig prints netmask, the Linux ip command prints the prefix length and Windows ipconfig prints Subnet Mask. Every IP address on a network is read through one.
02How a subnet mask works: the binary AND, step by step
To find its network, a host performs a bitwise AND of its address and the mask: each output bit is 1 only where both input bits are 1. Take 192.168.10.77 with the mask 255.255.255.192. The first three octets pass through unchanged, because the mask is 255 there. Only the last octet needs work: 77 is 01001101 and 192 is 11000000, so the result is 01000000, which is 64.
The network is therefore 192.168.10.64. The six host bits the mask left at 0 give 2^6 = 64 addresses, from 192.168.10.64 to 192.168.10.127. The first is the network address and the last, with every host bit set to 1, is the broadcast address, so hosts use .65 to .126: 62 of them.
- Write the address and the mask in binary, octet by octet
- AND them bit by bit: the result is the network address
- Set every host bit of the network address to 1: that is the broadcast address
- Everything between the two is the usable host range
address 192.168.10.77 11000000.10101000.00001010.01001101
mask 255.255.255.192 11111111.11111111.11111111.11000000
AND 192.168.10.64 11000000.10101000.00001010.01000000 network
host bits set to 1 11000000.10101000.00001010.01111111 broadcast 192.168.10.127
$ python3 -c "import ipaddress as i; n = i.ip_interface('192.168.10.77/26'); print(n.network, n.netmask, n.hostmask, n.network.broadcast_address)"
192.168.10.64/26 255.255.255.192 0.0.0.63 192.168.10.12703Subnet mask to CIDR notation
CIDR notation writes the mask as the number of one-bits after a slash: 255.255.255.0 is /24 and 255.255.255.192 is /26. Classless Inter-Domain Routing arrived with RFC 1519 in 1993 and is now specified in RFC 4632. It replaced fixed class sizes with prefixes of any length, and it is how routers, firewalls and cloud consoles describe networks today.
Converting by hand needs only the nine values a mask octet can take, because RFC 4632 requires the ones to be contiguous. Add 8 for every 255, then the one-bits of the last non-zero octet: 255.255.240.0 is 8 + 8 + 4 = /20. The block size in that octet, 256 minus its value, is the step between consecutive networks, so with 255.255.255.224 a new network starts every 32 addresses.
| Mask octet | Binary | One-bits | Block size |
|---|---|---|---|
| 0 | 00000000 | 0 | 256 |
| 128 | 10000000 | 1 | 128 |
| 192 | 11000000 | 2 | 64 |
| 224 | 11100000 | 3 | 32 |
| 240 | 11110000 | 4 | 16 |
| 248 | 11111000 | 5 | 8 |
| 252 | 11111100 | 6 | 4 |
| 254 | 11111110 | 7 | 2 |
| 255 | 11111111 | 8 | 1 |
04Subnet mask cheat sheet: every prefix from /0 to /32
The table lists all 33 IPv4 masks with where each size usually turns up. Usable hosts subtract the network and broadcast addresses, except for /31, which RFC 3021 lets point-to-point links use in full, and /32, a single address. Prefixes shorter than /8 describe route summaries and reserved blocks rather than networks anyone numbers hosts in. To work out a specific network, use the subnet calculator.
| Prefix | Subnet mask | Wildcard | Addresses | Usable hosts | Where you meet it |
|---|---|---|---|---|---|
| /0 | 0.0.0.0 | 255.255.255.255 | 4,294,967,296 | 4,294,967,294 | 0.0.0.0/0, the default route that matches every address |
| /1 | 128.0.0.0 | 127.255.255.255 | 2,147,483,648 | 2,147,483,646 | Half the address space; VPN clients may route 0.0.0.0/1 and 128.0.0.0/1 to override the default route |
| /2 | 192.0.0.0 | 63.255.255.255 | 1,073,741,824 | 1,073,741,822 | Route summaries only, never one network |
| /3 | 224.0.0.0 | 31.255.255.255 | 536,870,912 | 536,870,910 | 224.0.0.0/3 spans the old classes D and E |
| /4 | 240.0.0.0 | 15.255.255.255 | 268,435,456 | 268,435,454 | 224.0.0.0/4 is all of multicast (the old class D); 240.0.0.0/4 is reserved |
| /5 | 248.0.0.0 | 7.255.255.255 | 134,217,728 | 134,217,726 | Eight /8s; route summaries only |
| /6 | 252.0.0.0 | 3.255.255.255 | 67,108,864 | 67,108,862 | Four /8s; route summaries only |
| /7 | 254.0.0.0 | 1.255.255.255 | 33,554,432 | 33,554,430 | Two /8s |
| /8 | 255.0.0.0 | 0.255.255.255 | 16,777,216 | 16,777,214 | Private 10.0.0.0/8, see private IP address ranges; the old class A |
| /9 | 255.128.0.0 | 0.127.255.255 | 8,388,608 | 8,388,606 | Half of a /8 |
| /10 | 255.192.0.0 | 0.63.255.255 | 4,194,304 | 4,194,302 | 100.64.0.0/10, shared space for carrier-grade NAT (RFC 6598) |
| /11 | 255.224.0.0 | 0.31.255.255 | 2,097,152 | 2,097,150 | 32 /16s |
| /12 | 255.240.0.0 | 0.15.255.255 | 1,048,576 | 1,048,574 | Private 172.16.0.0/12 (RFC 1918) |
| /13 | 255.248.0.0 | 0.7.255.255 | 524,288 | 524,286 | Eight /16s |
| /14 | 255.252.0.0 | 0.3.255.255 | 262,144 | 262,142 | Four /16s |
| /15 | 255.254.0.0 | 0.1.255.255 | 131,072 | 131,070 | 198.18.0.0/15, reserved for network benchmarking (RFC 2544) |
| /16 | 255.255.0.0 | 0.0.255.255 | 65,536 | 65,534 | Private 192.168.0.0/16, link-local 169.254.0.0/16, cloud network ranges; the old class B |
| /17 | 255.255.128.0 | 0.0.127.255 | 32,768 | 32,766 | Half of a /16 |
| /18 | 255.255.192.0 | 0.0.63.255 | 16,384 | 16,382 | A quarter of a /16 |
| /19 | 255.255.224.0 | 0.0.31.255 | 8,192 | 8,190 | 32 /24s |
| /20 | 255.255.240.0 | 0.0.15.255 | 4,096 | 4,094 | 16 /24s; large campus or data-centre ranges |
| /21 | 255.255.248.0 | 0.0.7.255 | 2,048 | 2,046 | Eight /24s; large Wi-Fi or campus networks |
| /22 | 255.255.252.0 | 0.0.3.255 | 1,024 | 1,022 | Four /24s; the single allocation each RIPE NCC member could receive from 2012 to 2019 |
| /23 | 255.255.254.0 | 0.0.1.255 | 512 | 510 | Two /24s: a LAN that outgrew 254 hosts |
| /24 | 255.255.255.0 | 0.0.0.255 | 256 | 254 | Home and office LANs; the smallest block routed globally, see the /24 subnet mask |
| /25 | 255.255.255.128 | 0.0.0.127 | 128 | 126 | Half of a /24 |
| /26 | 255.255.255.192 | 0.0.0.63 | 64 | 62 | Department VLANs, small server ranges |
| /27 | 255.255.255.224 | 0.0.0.31 | 32 | 30 | Small offices, DMZ segments |
| /28 | 255.255.255.240 | 0.0.0.15 | 16 | 14 | Small public blocks, appliance segments |
| /29 | 255.255.255.248 | 0.0.0.7 | 8 | 6 | Static IP blocks from ISPs, see the /29 subnet mask |
| /30 | 255.255.255.252 | 0.0.0.3 | 4 | 2 | Classic point-to-point links |
| /31 | 255.255.255.254 | 0.0.0.1 | 2 | 2 | Point-to-point links (RFC 3021) |
| /32 | 255.255.255.255 | 0.0.0.0 | 1 | 1 | One host: loopbacks, firewall rules, host routes |
05/25, /26 and /27 subnet masks: dividing a network into equal parts
Each extra network bit halves the subnet. A /25 (255.255.255.128) cuts a /24 into two halves of 128 addresses. A /26 subnet mask, 255.255.255.192, leaves 6 host bits: 64 addresses and 62 usable hosts, four networks per /24. A /27 subnet mask, 255.255.255.224, leaves 5: 32 addresses and 30 usable hosts, eight per /24.
A network of a given size must start on a multiple of its block size. 10.20.30.64/26 is a valid network; 10.20.30.96 cannot start a /26, because 96 is not a multiple of 64, and with that mask it is simply a host inside 10.20.30.64/26. Every /26 holds exactly two /27s, so the two sizes nest without gaps.
| Network | Mask | Host range | Broadcast |
|---|---|---|---|
| 10.20.30.0/26 | 255.255.255.192 | 10.20.30.1 to 10.20.30.62 | 10.20.30.63 |
| 10.20.30.64/26 | 255.255.255.192 | 10.20.30.65 to 10.20.30.126 | 10.20.30.127 |
| 10.20.30.128/26 | 255.255.255.192 | 10.20.30.129 to 10.20.30.190 | 10.20.30.191 |
| 10.20.30.192/26 | 255.255.255.192 | 10.20.30.193 to 10.20.30.254 | 10.20.30.255 |
| 10.20.30.0/27 | 255.255.255.224 | 10.20.30.1 to 10.20.30.30 | 10.20.30.31 |
| 10.20.30.32/27 | 255.255.255.224 | 10.20.30.33 to 10.20.30.62 | 10.20.30.63 |
| 10.20.30.64/27 to 10.20.30.224/27 | 255.255.255.224 | Six more networks, each starting 32 higher | Network address + 31 |
06What is a wildcard mask?
A wildcard mask is the inverse of a subnet mask: a 0 bit must match, a 1 bit is ignored. Subtract each octet of the subnet mask from 255 to get it, so 255.255.255.192 becomes 0.0.0.63. Cisco IOS access lists and OSPF network statements use wildcard masks, and Cisco's documentation also calls them inverse masks.
In a Cisco access list, 192.168.10.64 0.0.0.63 therefore matches the same 64 addresses as 192.168.10.64/26. Most other systems, including Linux firewalls and cloud security groups, expect prefixes or ordinary masks, so convert before copying a rule from one to the other.
07Classful addressing: class A, B and C networks
Before CIDR, the first bits of an address fixed the size of its network. RFC 791 (1981) defined classes A, B and C; RFC 1112 (1989), the IP multicast standard, uses class D for multicast and reserves class E. A class B network IP address starts with the bits 10, so it lies between 128.0.0.0 and 191.255.255.255, carries an implied 255.255.0.0 mask and holds 65,536 addresses; there were 16,384 such networks.
Classes wasted space. An organisation needing 2,000 addresses had to take a class B of 65,536, or juggle several class C networks that each needed its own route. CIDR removed the classes in 1993, so today a class is only a label: 172.16.0.0/12 is private space spanning 16 old class B networks, and 10.0.0.0/8 is one old class A.
| Class | First bits | Range | Implied mask | Networks | Addresses each |
|---|---|---|---|---|---|
| A | 0 | 0.0.0.0 to 127.255.255.255 | 255.0.0.0 (/8) | 128, of which 0 and 127 are reserved | 16,777,216 |
| B | 10 | 128.0.0.0 to 191.255.255.255 | 255.255.0.0 (/16) | 16,384 | 65,536 |
| C | 110 | 192.0.0.0 to 223.255.255.255 | 255.255.255.0 (/24) | 2,097,152 | 256 |
| D | 1110 | 224.0.0.0 to 239.255.255.255 | None: multicast | Not applicable | Not applicable |
| E | 1111 | 240.0.0.0 to 255.255.255.255 | None: reserved | Not applicable | Not applicable |
08Wrong subnet mask: symptoms, causes and fixes
Mask errors rarely break everything. They break some destinations, which makes them easy to mistake for firewall or DNS problems. The cause sits on the host, the router's LAN interface or the DHCP scope, not at the remote site, so compare the prefix with ip -brief address show on Linux or ipconfig on Windows first. To see how the same addresses look from outside, the IP lookup shows the public prefix your network is announced in, and BGP explains how those prefixes are routed.
| Symptom | Likely cause | Test | Fix |
|---|---|---|---|
| Internet works, some local hosts unreachable | Mask too long, e.g. /25 on a /24 LAN: half the LAN looks remote and is sent to the gateway | Compare the host's prefix with the router's | Set the LAN's real prefix, or correct the DHCP scope |
| Local hosts work, some remote networks fail | Mask too short, e.g. /16 on a /24 LAN: remote addresses look local and get ARP requests | ip route get on a failing address shows no via gateway | Correct the mask |
| A new device reaches nothing, others are fine | Static address with a mask that does not include the gateway | Check that address AND mask equals gateway AND mask | Pick an address and mask that contain the gateway |
| Two hosts disagree about being on the same network | Different masks on each host | Compare both prefixes | Use one prefix per network segment |
| The system rejects the mask | Not contiguous, e.g. 255.255.0.255 | Write it out in binary | Use one of the nine valid octet values |
Questions
Frequently asked questions
Sources
Sources and verification
Every mask, wildcard, host count and range on this page was computed with Python 3.11's ipaddress module and the binary example checked bit by bit; the ip commands named in the troubleshooting table were run with iproute2 6.1.0 in an isolated network namespace; Debian 12, October 2026.
- 01RFC 950: Internet Standard Subnetting Procedure · RFC Editor
- 02RFC 4632: Classless Inter-domain Routing (CIDR) · RFC Editor
- 03RFC 1519: Classless Inter-Domain Routing (CIDR), 1993 · RFC Editor
- 04RFC 791: Internet Protocol (address classes) · RFC Editor
- 05RFC 1112: Host Extensions for IP Multicasting (class D) · RFC Editor
- 06RFC 3021: Using 31-Bit Prefixes on IPv4 Point-to-Point Links · RFC Editor
- 07RFC 4291: IP Version 6 Addressing Architecture · RFC Editor
- 08RIPE-690: IPv6 prefix assignment for end-users · RIPE
- 09IPv4 Run-out (final /8 policy and /22 allocations) · RIPE NCC
- 10Configure IP Access Lists (inverse masks) · Cisco
- 11Implementing OSPFv2 using network commands (wildcard masks) · Cisco Press
- 12IANA IPv4 Special-Purpose Address Registry · IANA
- 13OpenVPN 2.6 manual (--redirect-gateway def1) · OpenVPN
Last updated