Wildcard Masks Explained
A wildcard mask is the bitwise inverse of a subnet mask. Where a subnet mask uses 1-bits to mark the network (must match), a wildcard mask uses 0-bits to mark what must match and 1-bits to mark what to ignore. Wildcard masks appear in Cisco ACLs, OSPF network statements, EIGRP, and a few other places. Convert any prefix with the wildcard mask calculator.
Subnet mask vs wildcard mask
| Subnet mask bit | Meaning | Wildcard bit | Meaning |
|---|---|---|---|
| 1 | Must match (network) | 0 | Must match |
| 0 | Ignore (host) | 1 | Ignore (wildcard) |
The conversion is simply wildcard = 255.255.255.255 − subnet_mask, octet by octet.
Conversion examples
| Prefix | Subnet mask | Wildcard mask | Calculation |
|---|---|---|---|
| /24 | 255.255.255.0 | 0.0.0.255 | 255−255, 255−255, 255−255, 255−0 |
| /25 | 255.255.255.128 | 0.0.0.127 | 255−128=127 |
| /26 | 255.255.255.192 | 0.0.0.63 | 255−192=63 |
| /27 | 255.255.255.224 | 0.0.0.31 | 255−224=31 |
| /28 | 255.255.255.240 | 0.0.0.15 | 255−240=15 |
| /30 | 255.255.255.252 | 0.0.0.3 | 255−252=3 |
| /16 | 255.255.0.0 | 0.0.255.255 | — |
| /8 | 255.0.0.0 | 0.255.255.255 | — |
Wildcard masks in ACLs
In a Cisco ACL, the address + wildcard pair defines which source (or destination) addresses match the line. A 0-bit in the wildcard means the corresponding address bit must match; a 1-bit means it is ignored.
! Match the entire 192.168.1.0/24 subnet
access-list 10 permit 192.168.1.0 0.0.0.255
! Match a single host (all bits must match)
access-list 10 permit 192.168.1.50 0.0.0.0
! Shorthand:
access-list 10 permit host 192.168.1.50
! Match any address (all bits ignored)
access-list 10 permit 0.0.0.0 255.255.255.255
! Shorthand:
access-list 10 permit anyMatching a range of subnets
Wildcard masks can be non-contiguous to match several subnets at once. To match 192.168.0.0/24, 192.168.1.0/24, 192.168.4.0/24, and 192.168.5.0/24 with one line, find the bits that vary and set those wildcard bits to 1:
0 = 00000000
1 = 00000001
4 = 00000100
5 = 00000101
^^^ ← bits that vary → wildcard 00000111 = 7
access-list 10 permit 192.168.0.0 0.0.7.255This matches 192.168.0.0 through 192.168.7.255 — broader than the four you wanted. For a precise match, use multiple lines or a prefix-list instead.
Wildcard masks in OSPF
OSPF network statements use wildcard masks to decide which interfaces join an area. The statement matches any interface whose IP address falls within the address + wildcard range.
router ospf 1
! Match interfaces in 10.0.0.0/24
network 10.0.0.0 0.0.0.255 area 0
! Match a single interface
network 10.0.0.1 0.0.0.0 area 0
! Match all 10.x.x.x interfaces
network 10.0.0.0 0.255.255.255 area 0A common practice is to use 0.0.0.0 wildcards (exact match) for loopbacks to avoid accidentally matching more than intended.
The "any" and "host" keywords
| Keyword | Equivalent | Meaning |
|---|---|---|
any | 0.0.0.0 255.255.255.255 | Match every address |
host A.B.C.D | A.B.C.D 0.0.0.0 | Match exactly one address |
Common mistakes
- Using a subnet mask in an ACL — Cisco IOS will often accept it but match the wrong range. Always convert.
- Non-contiguous wildcards — allowed and sometimes useful, but easy to get wrong. Prefer prefix-lists for clarity.
- Forgetting the inverse — /24 wildcard is 0.0.0.255, not 255.255.255.0.
Related guides
- IPv4 Subnetting Guide
- CIDR Explained
- Subnetting Cheat Sheet — includes wildcard column
- CIDR Cheat Sheet