What a Wildcard Mask Is
A wildcard mask is a 32-bit value that tells a Cisco device which bits of an IP address it has to compare and which bits it can ignore. You pair it with an address inside an ACL entry, and together they define a set of addresses. That's it. One address plus one mask gives you a match pattern.
See these masks in complete configurations in Cisco ACL examples and in the Cisco ACL runbook for IOS-XE.
The rule is simple and it's the opposite of what most people expect from a subnet mask. A 0 bit means the corresponding address bit must match exactly. A 1 bit means I don't care, so that bit can be anything. Subnet masks use 1 for the network portion and 0 for the host portion. Wildcard masks flip that. This is why people call them inverse masks, and it's also why the nickname causes trouble later. I'll get to that.
You'll meet wildcard masks in standard and extended ACLs, in OSPF and EIGRP
networkstatements, in route-map match conditions that reference ACLs, in NAT source lists, and in class-map match criteria. Learn it once and it pays off across half of IOS.
How the Match Actually Works
Under the hood the router does a bitwise comparison. For each bit position where the wildcard is 0, the packet's address bit must equal the ACL address bit. Where the wildcard is 1, the comparison is skipped. If every compared bit matches, the entry hits.
Take this entry:
access-list 10 permit 192.168.10.0 0.0.0.255
Break the wildcard into octets:
0.0.0.255. The first three octets are all zeros, so 192.168.10 must match exactly. The last octet is all ones, so anything from 0 to 255 is fine. The match range is 192.168.10.0 through 192.168.10.255. Same thing a /24 would give you, which is why the inverse-mask shortcut works so often.
Here's the binary view for a packet from 192.168.10.77:
ACL address : 11000000.10101000.00001010.00000000 (192.168.10.0)
Wildcard : 00000000.00000000.00000000.11111111 (0.0.0.255)
Packet src : 11000000.10101000.00001010.01001101 (192.168.10.77)
Bits under 0s in wildcard: identical -> MATCH
Now the same packet checked against 192.168.11.0 with the same wildcard. The third octet differs (00001010 vs 00001011), and that bit sits under a 0 in the wildcard, so the entry fails. No match, move to the next line.
The two keywords that save typing
Two shorthand forms exist because they're so common.
host 10.1.1.5is identical to
10.1.1.5 0.0.0.0, every bit must match. And
anyis identical to
0.0.0.0 255.255.255.255, no bit has to match. I always use the keywords in production configs. They read faster at 2 a.m. during an outage.
Calculating a wildcard from a subnet mask
For a contiguous mask, subtract each octet of the subnet mask from 255. A /20 is 255.255.240.0, so the wildcard is 0.0.15.255. A /12 is 255.240.0.0, so you get 0.15.255.255. A /30 is 255.255.255.252, giving 0.0.0.3. You can do this in your head after a few weeks of practice.
The other mental shortcut I lean on is the block size. The wildcard value in the interesting octet is always the block size minus one. A block of 16 addresses means 15. A block of 64 means 63. A block of 4 means 3.
Why It Matters
ACLs are first-match, top-down, with an implicit deny at the end. A wildcard that's too wide permits traffic you meant to block. One that's too narrow drops traffic you meant to allow. Either way you're debugging in the dark unless you can read the mask and predict the result.
I've seen this go wrong more than once on a Friday afternoon. Someone writes a deny for a server VLAN using
0.0.255.255because it looked right, and suddenly an entire /16 of user space can't reach DNS. The config was syntactically perfect. The intent was wrong by two octets.
Wildcard masks also let you summarize. A single line can cover sixteen /24s, or every even-numbered subnet, or a contiguous /22. Fewer lines means faster review, fewer mistakes, and less TCAM pressure on platforms where ACL entries cost hardware resources. Efficient ACLs are readable ACLs.
Real-World Examples
Example 1: A single host and a single subnet
The bread and butter. Let the management workstation at 192.168.50.10 reach SSH on the switch, and nothing else.
sw-infrarunbook-01(config)# ip access-list standard MGMT-SSH
sw-infrarunbook-01(config-std-nacl)# permit host 192.168.50.10
sw-infrarunbook-01(config-std-nacl)# deny any log
sw-infrarunbook-01(config-std-nacl)# exit
sw-infrarunbook-01(config)# line vty 0 15
sw-infrarunbook-01(config-line)# access-class MGMT-SSH in
sw-infrarunbook-01(config-line)# transport input ssh
Opening it up to the whole management subnet is just a matter of swapping the first line for
permit 192.168.50.0 0.0.0.255.
Example 2: Aggregating a contiguous range
Say you have four user subnets: 10.20.4.0/24, 10.20.5.0/24, 10.20.6.0/24 and 10.20.7.0/24. Writing four lines works, but they sit on a clean boundary. The third octet runs 4 to 7, a block of four, so the wildcard is 3 in that octet. The last octet is fully free, so 255.
ip access-list extended USERS-TO-SERVERS
permit tcp 10.20.4.0 0.0.3.255 172.16.10.0 0.0.0.255 eq 443
permit tcp 10.20.4.0 0.0.3.255 host 172.16.10.25 eq 22
deny ip any any log
Check the alignment before you trust it. The starting value in that octet (4) must be a multiple of the block size (4). It is. If the range started at 10.20.5.0, the mask
0.0.3.255would still match 4 through 7, because the ignored bits swallow the low bits of the address. That's a silent footgun, and I'll come back to it in the misconceptions section.
Example 3: Private address blocks
The three RFC 1918 ranges make a great exercise because each sits on a different boundary.
ip access-list extended BLOCK-RFC1918-OUT
deny ip any 10.0.0.0 0.255.255.255
deny ip any 172.16.0.0 0.15.255.255
deny ip any 192.168.0.0 0.0.255.255
permit ip any any
The 10/8 gets 0.255.255.255 because only the first octet is fixed. The 172.16/12 is trickier. The second octet runs from 16 to 31, a block of 16, so you ignore the low four bits: wildcard 15, and everything after it is 255. And 192.168/16 fixes two octets, leaving 0.0.255.255.
Example 4: OSPF network statements
This is where wildcard masks surprise people who only think of them as ACL syntax. The OSPF
networkcommand uses the same logic to decide which interfaces join an area.
sw-infrarunbook-01(config)# router ospf 1
sw-infrarunbook-01(config-router)# router-id 10.0.0.1
sw-infrarunbook-01(config-router)# network 10.10.0.0 0.0.255.255 area 0
sw-infrarunbook-01(config-router)# network 192.168.50.1 0.0.0.0 area 0
The first line pulls in any interface whose address falls inside 10.10.0.0/16. The second matches exactly one interface address. I prefer the exact-match style when I want tight control, because a broad statement will happily enrol an interface someone adds later.
Example 5: Non-contiguous wildcards
Here's where wildcard masks do something a subnet mask can't. Because the mask is just a per-bit ignore flag, the ones don't have to be contiguous. Suppose your design puts VLAN subnets for one function on odd third octets: 10.30.1.0, 10.30.3.0, 10.30.5.0 and so on. One entry catches all of them:
access-list 20 permit 10.30.1.0 0.0.254.255
The third octet wildcard is 254, binary 11111110. The lowest bit is a 0, so it must match the lowest bit of the address's third octet, which is 1 (from 10.30.1.0). Every other bit is ignored. The result: any third octet that's odd matches. Flip the address to 10.30.0.0 and you'd match every even one instead.
Same idea works in the last octet.
permit 10.30.1.1 0.0.0.254matches every odd host address in that /24. I've used this to split traffic across two firewalls by odd and even source addresses. It works, it's compact, and it will confuse the next person unless you comment it. Add a
remarkline.
Example 6: Verifying hits
Never assume. Look at the counters.
sw-infrarunbook-01# show ip access-lists USERS-TO-SERVERS
Extended IP access list USERS-TO-SERVERS
10 permit tcp 10.20.4.0 0.0.3.255 172.16.10.0 0.0.0.255 eq 443 (1842 matches)
20 permit tcp 10.20.4.0 0.0.3.255 host 172.16.10.25 eq 22 (37 matches)
30 deny ip any any log (12 matches)
If a line you expected to hit has zero matches, either no traffic arrived or your mask doesn't say what you think it says. Generate a test flow, watch the counter, and you'll know within a minute.
Common Misconceptions
Misconception 1: A wildcard mask is just an inverted subnet mask
For nearly every ACL you write on day one, that's true. As a teaching shortcut it's fine. As a mental model it's incomplete. A subnet mask must be contiguous ones followed by contiguous zeros. A wildcard mask has no such restriction, as the odd-and-even example showed. If you only think in inverse subnet masks, you'll never reach for the pattern that solves an awkward summarization problem, and you'll misread configs written by someone who did.
Misconception 2: The address in the entry has to be the network address
It doesn't. Bits under a wildcard 1 are ignored, so
10.20.5.0 0.0.3.255and
10.20.4.0 0.0.3.255match the same range. The device doesn't complain. That's convenient and dangerous in equal measure. A reviewer reading the first line may assume the range starts at 5 and ends at 8, which it doesn't. Always write the true base address so the line says what it does.
Misconception 3: You can match any arbitrary range with one entry
You can't. A single address-and-wildcard pair describes a power-of-two-aligned block, or a bit pattern. A range like 10.1.10.0 through 10.1.20.255 is not aligned, so no single mask covers it without also catching extra addresses. You'll need several entries: 10.1.10.0/23 (10 and 11), 10.1.12.0/22 (12 to 15), 10.1.16.0/22 (16 to 19), and 10.1.20.0/24. In my experience, when someone insists on one line for an unaligned range, they end up permitting more than they intended.
Misconception 4: Order doesn't matter if the masks don't overlap
They often do overlap, and it's easy to miss. A broad permit above a narrow deny makes the deny unreachable. Put the specific entries first and the general ones last. Counters will expose a dead line immediately, because it sits at zero matches while the line above it climbs.
Misconception 5: Every platform wants a wildcard mask
Not quite. Standard and extended IOS ACLs, OSPF and EIGRP network statements use wildcards. But NX-OS accepts CIDR notation in ACLs, and many IOS-XE commands outside ACLs expect a normal subnet mask, like
ip addressor
ip route. Mixing them up is a classic slip. I once watched a colleague type a wildcard into a static route and spend twenty minutes wondering why the route pointed at a bizarre prefix.
Misconception 6: The implicit deny will catch the mistakes
Only if your mistake errs on the side of too narrow. If the mask is too wide on a permit, the implicit deny never sees the extra traffic. If the mask is too wide on a deny, you block legitimate flows. The implicit deny is a safety net for omissions, not for bad arithmetic. Add an explicit
deny ip any any logat the bottom while you're troubleshooting so you can see what falls through.
A Quick Habit That Prevents Most Errors
Before you commit any new ACL line, write out the first and last address it matches. If the mask is
0.0.15.255against 10.1.16.0, the first address is 10.1.16.0 and the last is 10.1.31.255. If that matches what you wanted, commit. If it doesn't, stop and redo the math. It takes ten seconds and it's saved me from more rollback windows than I can count.
Wildcard masks look odd for about a week. After that they're just a per-bit ignore flag, and you'll start spotting clever patterns in other people's configs. Practice on the RFC 1918 ranges, check your work against
show ip access-listscounters, and always write the base address cleanly.
