Wildcard Mask Calculator for ACL and OSPF (Inverse Mask)
Wildcard Mask Calculator (ACL, OSPF, Inverse Mask)
Convert subnet mask, wildcard (inverse) mask and prefix length, analyse any address/wildcard pair (including discontiguous wildcards such as 0.0.254.255), test whether an IP matches, generate Cisco IOS, IOS-XR, OSPF and Junos lines, and turn an IP range into address/wildcard pairs. IPv4 only. Everything runs in your browser.
1. Subnet mask ↔ wildcard mask ↔ prefix length
Examples: 255.255.255.0, 0.0.0.255, /27, 24
2. Address + wildcard: what does it match?
3. Match tester: does an IP match this address/wildcard?
Tested against the address and wildcard from section 2.
4. ACL and OSPF lines for this address/wildcard
5. IP range → address/wildcard pairs
What this wildcard mask calculator does
Cisco access lists and the OSPF network command don't use subnet masks. They use wildcard masks, also called inverse masks, where a 0 bit means "this bit must match" and a 1 bit means "ignore this bit". This page converts between subnet mask, wildcard mask and prefix length, shows exactly which addresses an address/wildcard pair matches (including discontiguous wildcards like 0.0.254.255), checks a single IP bit by bit, writes the matching Cisco IOS, IOS-XR, OSPF and Junos configuration lines, and turns any IP range into the shortest list of ACL entries.
How it works
Subnet mask to wildcard mask (invert mask)
The wildcard mask is the bitwise inverse of the subnet mask. In decimal, subtract every octet from 255: wildcard = 255.255.255.255 - subnet mask. For example 255.255.255.255 - 255.255.255.0 = 0.0.0.255. For a prefix length n, the wildcard has 32 - n one bits on the right.
A subnet mask must have contiguous 1 bits from the left, so 255.255.0.255 is rejected as a subnet mask. A wildcard mask may have its 1 bits anywhere. When its 1 bits are all on the right (W AND (W + 1) = 0), it is contiguous and equals a prefix; otherwise it is discontiguous and no prefix length describes it.
Matching rule
- An IP address X matches address A with wildcard W when
(X XOR A) AND (NOT W) = 0, which means every bit where W is 0 must be equal in X and A. - First matched address =
A AND (NOT W); last matched address =A OR W. - Number of matched addresses = 2 to the power of the number of 1 bits in W. For 0.0.254.255 that is 2^15 = 32,768.
- Wildcard 0.0.0.0 matches one host (keyword
host); 0.0.0.0 with 255.255.255.255 matches every address (keywordany).
Range to address/wildcard pairs
The range from the first to the last IP is split into the largest aligned power-of-two blocks (the same decomposition as CIDR summarisation in RFC 4632). This gives the minimal list of contiguous wildcard entries. Because Cisco ACLs also accept discontiguous wildcards, the tool then tries to merge pairs of blocks that differ in a single bit. If that produces fewer lines, the shorter list is shown too, checked to cover exactly the same addresses.
Vendor behaviour
- Cisco IOS / IOS-XE: standard and extended ACLs take
source source-wildcard, withhostandanyas shortcuts. - Cisco IOS-XR:
ipv4 access-listentries accept a wildcard or prefix notation (10.1.1.0/24). The tool uses the prefix when one exists. - OSPF:
network ip-address wildcard-mask area area-idenables OSPF on the interfaces whose address matches. - Junos: firewall filters and prefix-lists use prefixes (
10.1.1.0/24). For a noncontiguous match, a firewall filter accepts address/mask with a normal mask where 1 means "must match" (for example 10.0.0.10/255.0.0.255). Simple filters don't support noncontiguous masks.
Sources: Cisco, Configure IP Access Lists (inverse mask, host/any); Cisco, Configure Commonly Used IP ACLs; Cisco, IOS XR Access List Commands (wildcard and prefix-length syntax); Cisco, IOS IP Routing: OSPF Command Reference (network area); Juniper, Firewall Filter Match Conditions Based on Address Fields and source-address (noncontiguous masks); RFC 4632 (CIDR); RFC 3021 (/31 links).
Worked examples
- /27 subnet mask to wildcard. 255.255.255.255 - 255.255.255.224 = 0.0.0.31. The wildcard has 5 one bits, so one entry matches 2^5 = 32 addresses, for example
access-list 10 permit 10.1.1.32 0.0.0.31matches 10.1.1.32 to 10.1.1.63. - Odd third octets with 0.0.254.255.
192.168.1.0 0.0.254.255checks the first two octets and only the last bit of the third octet, which must be 1. It matches 192.168.1.x, 192.168.3.x, 192.168.5.x ... 192.168.255.x: 128 × 256 = 32,768 addresses, first 192.168.1.0, last 192.168.255.255. With 192.168.0.0 instead you get the even third octets. Junos form:192.168.1.0/255.255.1.0. - Match test. Is 192.168.7.20 matched by 192.168.1.0 0.0.254.255? The third octet 7 is 00000111, and its last bit is 1, as required. Everything else is either equal (192.168) or ignored, so it matches. 192.168.8.20 does not, because 8 is 00001000 and its last bit is 0.
- /20 block.
172.16.0.0 0.0.15.255is contiguous and equals 172.16.0.0/20, which is 4,096 addresses from 172.16.0.0 to 172.16.15.255. On IOS-XR:10 permit ipv4 172.16.0.0/20 any; OSPF:network 172.16.0.0 0.0.15.255 area 0. - Range 10.0.0.1 - 10.0.0.6. As CIDR blocks it needs 4 entries: 10.0.0.1 0.0.0.0, 10.0.0.2 0.0.0.1, 10.0.0.4 0.0.0.1 and 10.0.0.6 0.0.0.0. With discontiguous wildcards it needs only 3: 10.0.0.1 0.0.0.2 (.1 and .3), 10.0.0.2 0.0.0.4 (.2 and .6), and 10.0.0.4 0.0.0.1 (.4 and .5).
- Invalid subnet mask, valid wildcard. 255.255.0.255 is not a subnet mask because its 1 bits aren't contiguous. As a wildcard,
10.1.5.0 255.255.0.255checks only the third octet and matches every address whose third octet is 5: 2^24 = 16,777,216 addresses.
Subnet mask, wildcard mask and prefix length reference
| Prefix | Subnet mask | Wildcard mask | Addresses matched |
|---|---|---|---|
| /32 | 255.255.255.255 | 0.0.0.0 | 1 |
| /31 | 255.255.255.254 | 0.0.0.1 | 2 |
| /30 | 255.255.255.252 | 0.0.0.3 | 4 |
| /29 | 255.255.255.248 | 0.0.0.7 | 8 |
| /28 | 255.255.255.240 | 0.0.0.15 | 16 |
| /27 | 255.255.255.224 | 0.0.0.31 | 32 |
| /26 | 255.255.255.192 | 0.0.0.63 | 64 |
| /25 | 255.255.255.128 | 0.0.0.127 | 128 |
| /24 | 255.255.255.0 | 0.0.0.255 | 256 |
| /23 | 255.255.254.0 | 0.0.1.255 | 512 |
| /22 | 255.255.252.0 | 0.0.3.255 | 1,024 |
| /21 | 255.255.248.0 | 0.0.7.255 | 2,048 |
| /20 | 255.255.240.0 | 0.0.15.255 | 4,096 |
| /19 | 255.255.224.0 | 0.0.31.255 | 8,192 |
| /18 | 255.255.192.0 | 0.0.63.255 | 16,384 |
| /17 | 255.255.128.0 | 0.0.127.255 | 32,768 |
| /16 | 255.255.0.0 | 0.0.255.255 | 65,536 |
| /15 | 255.254.0.0 | 0.1.255.255 | 131,072 |
| /14 | 255.252.0.0 | 0.3.255.255 | 262,144 |
| /13 | 255.248.0.0 | 0.7.255.255 | 524,288 |
| /12 | 255.240.0.0 | 0.15.255.255 | 1,048,576 |
| /11 | 255.224.0.0 | 0.31.255.255 | 2,097,152 |
| /10 | 255.192.0.0 | 0.63.255.255 | 4,194,304 |
| /9 | 255.128.0.0 | 0.127.255.255 | 8,388,608 |
| /8 | 255.0.0.0 | 0.255.255.255 | 16,777,216 |
| /7 | 254.0.0.0 | 1.255.255.255 | 33,554,432 |
| /6 | 252.0.0.0 | 3.255.255.255 | 67,108,864 |
| /5 | 248.0.0.0 | 7.255.255.255 | 134,217,728 |
| /4 | 240.0.0.0 | 15.255.255.255 | 268,435,456 |
| /3 | 224.0.0.0 | 31.255.255.255 | 536,870,912 |
| /2 | 192.0.0.0 | 63.255.255.255 | 1,073,741,824 |
| /1 | 128.0.0.0 | 127.255.255.255 | 2,147,483,648 |
| /0 | 0.0.0.0 | 255.255.255.255 | 4,294,967,296 |
FAQ
What is a wildcard mask?
A wildcard mask, also called an inverse mask, is a 32-bit value used in Cisco access lists and OSPF network statements. A 0 bit means the matching address bit must be equal and a 1 bit means the bit is ignored. For example 0.0.0.255 checks the first three octets and ignores the last one.
How do I convert a subnet mask to a wildcard mask?
Subtract each octet of the subnet mask from 255. For 255.255.255.224 the wildcard mask is 0.0.0.31, and for 255.255.240.0 it is 0.0.15.255. The calculator also does the reverse and shows the prefix length.
What do the wildcard masks 0.0.0.0 and 255.255.255.255 mean?
0.0.0.0 means every bit must match, so the entry matches a single host and can be written with the host keyword. 255.255.255.255 ignores every bit, so 0.0.0.0 255.255.255.255 matches any address and can be written with the any keyword.
Can a wildcard mask be discontiguous?
Yes. Cisco ACLs accept 1 bits anywhere in the wildcard, for example 192.168.1.0 0.0.254.255 matches every address in 192.168.0.0/16 with an odd third octet. A subnet mask cannot be discontiguous, and a discontiguous wildcard has no equivalent prefix length.
How many addresses does an address and wildcard pair match?
It matches 2 to the power of the number of 1 bits in the wildcard. 0.0.0.255 has 8 one bits and matches 256 addresses, while 0.0.254.255 has 15 one bits and matches 32768 addresses.
Do IOS-XR and Junos use wildcard masks?
IOS-XR access lists accept both wildcard masks and prefix notation such as 10.1.1.0/24. Junos uses prefixes in firewall filters and prefix-lists; for a noncontiguous match a Junos firewall filter takes an address with a normal mask where 1 means must match, such as 192.168.1.0/255.255.1.0.
Does the OSPF network command use a wildcard mask?
Yes. On Cisco IOS the syntax is network ip-address wildcard-mask area area-id, for example network 10.0.0.0 0.0.0.255 area 0. It selects the interfaces whose IP address matches and enables OSPF on them; it does not decide the mask of the advertised prefix.
Comments
Post a Comment