calculateCIDR
Fast CIDR network calculator for the terminal: IPv4 & IPv6, subnet division, address classification, binary view and JSON output for scripts.
✨ Features
- 🌐 IPv4 & IPv6 — network ID, host range, broadcast, netmask, wildcard and host count
- 🎯 Any address works —
10.1.2.3/20shows the address and the network it belongs to - 🧩 Subnet division — split any network into N subnets with correct prefix math
- 🏷️ Address type — Private (RFC 1918), Public, CGNAT, Loopback, Link-local, Multicast, Documentation…
- 📐 RFC 3021 aware —
/31point-to-point links have 2 usable hosts,/32has 1 - 🔠 Binary display — every IPv4 field in binary octets
- 🤖 JSON output — pipe results into
jq, Ansible or your own scripts - 🔇 Script-friendly — plain output when piped or when
NO_COLORis set; errors go to stderr
📥 Installation
pip install cidr-calculator
Or from source:
git clone https://github.com/serber1990/calculateCIDR.git
cd calculateCIDR
pip install -e .
🛠 Usage
cidr IP/PREFIX [-divide N] [-binary] [--json]
| Option | Description |
|---|---|
IP/PREFIX |
Address with CIDR prefix (-ip IP/PREFIX also works) |
-divide N |
Split the network into N subnets |
-binary |
Show IPv4 addresses in binary |
-j, --json |
Machine-readable JSON output |
-v, --version |
Show version |
-h, --help |
Show help |
🎨 Examples
Network details
cidr 192.168.1.10/24
╔══════════════════════════════════════════════╗
║ 192.168.1.0/24 · IPv4 ║
╚══════════════════════════════════════════════╝
Address 192.168.1.10
Network ID 192.168.1.0
First Host 192.168.1.1
Last Host 192.168.1.254
Broadcast 192.168.1.255
Netmask 255.255.255.0
Wildcard 0.0.0.255
Prefix /24
Hosts 254
Type Private (RFC 1918)
Subnet division
cidr 192.168.1.0/24 -divide 4
╔════════════════════════════════════════════════════╗
║ 192.168.1.0/24 · 4 subnets / new prefix /26 ║
╚════════════════════════════════════════════════════╝
# Subnet Network ID First Host Last Host Broadcast Netmask Wildcard Hosts
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 192.168.1.0/26 192.168.1.0 192.168.1.1 192.168.1.62 192.168.1.63 255.255.255.192 0.0.0.63 62
2 192.168.1.64/26 192.168.1.64 192.168.1.65 192.168.1.126 192.168.1.127 255.255.255.192 0.0.0.63 62
3 192.168.1.128/26 192.168.1.128 192.168.1.129 192.168.1.190 192.168.1.191 255.255.255.192 0.0.0.63 62
4 192.168.1.192/26 192.168.1.192 192.168.1.193 192.168.1.254 192.168.1.255 255.255.255.192 0.0.0.63 62
When N is not a power of two, the next power is used and the first N subnets are shown.
JSON for scripts
cidr 10.0.0.0/30 --json
{
"input": "10.0.0.0/30",
"address": "10.0.0.0",
"network": "10.0.0.0/30",
"version": 4,
"network_id": "10.0.0.0",
"broadcast": "10.0.0.3",
"netmask": "255.255.255.252",
"wildcard": "0.0.0.3",
"prefix": 30,
"first_host": "10.0.0.1",
"last_host": "10.0.0.2",
"usable_hosts": 2,
"total_addresses": 4,
"type": "Private (RFC 1918)"
}
# Usable hosts of a network, straight into a variable
hosts=$(cidr 10.20.0.0/22 --json | jq .usable_hosts)
Binary and IPv6
cidr 192.168.1.0/24 -binary
cidr 2001:db8::/32 -divide 16
🧪 Development
pip install -e ".[dev]"
ruff check .
pytest
See CHANGELOG.md for release notes.
📝 License
MIT — see LICENSE.
💬 Feedback
Open an issue or reach out via GitHub.
🌐 Connect
Release files for cidr-calculator 2.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cidr_calculator-2.1.0.tar.gz | 9.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cidr_calculator-2.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.8 kB
Release files / cidr_calculator-2.1.0.tar.gz
| Download URL | cidr_calculator-2.1.0.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
50b59c66b3979a50c2299597aed894ad8d2d3e566042ca5eb1ab9fc67ba0af11
|
|
BLAKE2b-256 checksum How to use checksums |
8d50e16c0c0368db928d5a98ce882a3a3a5f305dc102be564c3746431c209d99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / cidr_calculator-2.1.0-py3-none-any.whl
| Download URL | cidr_calculator-2.1.0-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
24a417f46913ad48704f67757f29f4a7671f62df4bc51aa0ee739bcbf9ebaf02
|
|
BLAKE2b-256 checksum How to use checksums |
0e26f0824ab37301df2453cc2ad4db9d68239800d1b727573af601b329794182
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|