Home/Computer Science/Networking/Subnet Hosts from CIDR Prefix

Formula & Calculator

Subnet Hosts from CIDR Prefix

Calculates the number of usable host addresses in an IPv4 subnet given its CIDR prefix length, excluding network and broadcast addresses.

Computer ScienceNetworkingIP Addressing

Usable Hosts from CIDR CalculatorHosts = 232‑prefix − 2

Usable Hosts = 232‑prefix − 2
prefix = CIDR prefix (/0–/32)  ·  excludes network & broadcast
⟹ Hostsprefix, hosts
/
Solve for:
Common prefixes:
Result
Subnet Mask:
Total Addresses:
✓ Copied!
Subnet Size
Small (<10 hosts) Medium (10–100) Large (100–1000) Very Large (1000–10000) Huge (>10000)
Hosts vs. Prefixexponential decay
Hosts(prefix) Computed point
Usable Hosts = 232‑prefix − 2  ·  excludes network and broadcast addresses

Variables

SymbolQuantityUnit
Usable HostsNumber of usable host addresses
prefixCIDR prefix length (e.g. /24)

What it means

CIDR (Classless Inter‑Domain Routing) notation specifies the number of bits in the network mask, e.g., /24 means the first 24 bits are the network part, leaving 8 bits for host addresses. The total number of IP addresses in the subnet is 2^(32−prefix). However, two addresses are reserved: the all‑zero address (network identifier) and the all‑ones address (broadcast). Therefore, the number of usable hosts is 2^(32−prefix) − 2. This is a fundamental calculation for network design, IP address allocation, and subnet planning. For example, a /24 subnet provides 254 usable IPs, which is common for small to medium LANs. For /30, there are 2 usable hosts (commonly used for point‑to‑point links). Understanding this formula helps in avoiding address exhaustion and ensuring efficient use of address space. It is also applied in IPv6, where the formula becomes 2^(128−prefix) − 2, though with a huge address space, the subtract‑2 is negligible. This concept is essential for network engineers and IT administrators.

Worked example

Subnet Hosts from CIDR – Two Examples

Real‑World
Scenario 1 – Office Network: You are assigned a /24 subnet (192.168.1.0/24). How many usable IP addresses can you assign to devices?
ParameterValue
Prefix/24
Total addresses2^(32−24) = 2⁸ = 256
Usable hosts256 − 2 = 254
1Subtract network address and broadcast address.
2254 usable addresses for hosts.
Result 254 usable hosts ✓ Standard /24 subnet
Scenario 2 – Point‑to‑Point Link: You need a subnet for just two routers. What prefix provides the fewest wasted addresses?
ParameterValue
Prefix/30
Total addresses2^(32−30) = 2² = 4
Usable hosts4 − 2 = 2
1/30 gives exactly 2 usable addresses – perfect for point‑to‑point.
2No wasted addresses.
Result 2 usable hosts ✓ Minimal waste
Key insight: Always subtract 2 for network and broadcast addresses – choose the smallest subnet that fits your needs to conserve IP space.

Common mistakes

  • Subtract 2: Always subtract 2 for network and broadcast addresses – forgetting this is a common error.
  • Prefix length: The prefix is the number of network bits (e.g., /24), not the number of host bits.
  • Zero subnet: Some networks reserve the all‑zeros subnet; however, in modern CIDR, that subnet is usable.
  • Subnet zero: Some legacy configurations may not allow the all‑zeros subnet; check your network policy.
  • Integer exponent: 2^(32−prefix) can be large; use 64‑bit integers to avoid overflow for small prefix lengths.

Applications

The CIDR prefix notation (e.g., /24) determines the number of usable host addresses in a subnet: 2^(32−prefix) − 2, subtracting the network and broadcast addresses. This calculation is fundamental to IP network design, addressing, and routing. Engineers use it to plan subnet sizes, allocate IP address ranges, and configure network devices such as routers and firewalls. In cloud computing, it is used to define VPCs (Virtual Private Clouds) and to ensure efficient utilisation of IPv4 addresses. Understanding this formula is critical for avoiding address exhaustion, for summarising routes, and for designing scalable and manageable networks. It is also essential for troubleshooting connectivity issues and for implementing security policies based on IP ranges.

  • IP subnet planning and allocation
  • Design of enterprise and cloud networks
  • Configuration of routing and access control lists
  • IPv4 address conservation strategies
  • Network troubleshooting and diagnostics