Port List Compressor

Compress port lists into ranges

Input Ports

Compressed Output

Compressed output will appear here

The Port List Compressor converts a list of individual port numbers into the most compact range notation possible. Paste a list like 20, 21, 22, 23, 25, 53, 80, 443, 8080, 8081, 8082 and get the optimized output 20-23, 25, 53, 80, 443, 8080-8082.

Understanding Port List Compression

Firewall rules, security documentation, and network configurations are easier to read when port lists are expressed as ranges rather than individual numbers. A rule that says "allow ports 8000-8100" is immediately understandable, while a rule listing 101 individual ports requires counting to verify coverage. But in practice, port lists often end up as flat lists of individual numbers -- accumulated one at a time as services are added, exported from tools that do not support range notation, or copied from documentation that listed ports individually.

Compression is the process of identifying consecutive sequences within a flat list and collapsing them into range notation. The algorithm is straightforward: sort the ports numerically, walk through the sorted list, and whenever you find a run of consecutive numbers (80, 81, 82, 83), replace it with a range (80-83). Non-consecutive ports remain as individual entries. The result is the most compact representation of the same set of ports.

This is not just a cosmetic improvement. Many firewall systems have limits on the number of rules or entries they can process. AWS security groups, for example, have a default limit of 60 inbound rules per group. If you are listing ports individually instead of using ranges, you hit that limit much faster. Compressing your port lists can be the difference between fitting your rules into a single security group and needing to split across multiple groups, which adds complexity to your infrastructure.

How to Compress a Port List into Ranges

  1. Paste your list of port numbers in any format -- one per line, comma-separated, or space-separated
  2. The compressor sorts and deduplicates the list automatically
  3. Consecutive port sequences are collapsed into dash-separated ranges
  4. Non-consecutive ports remain as individual entries
  5. Copy the compressed output in standard range notation

Port Compression Examples

Consecutive Ports Become Ranges

InputCompressed Output
80, 81, 82, 83, 84, 8580-85
22, 23, 24, 2522-25
3000, 3001, 3002, 30033000-3003

Mixed Lists Produce Optimal Notation

InputCompressed Output
22, 80, 81, 82, 44322, 80-82, 443
20, 21, 22, 25, 53, 80, 44320-22, 25, 53, 80, 443
8000, 8001, 8002, 8003, 8004, 8005, 8080, 84438000-8005, 8080, 8443

Real-World Compression

Before (20 individual ports):

20, 21, 22, 23, 25, 53, 80, 110, 143, 443,
465, 587, 993, 995, 3306, 5432, 8080, 8081, 8082, 8443

After (14 entries):

20-23, 25, 53, 80, 110, 143, 443, 465, 587, 993, 995, 3306, 5432, 8080-8082, 8443

Compression Statistics

The tool reports how effectively the list was compressed:

MetricValue
Input ports20
Output entries14
Compression ratio30% reduction
Duplicates removed0

When to Use the Port List Compressor

  • Cleaning up firewall rules that have accumulated individual port entries over time
  • Documenting port requirements in a concise format for security reviews and change requests
  • Optimizing configurations for firewalls with rule count limits (e.g., AWS security group limits of 60 rules per group)
  • Consolidating port specifications from multiple teams, applications, or vendors
  • Preparing specifications for security audits where compact notation improves readability
  • Reducing configuration drift by standardizing how port lists are expressed across your infrastructure

How Port Range Compression Works

The Compression Algorithm

  1. Parse all input port numbers from any supported format
  2. Validate each port is within 0-65535
  3. Deduplicate by removing repeated values
  4. Sort numerically in ascending order
  5. Identify runs of consecutive numbers (e.g., 80, 81, 82)
  6. Collapse runs into ranges using dash notation (80-82)
  7. Output the optimized combination of ranges and individual ports

Single-Port "Ranges"

A sequence of one port (e.g., 443 with no adjacent ports 442 or 444 in the list) remains as a single entry. The compressor never produces ranges like 443-443 -- a solitary port is always written as 443.

Deduplication

Duplicate port numbers in the input are silently removed. Entering 80, 443, 80, 80, 443 produces 80, 443 -- not an error, just clean output.

Port Compression in Practice

The most valuable application of port compression is during security reviews. When a security auditor asks "what ports are open on this system?", handing them a compressed list is far more useful than a raw list of 50 individual port numbers. Compressed notation makes patterns visible at a glance: a range like 8000-8010 immediately tells the auditor "this is an application cluster with 11 consecutive ports," while the same information spread across 11 individual entries requires more effort to interpret. The auditor can quickly assess whether the range is reasonable or whether it should be narrowed.

Another common scenario is consolidating port requirements from multiple teams. The application team says they need ports 8080-8085 and 8443. The database team says they need 3306 and 5432. The monitoring team says they need 9090 and 9100. Instead of maintaining three separate lists that get out of sync, compress them into a single specification: 3306, 5432, 8080-8085, 8443, 9090, 9100. This unified list is easier to maintain, easier to audit, and less likely to contain errors than three independent lists.

When working with automation tools, compression also helps reduce configuration file size and improve readability. A Terraform security group rule with ports = [8000, 8001, 8002, 8003, 8004, 8005, 8006, 8007, 8008, 8009, 8010] is harder to review than ports = ["8000-8010"] -- and more likely to contain a typo where one port in the sequence was accidentally skipped or duplicated.

Frequently Asked Questions

Does compression change which ports are included?

No. Compression is a lossless notation change -- 80-85 and 80, 81, 82, 83, 84, 85 represent exactly the same set of ports. The compressor never adds or removes ports, it only changes the representation.

What input formats are accepted?

The compressor accepts ports separated by commas (80,443,8080), spaces (80 443 8080), newlines (one per line), or any combination. Leading and trailing whitespace is ignored. Non-numeric values are flagged as errors.

Can I reverse the compression back to individual ports?

Yes. Use the Port List Expander to convert range notation back into individual port numbers. The two tools are complementary -- compress for readability, expand for systems that require individual port entries.

What is the minimum run length for compression?

Two consecutive ports are enough to form a range. Ports 80, 81 compress to 80-81. A single isolated port always remains as an individual entry. The compressor uses ranges wherever they reduce the total number of entries.

How does the compressor handle unsorted input?

The compressor sorts all ports numerically before identifying ranges, so the input order does not matter. 443, 80, 81, 82, 22 produces the same output as 22, 80, 81, 82, 443: 22, 80-82, 443.

Related Tools

IPparse•Free Network & Subnet Calculator Tools

© 2026 IPparse. All tools run locally in your browser.

100% Privacy-First • No Data Collected