Minimal Merge Tool
Merge all mergeable CIDR blocks in a list
Input CIDR Blocks
How It Works
Iteratively finds adjacent CIDR pairs that can be combined into larger blocks. Continues until no more merges are possible.
Merged Result
Enter CIDR blocks to merge adjacent pairs
The Minimal Merge Tool processes a list of CIDR blocks and iteratively merges all adjacent, same-sized pairs into larger blocks until no more merges are possible. Paste a list like 192.168.1.0/26, 192.168.1.64/26, 192.168.1.128/26, 192.168.1.192/26 and get back 192.168.1.0/24 -- the smallest possible set of CIDR blocks representing exactly the same address space.
Understanding CIDR Merging
Over time, network configurations accumulate CIDR entries the way a codebase accumulates technical debt. A firewall ruleset that started with a clean /16 allow rule gets individual /24 entries added as exceptions or additions. A BGP prefix list that originally announced a single aggregate picks up more-specific routes as peering arrangements change. Before long, you have dozens of entries that could be expressed as a handful of blocks, but nobody has taken the time to clean them up.
CIDR merging is the cleanup operation. It takes a list of CIDR blocks and finds every pair that can combine into a larger block, then repeats the process until no more combinations are possible. The result covers exactly the same address space as the input -- no addresses added, no addresses removed -- but with fewer entries. In a routing table, fewer entries means faster lookups and lower memory consumption. In a firewall, fewer rules means faster packet processing and easier auditing. In a cloud security group, fewer entries means staying within platform rule limits without having to request increases.
The merging rules are strict. Two blocks can only merge if they meet all three conditions: same prefix length, adjacent in address space (no gap), and properly aligned on the boundary of the resulting larger block. These are the "sibling pair" rules of the CIDR binary tree. The tool applies these rules iteratively because a single pass is not enough -- when two /26 blocks merge to a /25, that new /25 might be mergeable with another /25 that was already in the list, producing a /24 that only becomes visible after the first merge.
How to Merge CIDR Blocks into a Minimal Set
- Paste your list of CIDR blocks, one per line or comma-separated
- Click merge to begin the iterative merging process
- Review the optimized output showing the minimal set of CIDR blocks
- Check the merge log to see which blocks combined and in what order
- Copy the result for use in your firewall, routing table, or security group configuration
CIDR Merge Examples
Four /26 blocks merging to a single /24
Input:
192.168.1.0/26
192.168.1.64/26
192.168.1.128/26
192.168.1.192/26
Merge progression:
| Pass | Action | Result |
|---|---|---|
| 1 | 192.168.1.0/26 + 192.168.1.64/26 | 192.168.1.0/25 |
| 1 | 192.168.1.128/26 + 192.168.1.192/26 | 192.168.1.128/25 |
| 2 | 192.168.1.0/25 + 192.168.1.128/25 | 192.168.1.0/24 |
Output: 192.168.1.0/24
Reduction: 4 blocks reduced to 1 (75% reduction)
Partial merge with non-mergeable blocks
Input:
10.0.0.0/24
10.0.1.0/24
10.0.2.0/24
10.0.5.0/24
Output:
10.0.0.0/23
10.0.2.0/24
10.0.5.0/24
Explanation: 10.0.0.0/24 and 10.0.1.0/24 merge to 10.0.0.0/23. The other two blocks cannot merge with anything (there is a gap between 10.0.2.0/24 and 10.0.5.0/24, and 10.0.2.0/24 does not form an aligned pair with 10.0.0.0/23).
Large list optimization
Input: 16 consecutive /28 blocks from 172.16.0.0/28 through 172.16.0.240/28
| Pass | Blocks | Prefix |
|---|---|---|
| Start | 16 | /28 |
| Pass 1 | 8 | /27 |
| Pass 2 | 4 | /26 |
| Pass 3 | 2 | /25 |
| Pass 4 | 1 | /24 |
Output: 172.16.0.0/24
Reduction: 16 blocks to 1 (93.75% reduction)
When to Use the Minimal Merge Tool
- Routing table optimization -- reduce BGP announcement counts by merging adjacent prefixes that your AS originates
- Firewall rule consolidation -- combine individual allow/deny entries that have accumulated over months of changes into minimal rules
- Cloud security group cleanup -- stay within AWS/Azure/GCP security group rule limits by merging redundant CIDR entries
- ACL maintenance -- simplify access control lists on routers and switches after network reorganization
- Threat intelligence processing -- compact blocklists from multiple feeds that contain overlapping or adjacent entries
- Configuration drift remediation -- restore clean configurations after incremental changes have introduced redundancy
How Iterative CIDR Merging Works
The Multi-Pass Algorithm
The merge algorithm cannot simply make a single pass through the list. When two blocks merge, the result might be mergeable with another block that was not previously adjacent. The algorithm uses multiple passes:
- Sort all CIDR blocks by network address and prefix length
- Scan the sorted list for adjacent pairs with the same prefix length that share a common parent (sibling pairs in the binary tree)
- Merge each qualifying pair into a single block with prefix length reduced by 1
- Repeat from step 1 with the new list until a full scan produces no merges
Why Multiple Passes Are Necessary
Consider 10.0.0.0/26, 10.0.0.64/26, 10.0.0.128/26, 10.0.0.192/26. In pass 1, the first two merge to 10.0.0.0/25 and the last two merge to 10.0.0.128/25. These two /25 blocks were not in the original list, but they are mergeable to 10.0.0.0/24. Without a second pass, this optimization would be missed.
Mixed Prefix Lengths
When the input contains blocks of different sizes, only same-sized siblings can merge. A /24 and a /25 never merge directly. However, if two /25 blocks merge to a /24, that new /24 might then merge with an existing /24 in a subsequent pass.
IPv4 and IPv6 Separation
The tool processes IPv4 and IPv6 blocks independently. An IPv4 block can never merge with an IPv6 block. Both address families are optimized separately, and the output clearly separates them.
Practical Tips for CIDR List Optimization
Before running the merge tool, check whether your list contains duplicates or contained blocks. While the tool handles duplicates correctly (removing them before merging), cleaning your input first helps you understand the data better. If 10.0.0.0/16 and 10.0.1.0/24 both appear in your list, the /24 is entirely contained within the /16 and adds no coverage. The CIDR Deduper can strip these out before you merge.
When you merge CIDR blocks in a firewall or ACL, always test the result in a staging environment before deploying to production. While the merge mathematically preserves exact coverage, the behavior of your specific platform might differ in edge cases. Some firewalls treat the network and broadcast addresses of a CIDR block differently, and merging two blocks might change how those boundary addresses are handled. A quick validation against your test suite catches these platform-specific issues.
Keep the merge log from the tool output. When a colleague asks why a particular address is allowed or denied, the merge log lets you trace back from the optimized rule to the original individual entries that were combined. This audit trail is essential for compliance-sensitive environments where you need to justify every rule in your configuration.
Frequently Asked Questions
Does merging change the address coverage?
No. The merged output covers exactly the same set of IP addresses as the input. No addresses are added or removed. The tool only changes the representation, not the coverage.
What is the difference between this tool and the CIDR Aggregator?
The Minimal Merge Tool only merges true sibling pairs -- blocks that are adjacent, same-sized, and boundary-aligned. The CIDR Aggregator can also produce supernets that cover slightly more address space than the input (covering gaps between non-adjacent blocks). Use the Merge Tool when you need exact coverage preservation; use the Aggregator when you are willing to accept a covering supernet.
How does this handle duplicate entries in the input?
Duplicates are removed before merging begins. If 10.0.0.0/24 appears three times in your input, it is treated as a single entry. The deduplication step ensures no false merge operations occur.
What is the maximum list size this tool handles?
The tool processes lists of thousands of CIDR blocks efficiently in the browser. The multi-pass algorithm has a worst-case complexity proportional to the number of blocks multiplied by the number of merge passes (typically 2-5 passes), making it fast even for large inputs.
How many passes does the algorithm typically need?
Most real-world lists complete in 2-3 passes. The theoretical maximum is 32 passes for IPv4 (one for each bit position), but this would require an extremely specific input of 2^32 individual /32 entries. In practice, even lists with thousands of entries rarely need more than 5 passes.
Related Tools
- Adjacency Checker - Check if two CIDR blocks can be merged
- CIDR Aggregator - Aggregate multiple CIDR blocks into summarized routes
- CIDR List Minimal Non-overlapping Set - Convert a CIDR list to minimal non-overlapping blocks
- CIDR Deduper - Remove duplicate and contained CIDR blocks
- Summarize Routes by Site/Tag - Group and summarize routes with tags