🔌 Port Range Calculator – Expand, Merge, Subtract & Classify TCP/UDP Ports
The Port Range Calculator is a professional-grade networking utility designed for system administrators, network engineers, DevOps practitioners, and security professionals who work with TCP/UDP port ranges daily. Whether you are writing firewall ACL rules, configuring load balancers, auditing open ports, or planning network segmentation, this tool handles all port-range arithmetic instantly in your browser.
🎯 Six Powerful Operation Modes
The calculator supports six distinct modes, each targeting a common real-world task:
| Mode | What it does | Example |
|---|---|---|
| Expand | Lists every individual port number in a range expression | 8080-8083 → 8080, 8081, 8082, 8083 |
| Compress | Converts a flat list of ports into minimal hyphenated notation | 80, 81, 82, 443 → 80-82, 443 |
| Merge | Consolidates overlapping or adjacent ranges into one set | 100-200, 150-300, 301-400 → 100-400 |
| Subtract | Removes one range from another, returning the remainder | 8000-8100 minus 8040-8060 → 8000-8039, 8061-8100 |
| Port Check | Verifies whether a single port falls inside the defined ranges | Port 9025 in 9000-9050? → ✅ Yes |
| Classify | Annotates each port with its IANA service name and category | Port 22 → SSH · Well-Known |
📝 Input Notation
Enter port expressions as comma-separated tokens. Each token is either a single port number (e.g., 443) or a hyphenated range (e.g., 8080-8090). Whitespace around commas and hyphens is ignored. A full expression might look like:
22, 80, 443, 8080-8090, 9000-9100All port values must be integers in the range 0–65535. In a hyphenated range a-b, the start value a must be less than or equal to b. Duplicate ports are silently deduplicated before calculations.
🏛️ IANA Port Categories
TCP and UDP ports are divided into three IANA-defined categories:
| Category | Range | Description |
|---|---|---|
| Well-Known | 0 – 1023 | IANA-assigned system ports (HTTP=80, SSH=22, DNS=53). Require root/admin to bind. |
| Registered | 1024 – 49151 | Application-registered ports (MySQL=3306, Redis=6379, RDP=3389). No special privileges needed. |
| Ephemeral | 49152 – 65535 | Dynamically assigned by the OS for outbound client connections. Never registered with IANA. |
🔥 Firewall Rule Generation
Enable the Generate Firewall Rules toggle and select your protocol (TCP, UDP, or Both) to receive ready-to-paste rule snippets for three major firewall tools:
iptables (multiport)
-m multiport --dports 80,443,8080:8090Note: iptables multiport supports a maximum of 15 entries. A warning is shown if your ranges exceed this limit.
nftables
tcp dport { 80, 443, 8080-8090 }firewalld XML
<port port="80" protocol="tcp"/>
<port port="443" protocol="tcp"/>
<port port="8080-8090" protocol="tcp"/>📊 Port Space Density Bar
After calculation, a visual density bar appears spanning the full 0–65535 port space. Colored segments show exactly which ports are covered, divided into three colour bands: blue for Well-Known, green for Registered, and orange for Ephemeral. This gives an instant visual sense of how your ranges are distributed across the port space.
💡 Common Use Cases
🛡️ Firewall ACL Authoring
Expand or merge ranges to understand exactly which ports a rule covers before deploying.
🐳 Container & Kubernetes Port Mapping
Verify port conflicts between services, check NodePort ranges, and generate clean port lists.
🔍 Security Auditing
Classify ports from a scan output to instantly identify which services are exposed.
📋 Documentation
Compress ad-hoc port lists into compact range notation for runbooks and change tickets.
⚙️ Calculation Logic
All operations use pure set arithmetic on sorted, deduplicated port arrays:
- Parsing — tokenizes the input on commas, detects single ports vs. hyphenated ranges, and validates each value.
- Merge — sorts ranges by start, then walks linearly, extending the current range when the next range overlaps or is adjacent (
next.start ≤ current.end + 1). - Subtraction — expands both range sets to sorted arrays, computes the set difference, then re-compresses the result.
- Compression — groups consecutive integers into
[start, end]pairs, emittingstartalone whenstart === end. - Inclusion Check — performs a linear scan over merged ranges for the queried port.