CIDR Exclusion Tool
Subtract exception CIDRs from a parent block
Remaining CIDRs
The CIDR Exclusion Tool subtracts one or more exception CIDR blocks from a parent CIDR range, returning the minimal set of CIDR blocks that cover the remaining address space. Enter a parent block like 10.0.0.0/8 and exclusions like 10.100.0.0/16, 10.200.0.0/16 to get the precise set of CIDRs that tile the remaining space without including the carved-out ranges.
Understanding CIDR Exclusions
If you manage firewalls, routing policies, or cloud security groups, you will eventually need to express a rule that says "allow this entire range except for these specific subnets." The concept is straightforward, but the math is not. You cannot simply write "10.0.0.0/8 minus 10.100.0.0/16" in a firewall rule -- you need to express the remaining space as a list of valid CIDR blocks that your device actually understands. That is what CIDR exclusion does: it performs the set-difference operation and hands you the result in a format you can paste directly into a configuration.
The reason this is harder than it looks comes down to how CIDR notation works. Every CIDR block must be a contiguous range of addresses whose size is a power of two, starting on an aligned boundary. When you punch a hole in a larger block, the remaining space rarely lines up neatly with those constraints. Excluding 10.100.0.0/16 from 10.0.0.0/8 produces eight separate CIDR blocks of various sizes because the exclusion boundary at the 100th position in the second octet forces splits at multiple levels of the binary address tree. Doing this by hand is tedious and error-prone, especially when you have multiple exclusions at different positions within the parent.
This tool handles all the complexity automatically. You provide the parent block and the list of exclusions, and it returns the mathematically minimal set of CIDRs that cover the remaining space. Whether you are carving out a DMZ from an enterprise-wide allow rule, reserving a block within a larger allocation for future use, or building BGP announcements with delegated sub-blocks withdrawn, the output gives you exactly what you need for your device configuration.
How to Subtract CIDR Blocks from a Parent Range
- Enter the parent CIDR block (e.g.,
10.0.0.0/8) - Enter one or more exclusion CIDRs, one per line or comma-separated (e.g.,
10.100.0.0/16,10.200.0.0/16) - Click calculate to get the minimal set of remaining CIDR blocks
- Review the output list showing each resulting block with its address count
- Copy the results for use in firewall rules, ACLs, or routing configurations
CIDR Exclusion Examples
Excluding a single /16 from a /8
| Field | Value |
|---|---|
| Parent CIDR | 10.0.0.0/8 |
| Exclusion | 10.100.0.0/16 |
| Result | 10.0.0.0/10, 10.64.0.0/11, 10.96.0.0/14, 10.101.0.0/16, 10.102.0.0/15, 10.104.0.0/13, 10.112.0.0/12, 10.128.0.0/9 |
| Remaining IPs | 16,711,680 |
Excluding two subnets from a /16
| Field | Value |
|---|---|
| Parent CIDR | 192.168.0.0/16 |
| Exclusions | 192.168.1.0/24, 192.168.100.0/24 |
| Remaining blocks | 14 CIDR blocks covering 65,024 addresses |
Excluding a /28 from a /24
| Field | Value |
|---|---|
| Parent CIDR | 172.16.5.0/24 |
| Exclusion | 172.16.5.64/28 |
| Result | 172.16.5.0/26, 172.16.5.80/28, 172.16.5.96/27, 172.16.5.128/25 |
| Remaining IPs | 240 |
When to Use the CIDR Exclusion Tool
- Firewall allow rules with exceptions -- permit traffic from
10.0.0.0/8but block the DMZ at10.100.0.0/16 - IP address allocation -- reserve a
/24within a larger block for a specific purpose and allocate the rest - Cloud security groups -- create rules covering a VPC CIDR minus specific private subnets
- BGP announcements -- advertise a large prefix while withdrawing a more-specific block delegated elsewhere
- Compliance carve-outs -- exclude regulated subnets from general access policies
- Multi-tenant environments -- express "all customer space except tenant X" in shared infrastructure rules
How CIDR Exclusion Arithmetic Works
CIDR exclusion is fundamentally a set difference operation on IP address space. The algorithm works by:
Step 1: Binary Alignment
Every CIDR block maps to a contiguous range of addresses aligned on a power-of-two boundary. The parent 10.0.0.0/8 covers addresses 10.0.0.0 through 10.255.255.255 (16,777,216 addresses).
Step 2: Recursive Splitting
When an exclusion falls inside the parent, the parent must be split into sub-blocks that tile around the hole. The algorithm recursively bisects the parent along CIDR boundaries until each resulting block either falls entirely outside the exclusion or entirely inside it (and is discarded).
Parent: 10.0.0.0/8
|===============================|
Exclusion: 10.100.0.0/16
| |XX| |
Split: |/9 |/10|/14|/16|/15|/13|/12|/9|
Step 3: Minimal Recombination
Adjacent blocks at the same prefix length that share a common parent are recombined. This ensures the output is the mathematically minimal set of CIDRs representing the remaining space.
Why the Result Has Many Blocks
Excluding a range that does not align with the parent's binary boundaries produces many small CIDRs. For example, excluding 10.100.0.0/16 from 10.0.0.0/8 yields 8 blocks because the hole at position 100 forces splits at multiple levels of the binary tree. A hole on a more natural boundary (like 10.128.0.0/9) would produce fewer blocks because the split aligns with the binary structure.
Practical Tips for CIDR Exclusions
The most common mistake when working with exclusions is forgetting to verify that your exclusion CIDRs are actually contained within the parent. If an exclusion partially overlaps the parent boundary, the tool correctly handles it by only subtracting the overlapping portion, but the result may not be what you expected. Always double-check that your exclusion ranges make sense relative to the parent before deploying the resulting rules.
When building firewall rules from exclusion results, keep in mind that the order of rules matters on most devices. If your firewall processes rules top-to-bottom, you typically want to place the deny rules for the excluded ranges before the broader allow rule. However, if you are using the exclusion output as the allow list itself (with an implicit deny-all), then rule order within the allow set does not matter because the excluded addresses are simply absent from the list.
Another consideration is rule count limits. Some platforms, particularly cloud security groups, impose caps on the number of rules per group. An exclusion that produces 15 result blocks means 15 rules. If you are close to your limit, consider whether you can restructure the parent into smaller blocks where exclusions produce fewer fragments, or whether the platform supports IP sets or prefix lists that handle the complexity outside the rule table.
Frequently Asked Questions
Can I exclude multiple non-contiguous CIDRs at once?
Yes. Enter all exclusion CIDRs separated by commas or newlines. The tool processes them all simultaneously and returns the single minimal set of blocks covering the remaining space. The order of exclusions does not affect the result.
What happens if an exclusion is larger than or equal to the parent?
If an exclusion completely covers the parent CIDR, the result is an empty set -- there is no remaining address space. If the exclusion extends beyond the parent boundaries, only the overlapping portion is subtracted.
Does this work with IPv6?
Yes. The tool handles both IPv4 and IPv6 CIDR blocks. IPv6 exclusions follow the same binary splitting algorithm but operate on 128-bit addresses. For example, excluding 2001:db8:1::/48 from 2001:db8::/32 produces the expected set of remaining /48, /47, /46, etc. blocks.
How is this different from the Range Difference tool?
The CIDR Exclusion Tool takes CIDR notation as input and output, optimizing for use in firewall rules and routing configurations. The Range Difference tool works with arbitrary IP ranges (start-end notation) that may not align to CIDR boundaries. Use CIDR exclusion when your inputs and outputs are CIDR blocks.
Can I nest exclusions -- exclude from an already-excluded result?
Yes. Take the output of one exclusion operation and use it as input for another. However, it is simpler to list all exclusions at once in a single operation. The tool handles multiple simultaneous exclusions correctly and the result is the same as applying them sequentially.
How many result blocks should I expect?
The number of result blocks depends on where the exclusion falls relative to the parent's binary structure. Exclusions on natural power-of-two boundaries produce fewer blocks. In the worst case, excluding a single /32 from a /0 produces 32 blocks (one for each bit position). In practice, most exclusions produce between 4 and 15 result blocks.
Related Tools
- Range Difference - Calculate A minus B for arbitrary IP ranges
- CIDR Gap Finder - Find unallocated gaps within a parent CIDR
- CIDR Aggregator - Aggregate multiple CIDR blocks into summarized routes
- CIDR List Minimal Non-overlapping Set - Convert a CIDR list to minimal non-overlapping blocks
- Minimal Merge Tool - Merge all mergeable CIDR blocks in a list