Subnet exclusion and WireGuard AllowedIPs calculator

Subtract networks from a list of IPv4 and IPv6 ranges and get the fewest CIDR blocks left.

loading Subnet exclusion and WireGuard AllowedIPs calculator
About this tool

What does a subnet exclusion calculator do?

Sometimes you need "everything except this". A VPN client should send all internet traffic through the tunnel, but keep the office LAN and the home network outside it. A firewall rule should cover a whole range minus one host. WireGuard's AllowedIPs has no "except" syntax, so you must list the blocks that remain. Doing that by hand means splitting 0.0.0.0/0 into many CIDR blocks and checking each one.

This tool does the subtraction. You give it a list of allowed networks and a list of excluded networks, and it returns the fewest CIDR blocks that cover exactly the allowed addresses minus the excluded ones. It works with IPv4 and IPv6 in the same list. The result can be written as a WireGuard AllowedIPs line, as one block per line, or as ip route add commands for a given interface.

The calculation runs in your browser and nothing is uploaded. The result is checked against a brute-force model in the tool's tests, so no address is lost and none is counted twice. To make the full set of keys and client files that use this line, see the WireGuard config generator.

How to exclude subnets and build AllowedIPs

  1. In Allowed networks, write what may pass. The box opens with 0.0.0.0/0, ::/0, which means all IPv4 and all IPv6.
  2. In Excluded networks, write what must be left out. It opens with the private ranges. The preset buttons (private ranges, 192.168.0.0/16, Tailscale and CGNAT, link-local) add their networks to the list without removing yours.
  3. Separate items with commas, spaces or new lines. Each item can be an address, a block such as 10.0.0.0/8, or a range such as 10.0.0.1-10.0.0.9. A # starts a comment, and you can paste a whole AllowedIPs = line.
  4. Choose the output: AllowedIPs line, one per line, or ip route. For ip route, fill the interface name (default wg0).
  5. Read the result and the counts: how many blocks (split between IPv4 and IPv6) and how many addresses remain. If an excluded network does not overlap the allowed ones, a note says it removed nothing.
  6. Copy the result. For WireGuard, paste the line into the client's [Peer] section. Use the IPv4 subnet calculator to inspect any single block.

If the allowed server address itself falls inside the allowed range, remember to exclude it or route it outside the tunnel, otherwise the tunnel packets can try to travel through the tunnel.

Examples

All IPv4 except one LAN

Allowed 0.0.0.0/0, excluded 192.168.0.0/16. The result is 16 blocks:

AllowedIPs = 0.0.0.0/1, 128.0.0.0/2, 192.0.0.0/9, 192.128.0.0/11, 192.160.0.0/13, 192.169.0.0/16, 192.170.0.0/15, 192.172.0.0/14, 192.176.0.0/12, 192.192.0.0/10, 193.0.0.0/8, 194.0.0.0/7, 196.0.0.0/6, 200.0.0.0/5, 208.0.0.0/4, 224.0.0.0/3

Every address is in exactly one block, and 192.168.0.0/16 is the gap between 192.160.0.0/13 and 192.169.0.0/16.

Half of a network

Allowed 10.0.0.0/24, excluded 10.0.0.0/25. One block is left, and the tool says 128 IPv4 addresses remain:

AllowedIPs = 10.0.0.128/25

A range minus one address

Allowed 10.0.0.1-10.0.0.9, excluded 10.0.0.5. A range is not a block, so it is split into the fewest blocks:

AllowedIPs = 10.0.0.1/32, 10.0.0.2/31, 10.0.0.4/32, 10.0.0.6/31, 10.0.0.8/31

The counter shows 5 blocks and 8 addresses.

IPv6 and routes

Allowed ::/0, excluded fc00::/7, gives seven blocks: ::/1, 8000::/2, c000::/3, e000::/4, f000::/5, f800::/6, fe00::/7. In the ip route format, with interface wg0, a block pair looks like this:

ip route add 10.0.0.128/25 dev wg0
ip -6 route add 8000::/2 dev wg0

The default: everything except private networks

With 0.0.0.0/0, ::/0 allowed and 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7 excluded, the tool writes 38 blocks: 31 for IPv4 and 7 for IPv6. The first ones are 0.0.0.0/5, 8.0.0.0/7, 11.0.0.0/8, 12.0.0.0/6.

Common errors and how to fix them

The messages name the list and the line where the problem is. The rest of the calculation still runs.

  • Allowed networks, line 2: nope is not an IPv4 or IPv6 address, block or range. A token is misspelled or has a wrong octet, such as 10.0.0.256. Fix it or remove it.
  • The prefix in 1.2.3.4/40 is out of range. The prefix goes from 0 to 32 for IPv4 and 0 to 128 for IPv6.
  • In 10.0.0.9-10.0.0.1 the range ends before it starts. Swap the two ends.
  • 10.0.0.1-::2 mixes an IPv4 and an IPv6 address. Write two separate items.
  • Nothing is left. The excluded networks cover everything allowed. Check you did not exclude 0.0.0.0/0.
  • A block does not overlap the allowed networks, so it removed nothing. Not an error, but check for a typo in the excluded block.

Frequently asked questions

Why does the result have so many blocks?

A CIDR block must start at a boundary that matches its size, so a hole in the middle of a large network needs one block per level on each side. Excluding one /16 from all IPv4 takes 16 blocks, which is the fewest possible.

Does WireGuard understand an exclusion directly?

No. AllowedIPs is only a list of what to send, so you give it the blocks that remain. Some newer tools add an exclusion setting, but the plain config file does not.

Is a block with host bits accepted?

Yes. 10.1.2.3/8 is read as 10.0.0.0/8.

Is anything sent to a server?

No. The calculation runs in your browser.

Report a problem