wildcard mask
termKept in this browser · My desk
A wildcard mask is a 32-bit pattern written like an IPv4 address in which each 0 bit means the corresponding address bit must match and each 1 bit means it is ignored; for a contiguous block it is the bitwise inverse of the netmask, with the host bits set to one, and access lists and some routing commands use it to say which bits of an address to ignore.
Python's ipaddress documentation calls it the host mask, "the logical inverse of a net mask", which "is sometimes used (for example in Cisco access control lists) to denote a network mask": 0.0.0.255 for a /24, 0.0.0.63 for a /26. The module returns it as hostmask and with_hostmask, and reads a mask written after the slash as a host mask when its first field is zero. Cisco IOS uses it in ACLs (access control lists), in OSPF (Open Shortest Path First) network statements and elsewhere; other platforms, the Cisco ASA (Adaptive Security Appliance) among them, write ordinary netmasks in the same places, which is the source of a classic misconfiguration.
A wildcard mask, also called an inverse mask, is a 32-bit value written in dotted decimal like an IPv4 address, which tells a matching rule which bits of an address to compare. Cisco's guide to IP access lists states the rule: each 0 bit in the wildcard means the corresponding bit must match exactly, and each 1 bit means that bit can be ignored. An entry such as 10.1.1.0 0.0.0.255 therefore matches every address that begins 10.1.1, because the first three octets must match and the last one may be anything. The netmask works the other way round, with ones marking the network part, which is why, for the contiguous blocks that make up nearly all real use, the wildcard is simply the bitwise inverse of the netmask: the host mask, in the vocabulary of Python's ipaddress module, which defines it as the logical inverse of a net mask, sometimes used, for example in Cisco access control lists, to denote a network mask.
Computing one is subtraction. Cisco's guide gives the method, subtract the subnet mask from 255.255.255.255, so 255.255.255.0 gives 0.0.0.255 and 255.255.248.0 gives 0.0.7.255; in prefix terms, a /n block has 32 minus n ones at the right-hand end, which is why a /30 is 0.0.0.3, a /26 is 0.0.0.63, a /23 is 0.0.1.255, a /20 is 0.0.15.255 and a /16 is 0.0.255.255. Two values have keywords of their own: a wildcard of 0.0.0.0 matches one exact address, which IOS lets an administrator write as host 10.1.1.2, and the pair 0.0.0.0 255.255.255.255 matches everything, written any. In a standard ACL (access control list) an omitted wildcard is taken as all zeros, so a bare address matches only itself. An entry whose address has bits set where the wildcard ignores them, 10.1.1.5 0.0.0.255 for instance, still matches the whole of 10.1.1.0/24, since the ignored bits are not compared.
What the wildcard can do that a netmask cannot is express non-contiguous patterns. Any bit pattern is legal: 0.0.0.254 combined with 10.10.10.2 matches the even addresses 10.10.10.0, 10.10.10.2, 10.10.10.4 and so on, and combined with 10.10.10.1 it matches the odd ones, and with enough care several unrelated /24s can be squeezed into one entry by finding the bits they share. That power is also the trap. A non-contiguous wildcard does not describe one block, cannot be written as a prefix length, and matches every address the free bits allow, including many that were not meant; as Tony Mattke put it in 2010, the more complex such masks get, the more unintentional traffic they let in, and their use in routing protocols is frowned upon if not prohibited. Reviewers, audit tools and the next administrator all read prefixes more easily than bit puzzles.
The same notation appears outside ACLs on Cisco IOS, most visibly in the OSPF (Open Shortest Path First) network statement, network 10.1.16.0 0.0.15.255 area 3, where the wildcard does not describe a subnet at all. As Ivan Pepelnjak explained in 2007, the statement works like a simple IP access list run against the router's interface addresses: any interface whose address matches is placed in the area, the statements are sorted from most to least specific, and the first match wins. The wildcard bits therefore need not be the inverse of the interface's mask; network 192.168.1.2 0.0.0.0 area 0 selects exactly one interface, and network 0.0.0.0 255.255.255.255 area 0 puts every interface into area 0. A wrong wildcard in that statement does not break a subnet, it silently enables or disables OSPF on interfaces nobody intended. EIGRP (Enhanced Interior Gateway Routing Protocol) network statements on IOS take an optional wildcard in the same way.
Platforms disagree about which mask goes where, and that is the most common practical error. Cisco's own ASA (Adaptive Security Appliance) documentation warns that its access lists take a network mask such as 255.255.255.0, unlike the Cisco IOS access-list command, whose mask uses wildcard bits such as 0.0.0.255. Linux iptables writes a network mask or a prefix length after the slash. FortiOS uses prefixes and netmasks in firewall policy, but its routing access lists, used to filter routes, accept either a prefix or a wildcard described as Cisco-style wildcard filter criteria. An administrator who types 255.255.255.0 into an IOS ACL as if it were a netmask gets the opposite of what was meant: the first three octets are ignored and only the last must match, so the entry matches one host number in every /24 on the internet.
Python's ipaddress module handles the conversion and shows the ambiguity it has to resolve. A network can be written as 192.168.1.0/24, 192.168.1.0/255.255.255.0 or 192.168.1.0/0.0.0.255, all equivalent; the module reads a dotted mask after the slash as a netmask when its first field is non-zero and as a host mask when its first field is zero, with one exception, an all-zero mask, which it treats as a netmask. That exception is worth remembering, because the same text 0.0.0.0 means a single host as an IOS wildcard but /0, everything, as a Python mask. Every network object exposes the wildcard as hostmask and the network with it as with_hostmask, and calculators commonly print it next to the netmask for the same reason.
The numbers to remember follow from the inversion: each octet of the wildcard is 255 minus the corresponding octet of the netmask, a /24 is 0.0.0.255, a /32 is 0.0.0.0, and the full wildcard 255.255.255.255 matches any address. Wildcards appear only for IPv4 in this form; IPv6 ACLs and routing filters on the same platforms use prefix lengths.
Also known as: host mask, hostmask, inverse mask, 0.0.0.255
Sources
- Python 3.13 documentation, ipaddress: IPv4/IPv6 manipulation library (read 2026-11-12): a host mask is the logical inverse of a net mask, sometimes used (for example in Cisco access control lists) to denote a network mask, 0.0.0.255 for /24; a mask after the slash read as a net mask if its first field is non-zero and as a host mask if it is zero, an all-zero mask being a net mask; 192.168.1.0/24, 192.168.1.0/255.255.255.0 and 192.168.1.0/0.0.0.255 equivalent; the hostmask and with_hostmask attributes
- Cisco, Configure IP Access Lists, Document ID 23602, updated 15 October 2025 (read 2026-11-12): ACLs use a wildcard mask, also called an inverse mask; a 0 bit must match and a 1 bit is ignored; the inverse mask is 255.255.255.255 minus the subnet mask; 0.0.0.255, 0.0.7.255 for 255.255.248.0 and 0.0.1.255 examples; host as a 0.0.0.0 wildcard, any as 0.0.0.0 with 255.255.255.255; an omitted wildcard in a standard ACL taken as all zeros; the implicit deny
- Cisco, ASA 5500 Series Configuration Guide using the CLI 8.3, Adding an Extended Access List (read 2026-11-12): the ASA uses a network mask such as 255.255.255.0 in access lists, unlike the Cisco IOS access-list command, whose mask uses wildcard bits such as 0.0.0.255
- Ivan Pepelnjak, Be Smart When Using the OSPF Network Statement, blog post, 12 July 2007 (read 2026-11-12): the wildcard bits of the OSPF network statement need not be the inverse of the interface mask; network statements work like a simple IP access list, sorted from most to least specific, first match wins; network x.y.z.w 0.0.0.0, network 10.1.16.0 0.0.15.255 area 3 and network 0.0.0.0 255.255.255.255 as patterns
- Wikipedia, Wildcard mask (read 2026-11-12): used in Cisco IOS for OSPF network size and for ACLs; 0 must match and 1 does not matter; any bit pattern possible, 0.0.0.254 matching even addresses with 10.10.10.2 and odd ones with 10.10.10.1; the table of prefix lengths, netmasks and wildcard masks
- Tony Mattke, Using discontiguous wildcard masks in ACLs, Router Jockey, 19 May 2010 (read 2026-11-12): unlike subnet masks, wildcard masks allow discontiguous bits; their use in routing protocols frowned upon if not prohibited; the more complex the mask, the more unintended traffic it matches
- Fortinet, FortiOS 7.2.4 CLI Reference, config router access-list (read 2026-11-12): each rule has a prefix for regular filter criteria or a wildcard to define Cisco-style wildcard filter criteria, with exact-match
- iptables(8), Linux manual page (read 2026-11-12): the mask after the slash is an IPv4 network mask or a plain number of leading ones, so a mask of 24 equals 255.255.255.0