CIDR to IP Range: Calculate First and Last IP by Hand

CIDR to IP Range: Calculate First and Last IP by Hand

CIDR to IP range is mask arithmetic. A prefix such as 192.168.1.0/24 means “the first 24 bits are the network.” FlashKit’s CIDR to IP range calculator does that for IPv4 in this tab. It does not implement IPv6 prefixes. Examples below were checked with Python ipaddress and with the widget’s own 32-bit AND/OR math.

RFC 4632 restates CIDR. Host count is 2^(32−prefix). Classic usable hosts subtract the network and broadcast addresses.

Worked /24, /27 and /30

/24 — host bits 8, total 256, mask 255.255.255.0. Input 192.168.1.1/24 (the widget default):

  • Network 192.168.1.0
  • First usable 192.168.1.1
  • Last usable 192.168.1.254
  • Broadcast 192.168.1.255
  • Usable hosts 254 (256 − 2)

/27 — host bits 5, total 32, mask 255.255.255.224. Input 10.0.0.16/27 networks to 10.0.0.0 because 16 AND 224 = 0 in the last octet. Range 10.0.0.0–10.0.0.31, usable 10.0.0.1–10.0.0.30 (30 hosts).

/30 — host bits 2, total 4, mask 255.255.255.252. 192.0.2.1/30 (TEST-NET-1, RFC 5737) → network 192.0.2.0, usable 192.0.2.1–192.0.2.2, broadcast 192.0.2.3, usable hosts 2. Common on point-to-point links that still use a broadcast pair.

Check the cards against the hand math

IPv4 only. Slider /0–/32. Usable = total − 2, or 0 for /31 and /32.

Open the CIDR calculator

/31 (RFC 3021) and /32, as the tool actually behaves

RFC 3021 uses both addresses on a /31 as hosts (no broadcast pair). Python ipaddress lists 192.0.2.4 and 192.0.2.5 as hosts for 192.0.2.4/31. FlashKit does not implement that: usable hosts is total − 2 when that value is positive, else 0. On /31 and /32 the usable-hosts card is 0. On /32, first/last cards are network+1 and broadcast−1, which wrap on 32-bit arithmetic — trust the network and broadcast rows, not a “usable range,” for a single host.

IPv6 is out of scope here. Notation-only mapped IPv6 is the IPv4 to IPv6 converter. The inverse problem (a range that does not line up with one prefix) is IP range to CIDR. Prefix vocabulary: CIDR notation explained.

Need the mapped IPv6 spelling instead?

::ffff: plus hex. Not a prefix assignment.

Open IPv4 to IPv6

Hand method, one more time, with 192.168.1.1/24

Prefix 24. Host bits = 32 − 24 = 8. Total = 2^8 = 256. Mask bits: 24 ones, then 8 zeros → 255.255.255.0. The address 192.168.1.1 as four octets AND 255.255.255.0 is 192.168.1.0 (the last octet 1 AND 0 is 0). Inverse mask 0.0.0.255. Network OR inverse mask = 192.168.1.255 (broadcast). First usable 192.168.1.1, last usable 192.168.1.254, usable 254. That is the widget default. Dragging the slider to /16 on the same address yields network 192.168.0.0, mask 255.255.0.0, total 65,536, usable 65,534.

10.0.0.16/27: last octet 16, mask 224. 16 AND 224 = 0, so the network is 10.0.0.0, not 10.0.0.16. People paste a host address and expect the range to start at that host; CIDR starts at the network number. The calculator will show First IP 10.0.0.1 even though you typed .16. That is correct classic IPv4, not a bug.

Python check for the /24 (num_addresses, network, broadcast): ipaddress.ip_network("192.168.1.1/24", strict=False) → 192.168.1.0/24, 256 addresses, broadcast 192.168.1.255. strict=False is required when the host bits are not already zero; 192.168.1.1/24 is a host in that network, not the network number itself. FlashKit’s slider always treats the typed address as a host inside the prefix you picked.

IPv6 searches, /31, and honesty about the URL

People search “ipv6 cidr calculator”. This URL contains ipv4-ipv6. The parser is dotted IPv4 only. Pasting 2001:db8::/32 does not compute a /32 of IPv6; the previous IPv4 cards stay. /64 SLAAC math (2^64 addresses) belongs in a dedicated IPv6 tool or in ipaddress, not on this slider. Mapped notation (::ffff: plus the same 32 bits) is a spelling, not a prefix assignment — use the IPv4-to-IPv6 converter for that spelling.

/31: RFC 3021 uses both addresses. FlashKit usable-hosts = 0. /32: a single address; usable-hosts = 0. If you are documenting a point-to-point /31, write the two addresses from RFC 3021 by hand and do not trust the usable-hosts card. The network and broadcast rows still show the two addresses of that /31.

CIDR (RFC 4632) replaced classful masks. A “class C” habit of always subtracting 2 is what the widget implements. Cloud providers may reserve extra addresses inside a VPC subnet (AWS documents five reserved in IPv4). The widget does not know about AWS reservations. Copy the range into a ticket, then confirm in the console before you open a security group.

Prefix length table you can check on the slider

Host bits = 32 − prefix. Total = 2^(host bits). Classic usable = total − 2 when that is positive, else 0 on this widget:

  • /8 — host bits 24, total 16,777,216, mask 255.0.0.0, usable 16,777,214
  • /16 — host bits 16, total 65,536, mask 255.255.0.0, usable 65,534
  • /24 — host bits 8, total 256, mask 255.255.255.0, usable 254
  • /25 — host bits 7, total 128, mask 255.255.255.128, usable 126
  • /26 — host bits 6, total 64, mask 255.255.255.192, usable 62
  • /27 — host bits 5, total 32, mask 255.255.255.224, usable 30
  • /28 — host bits 4, total 16, mask 255.255.255.240, usable 14
  • /29 — host bits 3, total 8, mask 255.255.255.248, usable 6
  • /30 — host bits 2, total 4, mask 255.255.255.252, usable 2
  • /31 — host bits 1, total 2, mask 255.255.255.254, widget usable 0 (RFC 3021: 2)
  • /32 — host bits 0, total 1, mask 255.255.255.255, widget usable 0

Those totals are powers of two, not measurements from a production VPC. Drag the FlashKit slider to each prefix on 192.168.1.1 and read Network, Broadcast, and Usable hosts. /16 on that address is network 192.168.0.0, broadcast 192.168.255.255. /25 mask last octet is 128: 192.168.1.1 AND 128 in the last octet is 0, so network 192.168.1.0, broadcast 192.168.1.127, usable 126. /25 on 192.168.1.200 networks to 192.168.1.128 (200 AND 128 = 128), broadcast 192.168.1.255.

The inverse problem — two endpoints that do not fill one prefix — is the IP-range-to-CIDR guide. Vocabulary without the hand arithmetic is the CIDR notation explainer. Mapped IPv6 spelling of one host is the IPv4-to-IPv6 converter. None of those pages take a colon-hex IPv6 prefix on this slider.

Worked AND for 10.0.0.16/27 one more time, last octet only: address 16, mask 224, because /27 means 27 ones (the last octet has 3 ones: 128+64+32 = 224). 16 in binary is 00010000. 224 is 11100000. AND is 00000000, so the last octet of the network is 0, not 16. Inverse mask of that octet is 31 (00011111). 0 OR 31 = 31, broadcast 10.0.0.31. Usable 10.0.0.1–10.0.0.30. Python ipaddress.ip_network("10.0.0.16/27", strict=False) agrees: network 10.0.0.0/27, 32 addresses. FlashKit’s First IP card is 10.0.0.1 even though you typed .16, because .16 is a host inside that network, not the start of a new one.

/30 on 192.0.2.1 (TEST-NET-1): mask 255.255.255.252, last octet 1 AND 252 = 0, network 192.0.2.0, broadcast 192.0.2.3, usable two hosts 192.0.2.1 and 192.0.2.2. That is the classic point-to-point pair with a broadcast. /31 on the next two addresses (192.0.2.4/31) is where FlashKit and RFC 3021 disagree on the usable-hosts card: the RFC uses both, the widget shows 0. Write the two addresses from the network and broadcast rows if you are documenting a /31 link. Python lists 192.0.2.4 and 192.0.2.5 as hosts for that /31; FlashKit still subtracts 2 and displays 0 usable.

Related Tools