Skip to main content

calculateCIDR

CI PyPI version License: MIT GitHub stars

Fast CIDR network calculator for the terminal: IPv4 & IPv6, subnet division, address classification, binary view and JSON output for scripts.

cidr demo: network details, subnet division and JSON output


✨ Features

  • 🌐 IPv4 & IPv6 — network ID, host range, broadcast, netmask, wildcard and host count
  • 🎯 Any address works — 10.1.2.3/20 shows 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 — /31 point-to-point links have 2 usable hosts, /32 has 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_COLOR is set; errors go to stderr

📥 Installation

pip install cidr-calculator

Or from source:

git clone https://github.com/serber-info/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

GitHub

Metadata

Release files for cidr-calculator 2.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cidr-calculator 2.1.1
File Size Uploaded
cidr_calculator-2.1.1.tar.gz 9.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cidr-calculator 2.1.1
File Interpreter ABI Platform
cidr_calculator-2.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.9 kB

Release files / cidr_calculator-2.1.1.tar.gz

Download URL cidr_calculator-2.1.1.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
50c7ee7d782f767066f40c4c6db1a2fc5e85a8d32fe28c87cfec4d2491ad2ec6
BLAKE2b-256 checksum
How to use checksums
797041d4d11f1a89d1cfb103674178017cf4a3c5cd8caafad4bc269f1997805a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / cidr_calculator-2.1.1-py3-none-any.whl

Download URL cidr_calculator-2.1.1-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc1a1d5cf2c9d485f843ee4045a92560cc48d4e898ba8683358c2979c061ecdf
BLAKE2b-256 checksum
How to use checksums
8ad03a5c71cf2e23b6cd5cd575dffd7ea3b1276de2d7ee19b4080e2f8ae2609b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

2.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page