CIDR Difference (A − B)

Subtract set B from set A and return the minimal set of CIDRs that remain.

About This Tool

The CIDR Difference Calculator performs set subtraction on IP address ranges by subtracting set B from set A (A − B), returning the minimal set of CIDR blocks that remain. This tool is essential for network planning scenarios where you need to exclude certain IP ranges from a larger network allocation, such as carving out reserved ranges, removing assigned blocks from available space, or calculating the remaining capacity after allocations. It supports both IPv4 and IPv6, handles multiple CIDR inputs, and offers alignment constraints for cleaner subnet boundaries.

How to Use

  1. Enter one or more CIDR blocks in Set A (the network to subtract from), one per line
  2. Enter one or more CIDR blocks in Set B (the ranges to remove from A), one per line
  3. Optionally enable "Constrain alignment" to force results to align on specific prefix boundaries
  4. When constrained, specify the prefix length for alignment (e.g., 24 for /24 boundaries)
  5. Click "Compute" to calculate the difference
  6. View separate results for IPv4 and IPv6 ranges
  7. The tool automatically returns the minimal set of CIDR blocks covering the remaining space

Features

  • Set subtraction for CIDR ranges (A − B)
  • Supports both IPv4 and IPv6 addresses
  • Handles multiple CIDR blocks in each set
  • Minimal CIDR representation by default
  • Optional alignment constraints for cleaner subnet boundaries
  • Real-time calculation with compute button
  • Separate output for IPv4 and IPv6 results
  • Validates all CIDR notation inputs

Common Use Cases

  • Removing allocated subnets from available IP space
  • Calculating remaining capacity after subnet assignments
  • Excluding reserved ranges (network, broadcast, gateway) from allocations
  • Carving out DMZ or management networks from larger blocks
  • Determining available space after cloud resource allocations
  • Planning subnet expansions by removing existing allocations
  • Documenting free IP space in complex network environments
  • Calculating IP space available for future growth
  • Removing overlapping ranges when consolidating networks
  • Identifying gaps between allocated and total address space

Technical Details

CIDR difference operates on the principle of set subtraction, where addresses present in set B are removed from set A, and the result is expressed as the minimal set of non-overlapping CIDR blocks.

Basic Example (Minimal Mode):

  • Set A: 192.168.1.0/24 (256 addresses: .0 to .255)
  • Set B: 192.168.1.0/25 (128 addresses: .0 to .127)
  • Result: 192.168.1.128/25 (128 remaining addresses: .128 to .255)

Complex Example:

  • Set A: 10.0.0.0/22 (1024 addresses: 10.0.0.0 to 10.0.3.255)
  • Set B: 10.0.1.0/24 (256 addresses: 10.0.1.0 to 10.0.1.255)
  • Result: 10.0.0.0/24, 10.0.2.0/23 (remaining 768 addresses)

Constrained Alignment Mode:

When you enable alignment constraints with a specific prefix (e.g., /24), the tool ensures all resulting CIDR blocks align on those boundaries. This is useful for maintaining clean subnet organization:

  • Without constraint: May produce /25, /26, /27 subnets for minimal representation
  • With /24 constraint: Forces all results to /24 boundaries, even if less optimal

Algorithm Behavior:

  • Expands all CIDR blocks to their individual IP ranges
  • Performs set subtraction (removes B addresses from A)
  • Aggregates remaining addresses into minimal CIDR representation
  • Applies alignment constraints if specified
  • Separates results by IPv4 and IPv6

Edge Cases:

  • If B completely contains A, the result is empty
  • If A and B don't overlap, the result equals A
  • Multiple blocks in A and B are processed together as unified sets