ACL Wildcard Masks
Understanding wildcard masks for ACLs - how they differ from subnet masks and quick conversion methods.
What are Wildcard Masks?
Wildcard masks are used in Access Control Lists (ACLs) to specify which parts of an IP address to match. Unlike subnet masks, wildcard masks use inverted logic: - 0 means "must match exactly" - 1 means "don't care" or "can be anything" This is the opposite of subnet masks, where 1 means network and 0 means host.
Wildcard vs Subnet Masks
The key difference is the bit meaning: **Subnet Mask:** 1 = network portion, 0 = host portion **Wildcard Mask:** 0 = must match, 1 = don't care Wildcard masks are essentially the inverse (bitwise NOT) of subnet masks.
Conversion Examples
255.255.255.0
11111111.11111111.11111111.00000000
0.0.0.255
00000000.00000000.00000000.11111111
255.255.248.0
11111111.11111111.11111000.00000000
0.0.7.255
00000000.00000000.00000111.11111111
255.255.255.252
11111111.11111111.11111111.11111100
0.0.0.3
00000000.00000000.00000000.00000011
255.0.0.0
11111111.00000000.00000000.00000000
0.255.255.255
00000000.11111111.11111111.11111111
Quick Conversion Method
Formula: Wildcard = 255.255.255.255 - Subnet Mask
Steps:
- Take the subnet mask
- Subtract each octet from 255
- The result is your wildcard mask
Examples:
Subnet Mask | Calculation | Wildcard Mask |
---|---|---|
255.255.255.0 | 255-255, 255-255, 255-255, 255-0 | 0.0.0.255 |
255.255.240.0 | 255-255, 255-255, 255-240, 255-0 | 0.0.15.255 |
255.255.255.252 | 255-255, 255-255, 255-255, 255-252 | 0.0.0.3 |
ACL Examples by Platform
Cisco Router ACL Examples
access-list 10 permit 192.168.1.0 0.0.0.255
access-list 10 deny 10.0.0.0 0.255.255.255
access-list 10 permit 172.16.0.0 0.0.255.255
access-list 10 permit 192.168.1.100 0.0.0.0
Juniper Firewall Examples
from source-address 10.0.0.0/8
from source-address 192.168.1.0/24
Special Cases
Usage: Often written as 'any' in ACLs
Usage: Can be written as just the IP without mask
Usage: Match pairs of consecutive addresses
Usage: Match groups of 4 consecutive addresses
Platform Differences
Platform | Format | Example | Notes |
---|---|---|---|
Cisco IOS | access-list [number] [permit|deny] [source] [wildcard] | access-list 10 permit 192.168.1.0 0.0.0.255 | Explicit wildcard mask required |
Cisco ASA | access-list [name] [permit|deny] [protocol] [source/mask] [dest/mask] | access-list INSIDE permit ip 192.168.1.0/24 any | Can use CIDR notation or wildcard masks |
Juniper | from source-address [network/prefix] | from source-address 192.168.1.0/24 | Uses CIDR notation, not wildcard masks |
Palo Alto | [network/prefix] or [start-ip]-[end-ip] | 192.168.1.0/24 or 192.168.1.1-192.168.1.254 | CIDR or range format, no wildcard masks |
Quick Reference Table
CIDR | Subnet Mask | Wildcard Mask | Addresses |
---|---|---|---|
/32 | 255.255.255.255 | 0.0.0.0 | Single host |
/30 | 255.255.255.252 | 0.0.0.3 | 4 addresses |
/29 | 255.255.255.248 | 0.0.0.7 | 8 addresses |
/28 | 255.255.255.240 | 0.0.0.15 | 16 addresses |
/27 | 255.255.255.224 | 0.0.0.31 | 32 addresses |
/26 | 255.255.255.192 | 0.0.0.63 | 64 addresses |
/25 | 255.255.255.128 | 0.0.0.127 | 128 addresses |
/24 | 255.255.255.0 | 0.0.0.255 | 256 addresses |
/16 | 255.255.0.0 | 0.0.255.255 | 65k addresses |
/8 | 255.0.0.0 | 0.255.255.255 | 16M addresses |
Common Mistakes
Problem: ACL won't match intended addresses
Solution: Remember to invert the mask (subtract from 255.255.255.255)
Problem: Many devices assume 0.0.0.0 (host-only match)
Solution: Always specify the wildcard mask explicitly
Problem: Can create unexpected matches
Solution: Stick to contiguous bit patterns for predictable results