netmask
termKept in this browser · My desk
A mask with the network bits set to one and the host bits set to zero, written like an address (255.255.255.0) and equivalent to a prefix length (/24).
Request for Comments (RFC) 4632 explains the prefix 172.16.0.0/16 as a mask whose 16 most significant bits are ones and whose 16 least significant bits are zeros, and requires that "the mask must be left contiguous". Its bitwise inverse is the host mask, which access lists call a wildcard. Python's ipaddress accepts all three IPv4 forms after the slash (/24, /255.255.255.0 and /0.0.0.255) and refuses a mask that mixes ones and zeros; for IPv6 it accepts the prefix length only.
What it does. A netmask is a 32-bit value that marks which bits of an IPv4 address name the network and which name the host. A host applies it every time it sends a packet: Request for Comments (RFC) 1122 requires it to extract, with the mask, the same bits from the destination address and from its own, and to deliver directly if they match or hand the packet to a gateway if they do not. A router applies the mask of each route in the same way to decide whether the route covers a destination. The mask itself never travels in the Internet Protocol (IP) header; it is local configuration, which is why two hosts on one wire can hold different opinions about who their neighbours are. It has had several names for the same thing: address mask in RFC 950, subnet mask in most configuration screens, network mask or netmask in routing documents.
Where it came from. In the original classful scheme the mask was implied by the first bits of the address: 172.16.0.0, a Class B network, had an implied mask of 255.255.0.0. Subnetting needed something explicit. Jeffrey Mogul proposed it in RFC 917 (October 1984), and RFC 950, by Mogul and Jon Postel (August 1985), made it the standard, choosing a bit mask over four other schemes for marking the subnet field. Because the bits are named by a mask, RFC 950 noted, they need not be adjacent, but it recommended that they be contiguous and the most significant bits of the local part. It also defined two messages of the Internet Control Message Protocol (ICMP), Address Mask Request (type 17) and Address Mask Reply (type 18), so that a booting host could ask for its mask.
How the rule hardened. RFC 1122 (October 1989) still remarked that its notation did not imply contiguous one bits. Classless Inter-Domain Routing (CIDR) ended the tolerance: RFC 1519 (September 1993), and RFC 4632 which replaced it in August 2006, generalize routing to any network number and mask on the single condition that the mask be left contiguous. RFC 1812 (June 1995) says that discontiguous subnet masks are not permitted, because arbitrary masks can make routing ambiguous, with two equally specific routes matching one destination, and it describes the subnet mask as the historical name for what newer protocols express as a prefix length: a contiguous string of ones at the more significant end, a contiguous string of zeros at the other, and nothing in between. The ICMP messages lasted until RFC 6918 (April 2013) formally deprecated them as superseded by the Dynamic Host Configuration Protocol (DHCP), which carries the mask as option 1, four octets, placed before the router option.
The numbers. With contiguity required there are only 33 masks, one for each prefix length from 0 to 32, and each octet of a mask can take only nine values: 0, 128, 192, 224, 240, 248, 252, 254 and 255. RFC 1878 (December 1995) tabulates them all: /16 is 255.255.0.0, /23 is 255.255.254.0 with 512 addresses, /24 is 255.255.255.0 with 256, /27 is 255.255.255.224 with 32, /30 is 255.255.255.252 with 4, and /32, 255.255.255.255, is a single host route. A block holds two to the power of the number of zero bits, and in ordinary subnets two of those addresses, all zeros and all ones in the host part, are the network and the broadcast. That is why a /30 spends four addresses on a link with two ends, and why RFC 3021 (December 2000) allows the 31-bit mask 255.255.255.254 on point-to-point links. At the other extreme the mask 0.0.0.0 matches everything: 0.0.0.0/0 is the default route.
The inverse. Subtracting a mask from 255.255.255.255 gives its complement, 0.0.0.255 for a /24. Python's documentation calls it the host mask; Cisco access lists call it the wildcard or inverse mask, in which a 0 means that the bit must match and a 1 means that it is ignored. The two are easy to confuse because both look like addresses. Python decides by the first field: text after the slash that begins with a non-zero field is a net mask, text that begins with a zero field is a host mask, and an all-zero mask is taken as a net mask.
Where each form is typed. Linux shows both generations side by side. The ifconfig command takes netmask followed by a dotted mask, defaults to the old class A, B or C mask if none is given, and prints lines such as inet 203.0.113.9 netmask 255.255.255.0; the newer ip address command takes only an address followed by a slash and the prefix length. Windows keeps the mask in its route command, as in route add 10.41.0.0 mask 255.255.0.0 10.27.0.1; a missing mask defaults to 255.255.255.255, a host route, and a destination with bits set where the mask has zeros is refused with an error. FortiGate writes a prefix as a subnet followed by a netmask. F5 BIG-IP writes a self IP address as 10.10.10.24/16, yet gives a network virtual server a mask option in dotted form whose default, 255.255.255.255, makes it a host. In Python, an IPv4Network object exposes netmask, hostmask and with_netmask, which is the quickest way to convert between the three notations.
IPv6 has no netmask to type. RFC 4291 writes a prefix as an address, a slash and a decimal prefix length, the number of leftmost contiguous bits, and nothing else. Python says so explicitly: 2001:db00::0/24 is valid and 2001:db00::0/ffff:ff00:: is not. The mask still exists as arithmetic, and occasionally surfaces, as in the IPv6 default of that BIG-IP virtual server option, which is written out as eight groups of ffff.
What goes wrong. Because the mask drives the local or remote decision, a wrong one fails in a characteristic way. A mask that is too short makes a host believe that distant addresses are on its own segment, so it tries to reach them directly and never uses the gateway; a mask that is too long makes it send its neighbours' traffic to the gateway, or leaves the gateway itself outside the subnet. Old software fills in the classful mask when none is given, as ifconfig still documents, and the first version of the Routing Information Protocol (RIP) carried no mask at all. Software that validates masks rejects the malformed ones: Python raises an error for a mask that mixes ones and zeros, and RFC 1812 tells a router to check that an interface mask is neither all ones nor all zeros and that its one bits are contiguous. The lasting advice is in RFC 1812 itself: both representations are in common use, so an engineer has to read both, and convert without hesitation.
Also known as: subnet mask, network mask, net mask, 255.255.255.0
Sources
- IETF, RFC 4632 (BCP 122), Classless Inter-domain Routing (CIDR): The Internet Address Assignment and Aggregation Plan, V. Fuller and T. Li, August 2006, obsoletes RFC 1519 (read 2026-11-12): section 3.1, the prefix 172.16.0.0/16 as a mask of 16 ones and 16 zeros and the implied masks of the legacy classes; section 5.1, the mask must be left contiguous and 0.0.0.0/0 is the default route
- Python 3.13 documentation, ipaddress (read 2026-11-12): prefix, net mask and host mask; the host mask as the logical inverse of the net mask, used in Cisco access control lists; IPv4Network reads the text after the slash as a prefix, a net mask or, if it starts with a zero field, a host mask; expanded IPv6 netmasks are not supported; the netmask, hostmask and with_netmask attributes
- IETF, RFC 950, Internet Standard Subnetting Procedure, J. Mogul and J. Postel, August 1985 (read 2026-11-12): the address mask chosen among five schemes; the subnet bits need not be adjacent but should be contiguous and most significant; the all-zeros and all-ones subnet values; ICMP Address Mask Request (17) and Reply (18)
- IETF, RFC 917, Internet Subnets, J. Mogul, October 1984 (read 2026-11-12): the proposal that preceded RFC 950
- IETF, RFC 1122, Requirements for Internet Hosts, Communication Layers, October 1989 (read 2026-11-12): section 3.3.1.1, the local/remote decision by comparing the bits the address mask extracts; section 3.2.1.3, the notation does not imply that the one bits of a mask are contiguous; section 3.2.2.9, ways of learning the mask
- IETF, RFC 1812, Requirements for IP Version 4 Routers, F. Baker, June 1995 (read 2026-11-12): section 2.2.5, the subnet mask as the historical name, newer protocols refer to a prefix length, correct masks are a contiguous string of ones followed by zeros; section 10.2.2, discontiguous masks are not permitted and the checks a router makes on a mask
- IETF, RFC 1519, Classless Inter-Domain Routing (CIDR): an Address Assignment and Aggregation Strategy, September 1993 (read 2026-11-12): the same requirement that the mask be left contiguous
- IETF, RFC 1878, Variable Length Subnet Table For IPv4, T. Pummill and B. Manning, December 1995, Informational (read 2026-11-12): the table of masks in hexadecimal, prefix and dotted form with their address counts, from /1 to /32
- IETF, RFC 3021, Using 31-Bit Prefixes on IPv4 Point-to-Point Links, December 2000 (read 2026-11-12): a 30-bit mask spends four addresses per link; 31-bit masks allowed on point-to-point links
- IETF, RFC 2132, DHCP Options and BOOTP Vendor Extensions, March 1997 (read 2026-11-12): option 1, Subnet Mask, four octets, placed before the router option
- IETF, RFC 6918, Formally Deprecating Some ICMPv4 Message Types, F. Gont and C. Pignataro, April 2013 (read 2026-11-12): Address Mask Request and Reply superseded by DHCP; updates RFC 792 and RFC 950
- IETF, RFC 4291, IP Version 6 Addressing Architecture, February 2006 (read 2026-11-12): section 2.3, an IPv6 prefix is written as an address, a slash and a prefix length, the number of leftmost contiguous bits
- Cisco, Configure IP Access Lists, document 23602, updated 15 October 2025 (read 2026-11-12 through WebFetch): the wildcard or inverse mask, where 0 means the bit must match and 1 means it is ignored; the inverse mask is 255.255.255.255 minus the subnet mask
- ifconfig(8), Linux manual page, man7.org (read 2026-11-12): netmask addr sets the IP network mask and defaults to the usual class A, B or C mask; the output line with inet, netmask and broadcast
- ip-address(8), Linux manual page, man7.org (read 2026-11-12): the address may be followed by a slash and a decimal number which encodes the network prefix length
- Microsoft Learn, route, Windows Commands, last updated 3 February 2023 (read 2026-11-12): route add with the mask keyword; the netmask defaults to 255.255.255.255; the error when the destination has bits set where the mask has zeros
- F5, TMSH Reference v17, ltm virtual and net self (read 2026-11-12): the mask option of a network virtual server, default 255.255.255.255 for IPv4 or ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff for IPv6; a self IP written as 10.10.10.24/16
- Fortinet, FortiOS 8.0.0 Administration Guide, RIP (read 2026-11-12): set prefix with a subnet and a netmask under config router rip