IP Range to CIDR: Find the Smallest Prefix That Fits

IP Range to CIDR: Find the Smallest Prefix That Fits

IP range to CIDR asks: which prefix bits do these addresses share, and do they fill that prefix exactly? When they do, you get one block. When they do not, you get a list. FlashKit’s IP to CIDR calculator checks a single address + prefix. It does not take two endpoints. The splits below come from Python ipaddress.summarize_address_range.

Aligned ranges: one prefix

summarize_address_range(192.168.1.0, 192.168.1.255) → 192.168.1.0/24. Count: 256 addresses, which is 2^(32−24). 10.0.0.0–10.0.0.31 → 10.0.0.0/27. 172.16.0.0–172.16.1.255 → 172.16.0.0/23.

Type 192.168.1.1 and prefix 24 on the calculator: network 192.168.1.0, last usable 192.168.1.254, broadcast 192.168.1.255. That confirms the block; it does not invent it from two ends.

Verify a prefix you already have

IPv4 address + slider. Not a range inverter.

Open the CIDR calculator

Unaligned ranges: the split

Python output, pasted:

  • 192.168.1.10–192.168.1.20 → 192.168.1.10/31, 192.168.1.12/30, 192.168.1.16/30, 192.168.1.20/32
  • 192.0.2.1–192.0.2.14 → 192.0.2.1/32, 192.0.2.2/31, 192.0.2.4/30, 192.0.2.8/30, 192.0.2.12/31, 192.0.2.14/32

A /28 covering 192.168.1.0–15 would include .0–.9, which the 10–20 range did not ask for. Rounding up is how ACLs leak. Hand method: XOR the two ends, find the highest bit that differs, then emit the largest aligned prefix that stays inside the range, repeat. summarize_address_range is that loop.

By-hand CIDR → range (the forward direction): CIDR to IP range. Vocabulary and /24 pictures: CIDR notation explained. After you have a host IP, coarse geo is IP address lookup.

Look up a single address

Geo/ISP snapshot via a public API. Not warrant-grade, and the query leaves the browser.

Open IP lookup

Worked splits, pasted from ipaddress

summarize_address_range(IPv4Address("192.168.1.10"), IPv4Address("192.168.1.20")) returned four networks: 192.168.1.10/31, 192.168.1.12/30, 192.168.1.16/30, 192.168.1.20/32. Count the addresses: 2 + 4 + 4 + 1 = 11, which is 10 through 20 inclusive. A single /28 cannot represent that range without extra hosts: 192.168.1.16/28 is .16–.31; 192.168.1.0/28 is .0–.15. Neither equals 10–20.

192.168.1.0–192.168.1.255 → 192.168.1.0/24 (aligned). 10.0.0.0–10.0.0.31 → 10.0.0.0/27. 10.0.0.0–10.0.1.255 → 10.0.0.0/23. When the count of addresses is a power of two and the start is aligned on that size, you get one prefix. When it is not, you get a list. FlashKit cannot invert the list; you type each prefix back into the slider to read network, mask, broadcast, and usable hosts.

Usable hosts on the widget is still classic IPv4: total − 2, or 0 for /31 and /32. So a summarized /31 that RFC 3021 would call two hosts shows 0 usable on the card. If you are building an ACL, the addresses in the summarized list are the ones to allow, not the usable-hosts card.

Do not round up a messy range

The smallest prefix that covers 192.168.1.10–20 is not the same as the list that equals 192.168.1.10–20. A covering /28 or /24 includes extra numbers. Security groups that round up have opened hosts you did not intend. Prefer the summarized list. If a vendor UI only accepts one CIDR, either accept the extra hosts explicitly or split the rule into several CIDRs — many clouds allow a list.

The calculator’s IP Address field is one dotted quad. There is no “end address” box. Workflow: summarize in Python (or an equivalent library), then paste each network address and drag the prefix. Domain-to-IP is a different job (DNS A/AAAA). IP geo lookup is a different job (a third-party geo API). Neither inverts a range. The forward direction — prefix to first/last — is the CIDR-to-range guide. This page is the inverse, with honesty about what the widget will not do.

Hand method when you do not have Python

Write both ends as 32-bit integers. XOR them. The highest bit that differs tells you how large an aligned prefix can be at the start address. Emit the largest prefix that (a) starts at or after the remaining start, (b) ends at or before the remaining last, (c) is aligned on its own size. Subtract that block, repeat. That is what summarize_address_range implements. For 192.168.1.10–20:

  • Start 10 is even, so a /31 (two addresses) fits: 10–11. Remainder 12–20.
  • 12 is divisible by 4, and 12+3=15 is inside 20, so a /30 fits: 12–15. Remainder 16–20.
  • 16 is divisible by 4, 16+3=19 is inside 20, so another /30: 16–19. Remainder 20–20.
  • 20 is a single host: /32.

You cannot replace that list with 192.168.1.0/28 (.0–.15) or 192.168.1.16/28 (.16–.31). Both leak extra hosts. A firewall rule that used either /28 would allow addresses the range 10–20 did not include.

Check each emitted prefix on FlashKit: type the network address, set the prefix, read first/last. For 192.168.1.10/31 the widget’s usable-hosts card is 0 (classic subtract-2 on a /31). The addresses in the ACL are still .10 and .11. Trust the summarized list for allow-rules, not the usable-hosts card.

More splits, then stop rounding

Python summarize_address_range for 192.0.2.1–192.0.2.14 (TEST-NET-1, RFC 5737) returned six networks: 192.0.2.1/32, 192.0.2.2/31, 192.0.2.4/30, 192.0.2.8/30, 192.0.2.12/31, 192.0.2.14/32. Count: 1+2+4+4+2+1 = 14, which is 1 through 14 inclusive. A covering /28 would be 192.0.2.0–15, which adds .0 and .15.

Aligned examples worth memorizing: 256 addresses starting at a /24 boundary → one /24. 32 addresses starting at a /27 boundary → one /27. 512 addresses starting at a /23 boundary → one /23. If the start is not aligned, you get a list even when the count is a power of two. 192.168.1.1–192.168.1.8 is eight addresses but is not 192.168.1.0/29 (.0–.7) and not 192.168.1.8/29 (.8–.15).

Cloud security groups often accept a list of CIDRs. Prefer the list. If a vendor UI allows only one CIDR, you must either (1) accept extra hosts in a covering prefix and document them, or (2) split into several rules. Rounding up silently is how a lab range becomes a /16 in production. FlashKit will not stop you: it only shows one prefix at a time. The discipline is in the summarize step, not in the slider.

Python for 192.168.1.1–192.168.1.8 returned four networks: 192.168.1.1/32, 192.168.1.2/31, 192.168.1.4/30, 192.168.1.8/32. Count: 1+2+4+1 = 8. That range is eight addresses and still is not a /29. 192.168.1.0/29 is .0–.7 (includes .0, excludes .8). 192.168.1.8/29 is .8–.15 (includes six extra hosts). Paste each of the four prefixes into the calculator to read network, mask, and broadcast. Usable hosts on the /31 and /32 cards will be 0; the allow-list is still the addresses in the summarized list.

IPv6 range summarization exists in the same Python module (summarize_address_range on IPv6Address). FlashKit’s slider will not take those prefixes. Mapped IPv6 (::ffff: plus the IPv4 bits) is a spelling of one host, not a way to invert a range. Domain-to-IP resolves a name; it does not invert 10–20. After you have one host to inspect, IP lookup is a geo/ISP snapshot via a public API, not a CIDR calculator. Keep the jobs separate: summarize, then verify each block, then look a host up if you still need to.

Aligned ranges worth typing into the slider once: 192.168.1.0/24 fills .0–.255; 10.0.0.0/27 fills .0–.31; 10.0.0.0/23 fills 10.0.0.0–10.0.1.255. Those three are single prefixes because the start is aligned and the count is 2^(32−p). Everything else on this page is a list. Do not round the list up to a covering prefix that includes extra hosts.

Related Tools