CIDR to IP Range & Wildcard Mask Converter
Converts an IPv4 CIDR block to its first and last address, address count, usable hosts, netmask and wildcard mask, and converts a start and end address back into the fewest CIDR blocks. The first address is the input with its host bits cleared, and the block holds 2^(32 − prefix) addresses. A range is covered greedily: at each step it takes the largest aligned block that starts there without passing the end.
Type a CIDR block and the converter gives the range it covers, the first and last address, how many addresses it holds and how many a host can use, plus its netmask and the wildcard mask an access list wants. Switch to range mode and it works the other way: a start and end address become the fewest CIDR blocks that cover exactly that range, one row each, with each block's wildcard ready for a firewall or ACL rule. The default, 10.24.0.0/13, covers 10.24.0.0 to 10.31.255.255, which is 524,288 addresses.
The block field accepts a prefix length from /0 to /32, a dotted netmask such as 10.24.0.0 255.248.0.0, or a wildcard such as 10.24.0.0 0.7.255.255, with a slash or a space before the mask. To size subnets around one address with a fixed prefix, use the subnet calculator. To split one network into subnets sized by host counts, use the VLSM calculator.
How the conversion works
An IPv4 address is a 32-bit number. The prefix length n says how many of its leading bits name the network, and the other 32 − n bits number the hosts inside it, so a block always holds a power of two of addresses and always starts on a multiple of its own size.
size = 232 − n
first = address AND netmask, last = first + size − 1
netmask = 232 − size, wildcard = size − 1
The netmask has ones over the network bits and zeros over the host bits. The wildcard mask is its exact inverse, which is why each pair of octets sums to 255. Clearing the host bits of the address gives the first address, and setting them all gives the last. If the address you typed had host bits set, the CIDR line says the host bits were cleared, the way Python's ipaddress module behaves when its strict check is off. Usable hosts are the size minus 2 up to /30, both addresses of a /31 under RFC 3021, and the single address of a /32.
Python's documentation reads a dotted mask as a netmask when its first octet is not zero and as a wildcard when it is zero, and the converter does the same, with one addition. A wildcard for /1 to /7, from 127.255.255.255 down to 1.255.255.255, starts with a non-zero octet but cannot be a netmask, so the converter reads it as the wildcard it is: 10.0.0.0 1.255.255.255 gives 10.0.0.0/7. Either way the mask's ones must form a single unbroken run, because only a contiguous mask describes one block. 0.0.0.0 and 255.255.255.255 mean opposite things as netmask and wildcard, so for those two the converter asks for /0 or /32 instead of guessing.
Range mode starts at the first address and repeats one step until it passes the end. Each step takes the largest block that starts exactly at the current address, sits on its own boundary and stops at or before the end address. The result is the shortest list of CIDR blocks that covers the range with nothing extra. The documentation for Python's summarize_address_range gives 192.0.2.0 to 192.0.2.130 as its example, and this converter splits it the same way, into 192.0.2.0/25, 192.0.2.128/31 and 192.0.2.130/32.
A worked example: 10.24.0.0/13
The default comes from RFC 4632, the current CIDR specification, which uses 10.24.0.0/13 as its example of a block given to one provider. A /13 covers the first octet and 5 bits of the second. In binary the second octet of the netmask is 11111000, which is 248, so the netmask is 255.248.0.0. The 19 host bits give 219 = 524,288 addresses, the same as 2,048 /24s. The wildcard is 0.7.255.255, because 255 − 248 = 7.
24 in binary is 00011000, and its low three bits are already zero, so 10.24.0.0 is the first address with nothing to clear. Setting the 19 host bits turns the second octet into 24 + 7 = 31 and the last two octets into 255, so the last address is 10.31.255.255. Taking away the network and broadcast addresses leaves 524,286 usable hosts. Type 10.24.3.7/13 instead and you get the same block, marked "host bits cleared".
Switch to range mode and the defaults are 192.168.146.0 to 192.168.149.255, the example in Cisco's guide to IP access lists. That is 1,024 addresses, the size of one /22, but a /22 has to start on a third octet divisible by 4, and 146 is not. The largest block that can start at 192.168.146.0 is a /23, which ends at 192.168.147.255. The next step starts at 192.168.148.0, where a /23 exactly reaches the end. Both blocks have wildcard 0.0.1.255, the mask Cisco's own access-list lines use for this pair.
From classes to prefixes
When Jeffrey Mogul and Jon Postel set out subnetting in RFC 950 in August 1985, the subnet mask was simply a bitmask, and they noted that the subnet bits "need not be adjacent in the address". They recommended that the bits be contiguous and placed at the top of the local part anyway, and that recommendation is the mask this converter insists on.
By the early 1990s the fixed address classes had run into trouble. RFC 4632 recounts that the IETF formed the ROAD group in November 1991, and that it met in January 1992 and named three problems: Class B space was running out, routing tables were outgrowing routers, and the 32-bit space would eventually be exhausted. A Class C held at most 254 hosts, too few for a mid-sized organization, while a Class B allowed 65,534, too many for most. The group's work became RFC 1338 in June 1992 and then RFC 1519 in September 1993, by Vince Fuller, Tony Li, Jessica Yu and Kannan Varadhan.
RFC 1519 put numbers on the urgency. On 25 February 1992, 5,467 of 16,382 Class B numbers had been allocated, and with allocations doubling about once a year, "all class B's will be exhausted within about 15 months". By 13 January 1993 the count was 7,133, a slowdown the authors suggested was due to the plan's initial deployment. RFC 1519 wrote its routes as network and mask pairs, such as 192.24.0.0 with mask 255.248.0.0, and required that "the mask must be left contiguous".
The slash notation took over. RFC 4632, by Fuller and Li in August 2006, replaced RFC 1519 and defines a prefix as four octets, a "/" and a decimal from 0 to 32 counting the significant bits. It also notes that CIDR was meant to last three to five years and "has far outlasted its anticipated lifespan".
Wildcard masks, octets and edge cases
Wildcard masks are what router access lists use. Cisco's guide explains that a 0 bit in the wildcard means the address bit must match and a 1 bit means it can be ignored. So 192.168.146.0 0.0.1.255 matches the first /23 of the default range, and 10.1.1.2 0.0.0.0 matches one host. Applied bit by bit, a wildcard with scattered ones, such as 0.0.255.0, would match addresses that no single CIDR block can express, which is why this converter rejects one.
Octets are read as decimal, so 010 means ten. The C library is not so strict: the Linux manual for inet_aton says each part of a dotted address may be decimal, octal with a leading 0, or hexadecimal with a leading 0x, so the same text can mean 8 there. Python's ipaddress has refused leading zeros since version 3.9.5 to avoid that confusion. If an address must work across tools, write it without leading zeros.
The arithmetic covers all of IPv4, from 0.0.0.0/0, with 4,294,967,296 addresses, down to a single /32. It doesn't know what an address is used for, though the default sits inside 10.0.0.0/8, one of the three private ranges RFC 1918 set aside in February 1996. A range always covers in 62 blocks or fewer, and 62 is reached only by 0.0.0.1 to 255.255.255.254. IPv6 is out of scope.
Frequently asked questions
What IP range does 10.24.0.0/13 cover?
10.24.0.0 through 10.31.255.255. The /13 keeps the first 13 bits as the network and leaves 19 host bits, so the block holds 2 to the 19th, or 524,288 addresses, of which 524,286 are usable hosts. Its netmask is 255.248.0.0 and its wildcard mask is 0.7.255.255. RFC 4632 uses this block as its worked example of a provider allocation, the same size as 2,048 old Class C networks.
How do I convert an IP range to CIDR?
Start at the first address and take the largest block that begins there on its own boundary without running past the end address, then repeat from the address after it. 192.168.146.0 to 192.168.149.255 is 1,024 addresses but not one block, because a /22 must start on a third octet divisible by 4. It splits into 192.168.146.0/23 and 192.168.148.0/23. The worst case, 0.0.0.1 to 255.255.255.254, needs 62 blocks.
What is a wildcard mask?
The bitwise inverse of the netmask, so each pair of octets adds up to 255. Cisco access lists use it: a 0 bit means the address bit must match and a 1 bit means it is ignored. A /23 has netmask 255.255.254.0 and wildcard 0.0.1.255, so the access-list entry 192.168.146.0 0.0.1.255 matches 192.168.146.0 through 192.168.147.255. A wildcard with ones scattered between zeros can match addresses that no single CIDR block covers.
What happens if I enter an address with host bits set, like 10.24.3.7/13?
The converter clears the host bits and says so, reading 10.24.3.7/13 as 10.24.0.0/13 (host bits cleared), with the same range as the default. Python's ipaddress module does the same when strict is off, and raises an error when it is on. The address inside the block does not change the block, only which host in it you meant.
How many usable hosts does a /31 or /32 have?
A /31 has 2, and a /32 has 1. Every block up to /30 loses its first address, the network, and its last, the broadcast, so a /30 keeps 2 of its 4 addresses. RFC 3021 lets a /31 on a point-to-point link use both of its addresses as hosts, since a point-to-point link has only two ends and no notion of broadcast. A /32 is a single address, the form a host route takes.
Sources
- RFC 4632: Classless Inter-domain Routing (CIDR): The Internet Address Assignment and Aggregation Plan, IETF, 2006
- RFC 1519: Classless Inter-Domain Routing (CIDR): an Address Assignment and Aggregation Strategy, IETF, 1993
- RFC 950: Internet Standard Subnetting Procedure, IETF, 1985
- RFC 3021: Using 31-Bit Prefixes on IPv4 Point-to-Point Links, IETF, 2000
- RFC 1918: Address Allocation for Private Internets, IETF, 1996
- Configure and Filter IP Access Lists, Cisco, 2025
- ipaddress: IPv4/IPv6 manipulation library, Python Software Foundation
- inet(3): Internet address manipulation routines, Linux man-pages project