Network & delivery

10 min readUpdated

What 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
The worked example in binary, and the same result from Python 3.11's ipaddress module (run on Debian 12)
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.127

03Subnet 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 octetBinaryOne-bitsBlock size
0000000000256
128100000001128
19211000000264
22411100000332
24011110000416
2481111100058
2521111110064
2541111111072
2551111111181

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.

PrefixSubnet maskWildcardAddressesUsable hostsWhere you meet it
/00.0.0.0255.255.255.2554,294,967,2964,294,967,2940.0.0.0/0, the default route that matches every address
/1128.0.0.0127.255.255.2552,147,483,6482,147,483,646Half the address space; VPN clients may route 0.0.0.0/1 and 128.0.0.0/1 to override the default route
/2192.0.0.063.255.255.2551,073,741,8241,073,741,822Route summaries only, never one network
/3224.0.0.031.255.255.255536,870,912536,870,910224.0.0.0/3 spans the old classes D and E
/4240.0.0.015.255.255.255268,435,456268,435,454224.0.0.0/4 is all of multicast (the old class D); 240.0.0.0/4 is reserved
/5248.0.0.07.255.255.255134,217,728134,217,726Eight /8s; route summaries only
/6252.0.0.03.255.255.25567,108,86467,108,862Four /8s; route summaries only
/7254.0.0.01.255.255.25533,554,43233,554,430Two /8s
/8255.0.0.00.255.255.25516,777,21616,777,214Private 10.0.0.0/8, see private IP address ranges; the old class A
/9255.128.0.00.127.255.2558,388,6088,388,606Half of a /8
/10255.192.0.00.63.255.2554,194,3044,194,302100.64.0.0/10, shared space for carrier-grade NAT (RFC 6598)
/11255.224.0.00.31.255.2552,097,1522,097,15032 /16s
/12255.240.0.00.15.255.2551,048,5761,048,574Private 172.16.0.0/12 (RFC 1918)
/13255.248.0.00.7.255.255524,288524,286Eight /16s
/14255.252.0.00.3.255.255262,144262,142Four /16s
/15255.254.0.00.1.255.255131,072131,070198.18.0.0/15, reserved for network benchmarking (RFC 2544)
/16255.255.0.00.0.255.25565,53665,534Private 192.168.0.0/16, link-local 169.254.0.0/16, cloud network ranges; the old class B
/17255.255.128.00.0.127.25532,76832,766Half of a /16
/18255.255.192.00.0.63.25516,38416,382A quarter of a /16
/19255.255.224.00.0.31.2558,1928,19032 /24s
/20255.255.240.00.0.15.2554,0964,09416 /24s; large campus or data-centre ranges
/21255.255.248.00.0.7.2552,0482,046Eight /24s; large Wi-Fi or campus networks
/22255.255.252.00.0.3.2551,0241,022Four /24s; the single allocation each RIPE NCC member could receive from 2012 to 2019
/23255.255.254.00.0.1.255512510Two /24s: a LAN that outgrew 254 hosts
/24255.255.255.00.0.0.255256254Home and office LANs; the smallest block routed globally, see the /24 subnet mask
/25255.255.255.1280.0.0.127128126Half of a /24
/26255.255.255.1920.0.0.636462Department VLANs, small server ranges
/27255.255.255.2240.0.0.313230Small offices, DMZ segments
/28255.255.255.2400.0.0.151614Small public blocks, appliance segments
/29255.255.255.2480.0.0.786Static IP blocks from ISPs, see the /29 subnet mask
/30255.255.255.2520.0.0.342Classic point-to-point links
/31255.255.255.2540.0.0.122Point-to-point links (RFC 3021)
/32255.255.255.2550.0.0.011One 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.

NetworkMaskHost rangeBroadcast
10.20.30.0/26255.255.255.19210.20.30.1 to 10.20.30.6210.20.30.63
10.20.30.64/26255.255.255.19210.20.30.65 to 10.20.30.12610.20.30.127
10.20.30.128/26255.255.255.19210.20.30.129 to 10.20.30.19010.20.30.191
10.20.30.192/26255.255.255.19210.20.30.193 to 10.20.30.25410.20.30.255
10.20.30.0/27255.255.255.22410.20.30.1 to 10.20.30.3010.20.30.31
10.20.30.32/27255.255.255.22410.20.30.33 to 10.20.30.6210.20.30.63
10.20.30.64/27 to 10.20.30.224/27255.255.255.224Six more networks, each starting 32 higherNetwork 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.

ClassFirst bitsRangeImplied maskNetworksAddresses each
A00.0.0.0 to 127.255.255.255255.0.0.0 (/8)128, of which 0 and 127 are reserved16,777,216
B10128.0.0.0 to 191.255.255.255255.255.0.0 (/16)16,38465,536
C110192.0.0.0 to 223.255.255.255255.255.255.0 (/24)2,097,152256
D1110224.0.0.0 to 239.255.255.255None: multicastNot applicableNot applicable
E1111240.0.0.0 to 255.255.255.255None: reservedNot applicableNot 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.

SymptomLikely causeTestFix
Internet works, some local hosts unreachableMask too long, e.g. /25 on a /24 LAN: half the LAN looks remote and is sent to the gatewayCompare the host's prefix with the router'sSet the LAN's real prefix, or correct the DHCP scope
Local hosts work, some remote networks failMask too short, e.g. /16 on a /24 LAN: remote addresses look local and get ARP requestsip route get on a failing address shows no via gatewayCorrect the mask
A new device reaches nothing, others are fineStatic address with a mask that does not include the gatewayCheck that address AND mask equals gateway AND maskPick an address and mask that contain the gateway
Two hosts disagree about being on the same networkDifferent masks on each hostCompare both prefixesUse one prefix per network segment
The system rejects the maskNot contiguous, e.g. 255.255.0.255Write it out in binaryUse one of the nine valid octet values

Questions

Frequently asked questions

The subnet mask defines which addresses are on your local network; the default gateway is the router that receives everything else. The mask is applied first: if a destination falls inside your network the packet goes straight to it, otherwise to the gateway. The gateway's own address must lie inside the network the mask defines, or the host cannot reach it at all.

It is a /26: 26 network bits and 6 host bits, so 64 addresses, of which 62 are usable hosts. Networks with this mask start at .0, .64, .128 and .192 within each /24, and the matching wildcard mask is 0.0.0.63. It is a common size for a department VLAN or a small range of servers.

30. A /27, written 255.255.255.224, leaves 5 host bits, which gives 2^5 = 32 addresses; the first is the network address and the last the broadcast address. Eight /27 networks fit into one /24, starting every 32 addresses at .0, .32, .64 and so on up to .224. The wildcard mask is 0.0.0.31.

Not in dotted form. IPv6 always uses prefix lengths, such as 2001:db8:1:2::/64. Almost every IPv6 LAN is a /64, because RFC 4291 fixes interface identifiers at 64 bits, and the RIPE community's guidance recommends giving each end user a /48 or a /56 so they can create many /64 networks. IPv6 has no broadcast address, so nothing is subtracted for one.

Not today. RFC 950 in 1985 technically allowed non-contiguous subnet bits while recommending against them, but CIDR requires the mask to be contiguous: a run of ones followed by a run of zeros. Each octet must therefore be 0, 128, 192, 224, 240, 248, 252, 254 or 255, and a value such as 255.0.255.0 is rejected by modern systems.

Because 254 usable addresses suit almost every home network, the arithmetic is easy (the last number is the host), and it matches the old class C size that 192.168.x.0 networks were built on. Nothing requires it: a home network can use a /23 or a /25 instead, as long as the router and every device agree on the same mask.

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.

  1. 01RFC 950: Internet Standard Subnetting Procedure · RFC Editor
  2. 02RFC 4632: Classless Inter-domain Routing (CIDR) · RFC Editor
  3. 03RFC 1519: Classless Inter-Domain Routing (CIDR), 1993 · RFC Editor
  4. 04RFC 791: Internet Protocol (address classes) · RFC Editor
  5. 05RFC 1112: Host Extensions for IP Multicasting (class D) · RFC Editor
  6. 06RFC 3021: Using 31-Bit Prefixes on IPv4 Point-to-Point Links · RFC Editor
  7. 07RFC 4291: IP Version 6 Addressing Architecture · RFC Editor
  8. 08RIPE-690: IPv6 prefix assignment for end-users · RIPE
  9. 09IPv4 Run-out (final /8 policy and /22 allocations) · RIPE NCC
  10. 10Configure IP Access Lists (inverse masks) · Cisco
  11. 11Implementing OSPFv2 using network commands (wildcard masks) · Cisco Press
  12. 12IANA IPv4 Special-Purpose Address Registry · IANA
  13. 13OpenVPN 2.6 manual (--redirect-gateway def1) · OpenVPN

Last updated