Computing, IT, Networking & Security IP Addressing & Subnetting Cisco IOS access-list and OSPF network syntax

Wildcard Mask Calculator for ACLs and OSPF

A wildcard mask is a subnet mask turned inside out: every bit that must match is a 0, and every bit the router should ignore is a 1. This calculator converts in any direction — prefix to wildcard, subnet mask to wildcard, or a wildcard back to its prefix — and then tells you the part that matters, which is exactly which addresses the pattern matches and how many of them there are. It also writes the finished access-list or OSPF network statement for you, and it handles discontiguous wildcards, which have no equivalent subnet mask at all.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
Network or addressThe address the pattern is anchored on, in dotted decimal. Ignored bits are cleared for you.10.0.0.0
What you are starting fromPick the form you already have; the calculator produces the other two.Prefix length (/n)
Prefix lengthNumber of leading bits that must match, from 0 to 32.22 /
Subnet maskThe ordinary mask as configured on the interface, for example 255.255.252.0.255.255.252.0
Wildcard maskAn inverse mask taken from an existing ACL, for example 0.0.3.255.0.0.3.255
Statement to generateChoose the command you are about to paste; the numbers are placeholders you can change.Standard ACL (access-list 10)

It returns

  • Wildcard mask — The inverse mask to type after the address.
  • Equivalent subnet mask
  • Equivalent prefix length
  • Addresses matched
  • Address range matched
  • Ready-to-paste statement

The formula

W=255.255.255.255M,N=2w
p=32w

In plain text: wildcard = 255.255.255.255 − subnet mask; addresses matched = 2^(number of 1 bits in the wildcard)

  • WWildcard (inverse) mask (dotted decimal)
  • MSubnet mask (dotted decimal)
  • NNumber of addresses the pattern matches (addresses)
  • wCount of 1 bits in the wildcard — the ignored, or don't-care, bits (bits)

The subtraction is per octet and never borrows, because a subnet mask octet is always between 0 and 255. Equivalently, the wildcard is the bitwise NOT of the mask.

Updated Category IP Addressing & Subnetting Verified against published test cases Reading time 11 min

What a wildcard mask is and why it looks backwards

A wildcard mask tells a router which bits of an address to compare and which to ignore. A 0 bit means the bit must match; a 1 bit means don't care. That is the exact opposite of a subnet mask, where the 1 bits identify the network portion, which is why the wildcard is often called an inverse mask.

The reason the convention exists is that an access list is a pattern matcher, not an interface configuration. A subnet mask answers “where does this network end?” A wildcard answers “which bits do I bother to look at?” The second question is more general: it can express patterns that are not networks at all, such as every odd-numbered address in a range, which a subnet mask cannot describe. Cisco IOS uses wildcards in numbered and named access lists, in OSPF and EIGRP network statements, and in route-map match clauses.

The conversion itself is a subtraction you can do in your head once you have seen it a few times: subtract each octet of the mask from 255. A /24 has mask 255.255.255.0, so the wildcard is 0.0.0.255. A /26 has mask 255.255.255.192, so the wildcard is 0.0.0.63. If you need the prefix and mask themselves rather than the inverse, the subnet mask and CIDR converter handles that direction, and the IPv4 subnet calculator gives the full properties of the resulting network.

The arithmetic, bit by bit

Wildcard = 255.255.255.255 − subnet mask. The subtraction runs octet by octet and never borrows, because every octet of a subnet mask lies between 0 and 255. It is the bitwise complement written in decimal, which is convenient because mask octets only ever take nine values: 0, 128, 192, 224, 240, 248, 252, 254 and 255. Their complements are 255, 127, 63, 31, 15, 7, 3, 1 and 0.

Matched addresses = 2 raised to the number of 1 bits in the wildcard. Each ignored bit is free to be 0 or 1, so each one doubles the set of addresses that match. A wildcard of 0.0.3.255 has 2 + 8 = 10 one-bits, so it matches 210 = 1,024 addresses. This is the calculation that catches errors: if the count is not what you expected, the mask is wrong regardless of how plausible it looks.

The range comes from clearing and setting the ignored bits. The lowest matching address has every don't-care bit set to 0; the highest has every one set to 1. When the 1 bits are all at the right-hand end — a contiguous wildcard — every address between those two endpoints matches, and the pattern is exactly a subnet. When they are not contiguous, the endpoints are still correct but the matches are a repeating pattern inside them.

Prefix length = 32 − ignored bits, and this only means anything for a contiguous wildcard. A wildcard of 0.0.0.254 ignores seven bits but leaves bit 0 significant, so no prefix length and no subnet mask describes it. The calculator reports that rather than inventing a mask.

One detail that trips people up on the command line: the router ignores the address bits that the wildcard marks as don't-care, so 10.1.2.3 0.0.0.255 and 10.1.2.0 0.0.0.255 behave identically. Writing the ignored bits as zeros is a convention for readability, not a requirement, and this calculator normalises to it.

Worked example: an ACL for 10.0.0.0/22

You need an access list entry that permits the whole of 10.0.0.0/22, and an OSPF statement that enables the protocol on the same range. Work it out by hand.

  1. Write the subnet mask. A /22 fixes 22 bits: eight, eight, then six more. The third octet's mask is 11111100 = 252, so the mask is 255.255.252.0.
  2. Subtract from 255 in each octet. 255 − 255 = 0; 255 − 255 = 0; 255 − 252 = 3; 255 − 0 = 255. The wildcard is 0.0.3.255.
  3. Count the ignored bits. The third octet's 3 is binary 00000011, which is 2 bits, and the fourth octet's 255 is 8 bits. That is 10 ignored bits, which agrees with 32 − 22 = 10.
  4. Count the addresses. 210 = 1,024 addresses.
  5. Find the range. Clear all ten ignored bits: 10.0.0.0. Set all ten: the third octet goes to 0 + 3 = 3 and the fourth to 255, giving 10.0.3.255. So the entry matches 10.0.0.0 through 10.0.3.255, which is 1,024 addresses — consistent with step 4.
  6. Write the statements. access-list 10 permit 10.0.0.0 0.0.3.255 for the standard ACL, and network 10.0.0.0 0.0.3.255 area 0 for OSPF.

Sanity-check the arithmetic the other way: 1,024 addresses starting at 10.0.0.0 spans four /24s — 10.0.0.x, 10.0.1.x, 10.0.2.x and 10.0.3.x — which is what a /22 is. Whenever the address count and the visible range disagree, trust the count and re-derive the mask.

How to check the result before you paste it

Read the address range first, not the mask. The mask is the thing you are likely to have got wrong; the range is the consequence you can verify against intent. If you meant to permit one building's /24 and the range covers four of them, the mask is one bit off.

Then check the address count against the prefix you expected. Every step down in prefix length doubles it: a /24 matches 256, a /23 matches 512, a /22 matches 1,024. A count that is not the power of two you expected is a discontiguous mask, which is almost always a typo — 0.0.0.254 instead of 0.0.0.255 is a single character and a completely different pattern.

Be careful with what the statement does not say. An access list ends with an implicit deny any, so a list containing only permits blocks everything else; if you are filtering rather than selecting, that is the intended behaviour, and if you are matching traffic for QoS or NAT it usually is not. A standard ACL matches on source address only, which is why an extended ACL takes two address-and-wildcard pairs.

For OSPF, remember what the network statement actually does: it selects interfaces whose primary address falls inside the range and enables OSPF on them, placing them in the stated area. It does not advertise a prefix. A statement wider than you intended will enable the protocol on interfaces you did not mean to include — including, on some platforms, ones facing customers. Many operators avoid the ambiguity entirely by configuring ip ospf 1 area 0 on each interface instead, which needs no wildcard at all.

Prefix, subnet mask and wildcard mask reference

Each row is one prefix length with its subnet mask, the wildcard that inverts it, and the number of addresses matched (2 raised to the ignored-bit count).
PrefixSubnet maskWildcard maskIgnored bitsAddresses matched
/8255.0.0.00.255.255.2552416,777,216
/16255.255.0.00.0.255.2551665,536
/20255.255.240.00.0.15.255124,096
/21255.255.248.00.0.7.255112,048
/22255.255.252.00.0.3.255101,024
/23255.255.254.00.0.1.2559512
/24255.255.255.00.0.0.2558256
/25255.255.255.1280.0.0.1277128
/26255.255.255.1920.0.0.63664
/27255.255.255.2240.0.0.31532
/28255.255.255.2400.0.0.15416
/29255.255.255.2480.0.0.738
/30255.255.255.2520.0.0.324
/31255.255.255.2540.0.0.112
/32255.255.255.2550.0.0.001

Mask and wildcard sum to 255 in every octet, so you can read the table in either direction.

Mistakes that produce a wrong access list

  • Typing the subnet mask where the wildcard belongs. access-list 10 permit 10.0.0.0 255.255.252.0 ignores the first 22 bits and matches on the last 10 — a pattern that still matches 4,194,304 addresses, so it looks like it works until traffic you did not intend is permitted.
  • Forgetting the implicit deny. Every access list ends with an invisible deny any. A list with one permit entry blocks everything else, which is right for filtering and wrong for classification.
  • Assuming a standard ACL can match a destination. Standard lists carry one address and one wildcard, and they match the source only. Use an extended list when the destination matters.
  • Using a discontiguous wildcard by accident. A single mistyped digit turns 0.0.0.255 into 0.0.0.254 or 0.0.0.253, which matches a repeating pattern instead of a block. The address count in the results is the fastest way to spot it.
  • Writing an OSPF network statement wider than intended. The statement enables OSPF on every interface whose address falls in the range, so a /8-wide wildcard can bring up adjacencies on links that should never run the protocol.
  • Reordering entries without re-reading them. Access lists are evaluated top to bottom and stop at the first match, so a broad permit above a narrow deny makes the deny unreachable.

Where wildcards are used, and where they are not

Wildcard masks are Cisco IOS syntax, and they appear in numbered and named access lists, OSPF and EIGRP network statements, and match ip address clauses in route maps. Cisco ASA firewalls take an ordinary subnet mask instead, which is a classic source of confusion when an engineer moves between the two platforms on the same day. Juniper, Arista and Linux iptables all use prefix notation directly.

Prefix lists are the other place this arithmetic surfaces. A prefix list matches route prefixes rather than host addresses, and it uses ge and le qualifiers instead of a wildcard, so it can express “any prefix inside 10.0.0.0/8 that is a /24 or longer” — something no wildcard can say, because a wildcard sees only addresses and not mask lengths. If you find yourself trying to build that with an ACL, the answer is a prefix list.

To design the address plan the ACL is going to protect, use the VLSM subnet design calculator, and to check how many hosts a given prefix carries use the IPv4 host count calculator. On IPv6 there is no wildcard at all: IPv6 access lists take a prefix directly, which the IPv6 subnet calculator works out for you.

A closing habit worth keeping: after generating an entry, verify it on the device rather than trusting the paste. show access-lists displays hit counts per line, and a line with zero hits on a rule you expect to be busy is the same signal as a wrong address count here — the pattern does not match what you think it matches.

Frequently asked questions

What is the wildcard mask for a /24?

0.0.0.255. A /24 has subnet mask 255.255.255.0, and subtracting each octet from 255 gives 0.0.0.255. It ignores the last 8 bits, so it matches 28 = 256 addresses — the whole of one class-C-sized block. The same subtraction gives 0.0.1.255 for a /23, 0.0.3.255 for a /22 and 0.0.0.127 for a /25.

Why does Cisco use wildcard masks instead of subnet masks?

Because an access list matches patterns, not networks. A wildcard says which bits to examine, which is a more general idea than which bits form a network prefix — it can describe every address whose last bit is 0, for instance, which no subnet mask can express. The convention dates from the original IOS access-list syntax and has been kept for compatibility ever since, even though most other vendors now take prefix notation directly.

How do I match a single host in an access list?

Use a wildcard of 0.0.0.0, or the shorthand keyword host. Every bit must match, so access-list 10 permit 10.4.5.6 0.0.0.0 and access-list 10 permit host 10.4.5.6 are the same entry, and IOS displays the second form. The mirror case is 255.255.255.255, which ignores every bit and matches anything; its shorthand is any.

What is a discontiguous wildcard mask?

One whose ignored bits are not all at the right-hand end, so it matches a repeating pattern instead of a solid range. For example 0.0.0.254 ignores bits 1 to 7 but examines bit 0, matching only the 128 even-numbered addresses in a /24. Cisco ACLs accept these and they are occasionally useful — matching every fourth VLAN's subnet, say — but no subnet mask or prefix length is equivalent, and most appearances in real configurations are typing errors.

Does the address in an ACL entry have to be the network address?

No. The router ignores every address bit that the wildcard marks as don't-care, so 10.1.2.99 0.0.0.255 matches exactly the same 256 addresses as 10.1.2.0 0.0.0.255. Writing the ignored bits as zeros is a readability convention that makes configurations easier to review and diff, and IOS normalises some entries to that form when it displays them.

What does the OSPF network statement's wildcard actually select?

Interfaces, not routes. OSPF compares the statement's range against the primary IP address of each interface, enables OSPF on the ones that fall inside it, and places them in the named area. The prefix that gets advertised is then whatever is configured on the matched interface. This is why a statement that is wider than intended brings up adjacencies on unexpected links, and why per-interface ip ospf configuration is often preferred.

How many addresses does a wildcard match?

Two raised to the number of 1 bits in it. Count the binary ones across all four octets: 0.0.3.255 has two in the third octet and eight in the fourth, so it matches 210 = 1,024 addresses. This works for discontiguous wildcards too, where the matched addresses are scattered rather than consecutive. The count is the quickest check on whether a mask says what you meant.

Is a wildcard mask the same as an inverse mask?

Yes, the two names are interchangeable, and “inverse mask” is the more descriptive of the pair. Both refer to the bitwise complement of a subnet mask as used in Cisco access lists and routing-protocol network statements. You may also see “don't-care bits” used for the 1 bits inside it, which is where the underlying idea comes from.

References