# Wildcard Mask Calculator: Prefix, Netmask and ACL

Convert between prefix length, subnet mask, wildcard (inverse) mask, hex and binary for IPv4 (accepts /27, 255.255.255.224, 0.0.0.31, 0xffffffe0, 32 binary digits or a CIDR block). Returns the prefix, mask, wildcard, hex, binary, address counts and host bits, and whether the mask is contiguous. A non-contiguous Cisco ACL wildcard (0.0.254.255) is reported with how many addresses it matches and a plain sentence generated from its bits. Optionally checks an address against the mask, and turns an address range into the shortest list of address and wildcard pairs that matches exactly that range. Includes Cisco IOS ACL, OSPF network and Juniper prefix-list lines. 0.0.0.0 and 255.255.255.255 are ambiguous: the answer names both readings. IPv6 is not covered. Pure computation.

**Not for:** IPv6 subnets (use subnet_calculate) or planning several subnets (use subnet_plan).

- Tool id: `netmask-convert`
- Category: ip
- Execution: pure
- MCP tool `netmask_convert` at https://lookupowl.com/mcp
- REST `GET https://lookupowl.com/api/v1/tools/netmask-convert` (or POST a JSON body)
- OpenAPI: https://lookupowl.com/api/openapi.json

## Input

| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| `value` | string | no | `""` | A prefix length (/27), a subnet mask (255.255.255.224), a wildcard mask (0.0.0.31), hex (0xffffffe0), 32 binary digits, or a block in CIDR form (192.168.1.32/27). Optional when `range` is given. max length 200 |
| `as` | "auto" \| "mask" \| "wildcard" | no | `"auto"` | How to read 0.0.0.0 and 255.255.255.255, which can be either a mask or a wildcard. auto: starts with 255 is a mask, starts with 0 is a wildcard. |
| `address` | string | no | `""` | An address to check against the mask: tells whether it matches, and which network it is in. max length 100 |
| `range` | string | no | `""` | An address range such as 192.168.1.10 - 192.168.1.77. Returns the shortest list of address and wildcard pairs that match exactly that range. max length 200 |

## Output

Results are wrapped in an envelope: `tool`, `version`, `requestId`, `data`, `summary`, `meta` (cache status, timing), `permalink`. `data` has these fields:

| Field | Type | Description |
|---|---|---|
| `input` | string | The value as typed, or the range. |
| `readAs` | "prefix" \| "mask" \| "wildcard" \| "hex" \| "binary" \| "block" \| "range" | What the value was read as: its form (prefix, hex, binary, a block) or, for a dotted quad, mask or wildcard. |
| `role` | string | Whether the value was taken as a subnet mask or as a wildcard. null for an IPv6 length or a range. |
| `readAsWhy` | string \| null | Why, for an ambiguous value: "it starts with 255". |
| `contiguous` | boolean \| null | True when the mask is one block of 1 bits. false for a wildcard that is not one subnet. |
| `prefix` | number \| null | The prefix length. null for a non-contiguous wildcard. |
| `mask` | string \| null |  |
| `wildcard` | string \| null |  |
| `hex` | string \| null |  |
| `binary` | object |  |
| `addresses` | string \| null | How many addresses the mask covers, as text. |
| `usable` | string \| null | Usable hosts, following the /31 rule (RFC 3021). |
| `hostBits` | number \| null |  |
| `matchCount` | string \| null | For a non-contiguous wildcard: how many addresses match, as text (2 to the power of the free bits). |
| `plain` | string \| null | For a non-contiguous wildcard: the derived sentence, for example "Odd third octets only". Generated from the bits. |
| `address` | object |  |
| `range` | object |  |
| `snippets` | object |  |
| `ipv6` | object | Set when the value is an IPv6 prefix length (above 32): IPv6 has no masks written like this. |
| `notes` | string[] |  |
| `alternatives` | object[] | The two readings of an ambiguous or non-contiguous value (the chosen one is `role`). Empty otherwise. |

## Examples

### A prefix length: /27 and an address in it

```json
{"value":"/27","as":"auto","address":"192.168.1.40","range":""}
```

```bash
curl 'https://lookupowl.com/api/v1/tools/netmask-convert?address=192.168.1.40&as=auto&range=&value=%2F27'
```

Web page: https://lookupowl.com/wildcard-mask-calculator?q=%2F27&address=192.168.1.40

### A subnet mask: 255.255.255.224

```json
{"value":"255.255.255.224","as":"auto","address":"","range":""}
```

```bash
curl 'https://lookupowl.com/api/v1/tools/netmask-convert?address=&as=auto&range=&value=255.255.255.224'
```

Web page: https://lookupowl.com/wildcard-mask-calculator?q=255.255.255.224

### A wildcard that is not one subnet: 0.0.254.255

```json
{"value":"0.0.254.255","as":"auto","address":"10.1.1.0","range":""}
```

```bash
curl 'https://lookupowl.com/api/v1/tools/netmask-convert?address=10.1.1.0&as=auto&range=&value=0.0.254.255'
```

Web page: https://lookupowl.com/wildcard-mask-calculator?q=0.0.254.255&address=10.1.1.0

### A range as the fewest ACL entries

```json
{"value":"","as":"auto","address":"","range":"192.168.1.10 - 192.168.1.77"}
```

```bash
curl 'https://lookupowl.com/api/v1/tools/netmask-convert?address=&as=auto&range=192.168.1.10+-+192.168.1.77&value='
```

Web page: https://lookupowl.com/wildcard-mask-calculator?range=192.168.1.10+-+192.168.1.77

## Web pages

- https://lookupowl.com/wildcard-mask-calculator

## Limits and caching

- Cost: 1 unit for a live lookup, 1 unit for a cached one. Budgets are per network and published in the `RateLimit` response headers.
- Cache: results are kept for 86400 s.
- Timeout: 5 s.

## Related tools

- [IP Subnet Calculator](https://lookupowl.com/tools/subnet-calculator.md): Network, broadcast, usable range, masks and exact host counts for any IPv4 or IPv6 subnet.
- [IP in CIDR: Is This Address in That Block?](https://lookupowl.com/tools/cidr-contains.md): Check which IP addresses fall inside which CIDR blocks, and whether two lists of blocks overlap.
- [CIDR / IP Range Converter](https://lookupowl.com/tools/ip-range-convert.md): Turn CIDR blocks into first/last addresses, and IP ranges into the minimal list of CIDR blocks.
- [VLSM Subnet Planner: Split a Network into Subnets](https://lookupowl.com/tools/subnet-plan.md): Split a network into equal subnets or right-sized VLSM subnets for named host counts, and see what is left.
- [CIDR Aggregator: Merge IPs and Ranges into CIDR Blocks](https://lookupowl.com/tools/cidr-aggregate.md): Merge a messy list of IPs, ranges and CIDRs into the fewest exact CIDR blocks, with optional exclusions and firewall-ready exports.
- [IP Address Converter](https://lookupowl.com/tools/ip-convert.md): Convert IP addresses to decimal, hex and binary, IPv4 to IPv6 forms, and pull the IPv4 out of an IPv6 address.

## Guide: Wildcard mask calculator

Convert a prefix, a subnet mask and a wildcard mask, and get the lines to paste into an ACL or an OSPF network statement.

### What the calculator does

Type a prefix (`/27`), a subnet mask (`255.255.255.224`), a wildcard mask (`0.0.0.31`), a hex mask (`0xffffffe0`), 32 binary digits or a block (`192.168.1.32/27`). The page says which one it understood, then gives the other forms, how many addresses and usable hosts the mask has, and the 32 bits with the ones that must match and the ones that can be anything marked.

A wildcard mask is the inverse of a subnet mask: a 0 bit must match and a 1 bit can be anything. Wildcard masks are used in Cisco ACLs and OSPF network statements. Interfaces take the subnet mask.

### How to use it

1. **Convert a value**: Type any of the forms above. `0.0.0.0` and `255.255.255.255` can be a mask or a wildcard: we read a value that starts with 255 as a mask and one that starts with 0 as a wildcard, and the other reading is one link away.
2. **Check an address**: Under More options, add an address to see the network and broadcast address it falls in, or, for a wildcard that is not one subnet, addresses that match it and one that does not.
3. **Cover a range**: Add a range such as `192.168.1.10 - 192.168.1.77` to get the shortest list of address and wildcard pairs that match exactly that range, with the ACL lines for it. That range takes 7 pairs for 68 addresses.

### Wildcards that are not one subnet

An ACL wildcard does not have to be one block of bits. `0.0.254.255` with the address `10.1.1.0` matches every address `10.1.x.y` where `x` is odd: the lowest bit of the third octet must match, and every other bit of the last two octets can be anything. That is 15 free bits, 32,768 addresses. As a mask, `0.0.254.255` is not valid, because its 1 bits are not together; as a wildcard it is. The page generates the plain sentence from the bits, never from a list of cases.

A subnet mask is always a run of 1 bits followed by 0 bits. `255.0.255.0` is not one, and the page says so, then offers to read it as a wildcard instead. IPv6 does not use masks written like this: a length above 32 is read as an IPv6 prefix and the page points to the [subnet calculator](https://lookupowl.com/subnet-calculator).

### Subnet mask and wildcard cheat sheet, /0 to /32

Exact for IPv4. A /31 has 2 addresses and both are usable on a point-to-point link (RFC 3021). A /32 is one host.

| Prefix | Subnet mask | Wildcard | Addresses | Usable hosts |
|---|---|---|---|---|
| /32 | `255.255.255.255` | `0.0.0.0` | 1 | 1 |
| /31 | `255.255.255.254` | `0.0.0.1` | 2 | 2 |
| /30 | `255.255.255.252` | `0.0.0.3` | 4 | 2 |
| /29 | `255.255.255.248` | `0.0.0.7` | 8 | 6 |
| /28 | `255.255.255.240` | `0.0.0.15` | 16 | 14 |
| /27 | `255.255.255.224` | `0.0.0.31` | 32 | 30 |
| /26 | `255.255.255.192` | `0.0.0.63` | 64 | 62 |
| /25 | `255.255.255.128` | `0.0.0.127` | 128 | 126 |
| /24 | `255.255.255.0` | `0.0.0.255` | 256 | 254 |
| /23 | `255.255.254.0` | `0.0.1.255` | 512 | 510 |
| /22 | `255.255.252.0` | `0.0.3.255` | 1,024 | 1,022 |
| /21 | `255.255.248.0` | `0.0.7.255` | 2,048 | 2,046 |
| /20 | `255.255.240.0` | `0.0.15.255` | 4,096 | 4,094 |
| /19 | `255.255.224.0` | `0.0.31.255` | 8,192 | 8,190 |
| /18 | `255.255.192.0` | `0.0.63.255` | 16,384 | 16,382 |
| /17 | `255.255.128.0` | `0.0.127.255` | 32,768 | 32,766 |
| /16 | `255.255.0.0` | `0.0.255.255` | 65,536 | 65,534 |
| /15 | `255.254.0.0` | `0.1.255.255` | 131,072 | 131,070 |
| /14 | `255.252.0.0` | `0.3.255.255` | 262,144 | 262,142 |
| /13 | `255.248.0.0` | `0.7.255.255` | 524,288 | 524,286 |
| /12 | `255.240.0.0` | `0.15.255.255` | 1,048,576 | 1,048,574 |
| /11 | `255.224.0.0` | `0.31.255.255` | 2,097,152 | 2,097,150 |
| /10 | `255.192.0.0` | `0.63.255.255` | 4,194,304 | 4,194,302 |
| /9 | `255.128.0.0` | `0.127.255.255` | 8,388,608 | 8,388,606 |
| /8 | `255.0.0.0` | `0.255.255.255` | 16,777,216 | 16,777,214 |
| /7 | `254.0.0.0` | `1.255.255.255` | 33,554,432 | 33,554,430 |
| /6 | `252.0.0.0` | `3.255.255.255` | 67,108,864 | 67,108,862 |
| /5 | `248.0.0.0` | `7.255.255.255` | 134,217,728 | 134,217,726 |
| /4 | `240.0.0.0` | `15.255.255.255` | 268,435,456 | 268,435,454 |
| /3 | `224.0.0.0` | `31.255.255.255` | 536,870,912 | 536,870,910 |
| /2 | `192.0.0.0` | `63.255.255.255` | 1,073,741,824 | 1,073,741,822 |
| /1 | `128.0.0.0` | `127.255.255.255` | 2,147,483,648 | 2,147,483,646 |
| /0 | `0.0.0.0` | `255.255.255.255` | 4,294,967,296 | 4,294,967,294 |

### Frequently asked questions

**What is a wildcard mask?**

The inverse of a subnet mask. In a wildcard, a 0 bit means the address bit must match and a 1 bit means it can be anything. `0.0.0.31` matches 32 addresses in a row.

**How do I turn a subnet mask into a wildcard mask?**

Subtract each octet from 255. `255.255.255.224` becomes `0.0.0.31`. The calculator does this for any prefix, mask, hex or binary value.

**Can a wildcard mask match addresses that are not in one subnet?**

Yes. A Cisco ACL wildcard such as `0.0.254.255` matches every odd third octet. The page shows how many addresses it matches and gives the sentence from its bits.

**Why does a /31 show 2 usable hosts?**

On a point-to-point link a /31 needs no network or broadcast address (RFC 3021), so both addresses are usable. The calculator says so instead of showing 0.
