Convert Hosts to CIDR
How to convert Hosts to CIDR
Calculating the right CIDR prefix for your host count adds 2 to account for the network and broadcast addresses, then finds the smallest power of 2 that covers the result. The prefix is 32 minus the number of host bits required.1
Common Hosts to CIDR conversions
Why host count math is fixed
IPv4 address space is binary, so every subnet boundary falls on a power of 2. Designing around this constraint means you cannot create a subnet for exactly 50 hosts without wasting some space. The smallest prefix covering 50 hosts is /26, which provides 2^6 − 2 = 62 usable addresses.1 Building on this, the formula h → 32 − ⌈log₂(h + 2)⌉ derives the minimum prefix length needed. Adding 2 to the host count before taking the ceiling accounts for the reserved network and broadcast addresses, and this step is the most common source of off-by-two errors in manual subnet planning. Consequently, the result is always the most compact subnet that holds all requested hosts without cutting off any addresses.
How IPv4 and IPv6 handle host ranges differently
In IPv4, two addresses per subnet are unavailable: the network address (all host bits zero) and the broadcast address (all host bits one).2 A /24 provides 256 total addresses but only 254 usable. Furthermore, AWS and Azure reserve 5 addresses per subnet (not 2), so cloud deployments require adding 5 to the host count before applying the formula: h + 5 rather than h + 2.3 IPv6 has no broadcast mechanism, so every address in a /64 is usable,4 but the standard practice of using /64 for all segments means the hosts-to-prefix formula is rarely applied to IPv6. Conversely, on-premises networks follow the standard RFC math.
Practical subnet planning to avoid address exhaustion
Address exhaustion in a cloud subnet requires either migrating all workloads to a larger subnet or adding a secondary CIDR block, and both operations are disruptive. Planning 20 to 30 percent headroom into initial subnet sizing avoids this. For a team expecting to grow from 40 to 60 instances over 18 months, the 40-instance plan would choose /26 (62 usable, 57 after AWS reservations), which exhausts at 57 instances. Adding 30% headroom and choosing /25 (126 usable, 121 after reservations) accommodates 60 instances with room to spare. Use this formula to find the right prefix, then check the usable count against your cloud provider's reservations before committing.
Cloud provider reservation patterns and their impact on sizing
AWS, Azure, and GCP each modify the standard hosts-to-CIDR formula. AWS reserves 5 addresses per subnet: .0 for network, .1 for VPC router, .2 for Route 53 DNS resolver, .3 for future use, and the last address for broadcast. Azure follows the identical reservation pattern. GCP reserves 4 addresses per subnet: the first two and the last two.5 Building on this, for a workload needing 50 hosts, the standard math says /26 (62 usable), but on AWS the /26 provides only 57 usable addresses after the 5-reservation deduction. That 5-address gap pushes you to /25 (123 usable on AWS) to maintain comfortable headroom.
When cloud reservations change your prefix selection
Always account for provider reservations before selecting a prefix. A /28 provides 14 usable hosts under standard math but only 9 after AWS or Azure reserves 5. GCP gives 10 usable from a /28. Subnets smaller than /27 are especially risky in cloud environments: a /28 in AWS with only 9 usable addresses can exhaust after a handful of deploys if your autoscaling group grows. The calculator applies the correct reservation count for each cloud provider's defaults.
GCP also enforces a hard floor on subnet size: the minimum primary range is /29 (8 total addresses, 4 usable after GCP's reservations), so the hosts-to-CIDR formula cannot return anything longer than /29 for a Google Cloud primary range even if the requested host count is small enough to fit in a /30 or smaller under standard math. Secondary ranges are the exception, since GCP does not reserve any addresses within them, so a small secondary range yields more usable addresses than the same-sized primary range.
Reverse-engineering subnet sizes from existing infrastructure
Auditing an existing network often means determining what prefix was used given only the number of active hosts. A subnet with 120 active hosts most likely uses a /25 (126 usable): anything smaller would be full, and anything larger wastes address space. When performing a network migration from on-premises to cloud, reverse-engineer each existing subnet's size first, then add the cloud provider's reservation offset before selecting the target CIDR.
Converting flat network scans to CIDR allocations
Network discovery tools like Nmap return lists of active IP addresses. Grouping these into contiguous CIDR blocks simplifies firewall rule creation and documentation. An algorithm that sorts active IPs, identifies contiguous ranges, and outputs the smallest covering CIDR blocks transforms a raw scan into an address plan. Python's ipaddress.summarize_address_range() performs this grouping automatically, and CapyToolkit generates the same groupings interactively for any range of addresses.
Supernetting and route summarization with CIDR arithmetic
Route summarization reduces the number of entries in routing tables by combining adjacent CIDR blocks into a single covering prefix.6 Four contiguous /24s (for example 10.0.0.0/24 through 10.0.3.0/24) summarize to 10.0.0.0/22. Building on this, BGP route advertisements use summarization to keep global routing tables manageable: an ISP that allocates contiguous /20s to customers can advertise those /20s directly rather than listing every constituent /24. Variable-length summarization (not limited to power-of-2 block counts) follows the same bitwise logic: find the longest common prefix bits across all blocks, and that prefix length is your summary route.
When summarization causes blackhole routes
Over-aggressive summarization creates blackhole routes. If 10.0.0.0/22 is advertised as a single route but only 10.0.0.0/24 and 10.0.1.0/24 are actually in use, traffic destined for 10.0.2.x and 10.0.3.x gets forwarded to a destination that drops it. Documenting which addresses inside a summarized block are reachable versus allocated-but-empty prevents this failure mode. Static null routes for the empty subnets, pointing to a discard interface, ensure unreachable traffic is dropped cleanly rather than looping.
Try in the tool
Conversion covered by this page
254 Hosts converts to 24 CIDR using the formula on this page. Use this figure as a reference point alongside the tool below.
Verify with the IPv4 / IPv6 Subnet & CIDR Calculator tool.
Try it in the tool ↑- 1.
V. Fuller and T. Li, "The CIDR Address Strategy," RFC 4632, IETF, September 2006. https://datatracker.ietf.org/doc/html/rfc4632
- 2.
J. Mogul and J. Postel, "Internet Standard Subnetting Procedure," RFC 950, IETF, August 1985. https://www.rfc-editor.org/rfc/rfc950.html
- 3.
Amazon Web Services, "Subnet CIDR blocks," docs.aws.amazon.com, accessed June 2026. https://docs.aws.amazon.com/vpc/latest/userguide/subnet-sizing.html
- 4.
R. Hinden and S. Deering, "IP Version 6 Addressing Architecture," RFC 4291, IETF, February 2006. https://datatracker.ietf.org/doc/html/rfc4291
- 5.
Google Cloud, "VPC Subnets," docs.cloud.google.com, accessed June 2026. https://docs.cloud.google.com/vpc/docs/subnets
- 6.
Cisco, "Understand Route Aggregation in BGP," cisco.com, accessed June 2026. https://www.cisco.com/c/en/us/support/docs/ip/border-gateway-protocol-bgp/5441-aggregation.html
254 usable hosts in a standard IPv4 /24. CapyToolkit applies the correct reservation count for whichever provider you select, so the usable-host figure updates automatically. AWS and Azure reserve 5 addresses per subnet, reducing the usable count to 251 per /24 in cloud environments.
/25 provides 126 usable hosts (128 total minus 2 reserved). In AWS, a /25 provides 123 usable hosts after the 5 AWS-reserved addresses. /26 (62 usable) is too small for 100 hosts.
Two addresses are reserved in every IPv4 subnet: the network address (all host bits 0) and the broadcast address (all host bits 1). Adding 2 ensures the selected prefix can hold both the required hosts and these two reserved addresses.
In theory yes, but IPv6 subnets are always /64 by convention because SLAAC requires the 64-bit interface ID. The formula is useful only in the rare case where you are assigning an IPv6 prefix smaller than /64, which breaks SLAAC.
/30 is the smallest standard subnet for two host addresses, and it provides exactly 2 usable addresses (4 total, minus network and broadcast). RFC 3021 defines /31 for point-to-point links where both addresses are usable and no broadcast is needed. CapyToolkit lets you toggle the reserved-address offset between 2 and 5, so you can see at a glance whether a /30 meets your needs on-premises versus in a cloud VPC.
Convert CIDR to host count
How to convert CIDR to host count
Calculating the usable host count from a CIDR prefix raises 2 to the power of the host bits (32 minus the prefix length), then subtracts 2 for the network and broadcast addresses.1
Common CIDR to host count conversions
Why host count math is fixed
IPv4 subnet sizes are powers of 2 by definition. A prefix of /n reserves n bits for the network, leaving 32 − n bits for hosts. The total address count is 2^(32−n). Subtracting 2 for the reserved network and broadcast addresses gives the usable host count. Building on this, the formula is exact and not an approximation. A /26 always has 2^6 = 64 total addresses and 62 usable hosts,1 regardless of the starting address. Consequently, you can look up any prefix in the table and get the precise count for firewall rules, DHCP pool sizes, and cloud subnet configuration without mental arithmetic.
How IPv4 and IPv6 handle host ranges differently
IPv4 subtracts 2 from the address count: one for the network address, one for the broadcast. IPv6 has no broadcast address, so all 2^(128−n) addresses in a subnet are theoretically usable,2 but standard /64 segments contain 2^64 addresses, a number so large that no existing tool can enumerate it in practice.
How cloud providers override the standard formula
Cloud providers override the standard math further: AWS and Azure each reserve 5 addresses per subnet.3 A /24 in AWS provides 256 − 5 = 251 usable addresses rather than the standard 254. Furthermore, the formula applies only to IPv4 when accounting for cloud reservations; subtract 5 instead of 2 when planning VPC subnets in either provider. This adjustment matters most in small subnets, where the 3-address difference between standard and cloud math can push you to the next larger prefix.
Practical subnet planning to avoid address exhaustion
A /28 (14 usable hosts) fits most specialty subnets, such as database servers, load balancers, and VPN endpoints, without wasting addresses. Yet a /28 in AWS provides only 11 addresses after the 5 AWS-reserved ones. If you're placing more than 8 instances, a /27 (27 usable in AWS) is safer. For production application subnets expected to scale, a /24 (251 usable in AWS) provides room to run hundreds of microservices without a subnet migration. Building on this, EKS pod CIDRs need much larger blocks because a /22 provides 1,019 usable addresses per node subnet in VPC CNI mode,4 supporting several large compute nodes without running out of pod IPs.
Working with /31 and /32 edge cases
The standard formula 2^(32−n) − 2 breaks at two prefix lengths. A /32 identifies exactly one host address: the network and broadcast addresses are the same address, so subtracting 2 would give −1, which is meaningless. A /31 provides two addresses with no network or broadcast distinction : RFC 3021 explicitly allows both addresses for point-to-point links.5 Building on this, routers from Cisco, Juniper, and Linux all support /31 links for WAN connections, saving addresses when every /30 wastes 50% of its space to broadcast reservations. For loopback interfaces on Cisco IOS, use /32 to represent a single router ID without advertising a broader network in OSPF or BGP.
Planning host counts for Kubernetes and container runtimes
Container runtimes consume IP addresses faster than traditional VM workloads. Docker assigns one IP per container on the default bridge network, so a /24 bridge subnet exhausts after roughly 250 containers. Kubernetes with VPC CNI (used in EKS and GKE) assigns one VPC IP per pod, meaning a node with 110 pod capacity needs at least 110 IPs plus the node address. A /24 in AWS provides 251 usable addresses after the provider's 5 reservations, which accommodates two nodes at full density : but leaves no room for system pods or daemon sets.
Pre-allocating CIDRs for cluster growth
Before provisioning an EKS node group, calculate the maximum node count multiplied by per-node pod density to determine the minimum subnet size. For 20 nodes at 110 pods each, 2,200 pod IPs plus 20 node IPs require a /21 (2,046 usable in AWS). Using a /22 (1,019 usable) forces a subnet split across multiple Availability Zones, which complicates the Terraform module that manages node group placement. CapyToolkit's subnet calculator confirms each candidate CIDR's usable count before you commit it to your infrastructure-as-code configuration.
Host count arithmetic in network verification scripts
Automated verification scripts that assert expected host counts catch misconfigured subnets before they reach production. A script that reads every CIDR from a Terraform plan output and validates that the usable count exceeds the declared instance count prevents deployment failures in autoscaling groups. Python's ipaddress module makes this trivial: IPv4Network('10.0.0.0/22').num_addresses returns 1024,6 and subtracting 2 (or 5 for cloud) gives the usable count. Building on this, tying the check to a CI pipeline gate means any subnet change that reduces available addresses below a threshold triggers a pull request comment in GitHub or GitLab.
Storing prefix-to-count mappings in application config
Hardcoding host count lookups in application configuration avoids repeated runtime calculation. A JSON map from prefix length to usable host count : for example {"/24": 254, "/25": 126, "/26": 62, "/27": 30, "/28": 14, "/29": 6, "/30": 2} : serves as a fast reference for validation logic. Include a cloud-specific variant that subtracts 5 instead of 2. The calculator generates these mappings on demand, so you can export the exact reference table your application needs for its target deployment environment.
Python's ipaddress module offers an alternative to a static lookup table: calling len(list(IPv4Network('10.0.0.0/24').hosts())) or subtracting from num_addresses returns the usable count directly, and hosts() already applies the /31 exception automatically, including both addresses instead of returning zero. For cloud-adjusted counts, subtracting the provider's reservation from num_addresses avoids maintaining two separate tables for standard and cloud math.
Try in the tool
Conversion covered by this page
24 CIDR converts to 254 host count using the formula on this page. Use this figure as a reference point alongside the tool below.
Verify with the IPv4 / IPv6 Subnet & CIDR Calculator tool.
Try it in the tool ↑- 1.
V. Fuller and T. Li, "The CIDR Address Strategy," RFC 4632, IETF, September 2006. https://datatracker.ietf.org/doc/html/rfc4632
- 2.
R. Hinden and S. Deering, "IP Version 6 Addressing Architecture," RFC 4291, IETF, February 2006. https://datatracker.ietf.org/doc/html/rfc4291
- 3.
Amazon Web Services, "Subnet CIDR blocks," docs.aws.amazon.com, accessed June 2026. https://docs.aws.amazon.com/vpc/latest/userguide/subnet-sizing.html
- 4.
Amazon Web Services, "Custom Networking for Amazon EKS," docs.aws.amazon.com, accessed June 2026. https://docs.aws.amazon.com/eks/latest/best-practices/customNetworking.html
- 5.
B. Carpenter and K. Nichols, "Using 31-Bit Prefixes on IPv4 Point-to-Point Links," RFC 3021, IETF, December 2000. https://www.rfc-editor.org/rfc/rfc3021.html
- 6.
Python Software Foundation, "ipaddress — IPv4/IPv6 manipulation library," docs.python.org, accessed June 2026. https://docs.python.org/3/library/ipaddress.html
14 usable hosts in a standard /28. In AWS or Azure, only 11 are usable after the provider reserves 5 addresses. Use /27 (30 standard, 27 AWS/Azure) if you need more than 10 hosts.
2^(32 − prefix) − 2. For a /27: 2^5 − 2 = 30 usable hosts. For a /24: 2^8 − 2 = 254 usable hosts. In cloud environments, subtract 5 instead of 2 to account for provider-reserved addresses.
No. RFC 3021 defines /31 subnets for point-to-point links where both addresses are usable even though the formula gives 2^1 − 2 = 0, because RFC 3021 overrides the standard math. Many network devices support /31 links. /32 is a host route with exactly 1 address. CapyToolkit flags /31 and /32 as edge cases and shows the correct usable count for each, so you do not have to memorize the exceptions.
1022 usable hosts in a standard /22 (2^10 = 1024 total, minus 2). In AWS or Azure, 1019 usable addresses. Commonly used for large VPC subnets that host many EC2 instances or EKS pods.
No in standard IPv4, because counts are always even: 2, 6, 14, 30, 62, 126, 254 (each is 2^n − 2). Cloud providers subtract 5 instead of 2, giving counts like 3, 11, 27, 59, 123, 251, and these can be odd. CapyToolkit shows both the standard and cloud-adjusted counts side by side, so you can see exactly how the reservation offset changes the usable total.