Skip to content

Subnet Calculator

Hosts, mask and ranges for a CIDR block.

Reviewed by the Calculation Machine team · Updated 24 October 2026 · How we check our maths

Your values

ⓘ Live results

Results
Usable hosts
254
Subnet mask
255.255.255.0
Total addresses
256
Prefix for hosts needed
/24

Quick answer

A subnet's size is set by its CIDR prefix: the block holds 2^(32 − prefix) IPv4 addresses, and you subtract 2 (the network and broadcast addresses) to get usable hosts. A /24 has the mask 255.255.255.0, 256 addresses and 254 usable hosts; a /27 has the mask 255.255.255.224 and 30 usable hosts.

What the Subnet calculator does

This calculator converts an IPv4 CIDR prefix (the number after the slash, such as /24) into its dotted-decimal subnet mask, the total number of addresses in the block and how many of those you can assign to devices. Enter how many hosts you need and it also tells you the longest prefix — the smallest subnet — that still fits them.

Network engineers use it when carving a VLAN or VPC address space into subnets, sizing a DHCP scope, or reading a firewall rule written in CIDR notation. Each step of one in the prefix halves the block, so picking the wrong prefix either wastes addresses or leaves no room for growth.

The tool covers IPv4 only. Masks are just binary numbers written in four 8-bit groups, so a binary converter or base converter helps if you want to see exactly which bits are network bits.

The formula

Total addresses = 2^(32 − p) Usable hosts = 2^(32 − p) − 2 Prefix for N hosts = 32 − ⌈log₂(N + 2)⌉

Formula variables
SymbolMeaningUnit
pCIDR prefix length: the number of leading 1 bits in the subnet maskbits (0–32)
32Length of an IPv4 addressbits
2Addresses reserved in every subnet: the network address (all host bits 0) and the broadcast address (all host bits 1)addresses
NNumber of devices that need an address, including routers and gatewayshosts

CIDR notation is defined in IETF RFC 4632. The −2 rule applies to ordinary subnets from /0 to /30. Two prefixes are exceptions: a /31 has two addresses that RFC 3021 allows both to be used on point-to-point router links, and a /32 identifies a single host (common in routes and firewall rules). This calculator reports 0 usable hosts for both, which is correct for normal LAN use.

This page also replaces the former IP range, IP address count and subnet CIDR calculators: the section below shows how to get the first and last address of any block from its size.

Worked examples

Office LAN with 200 devices

A small office expects about 200 laptops, phones and printers on one VLAN and wants to check a /24.

Inputs

  • CIDR prefix24
  • Hosts needed200

Result

  • Usable hosts254
  • Subnet mask255.255.255.0
  • Total addresses256
  • Prefix for hosts needed/24

A /24 gives 254 usable addresses, so 200 devices fit with about 50 to spare. If the office might pass 254 devices, plan a /23 (510 usable) now rather than renumbering later.

Small subnet for 25 cameras

A security team isolates 25 IP cameras plus a recorder on their own subnet and wants the tightest fit.

Inputs

  • CIDR prefix27
  • Hosts needed25

Result

  • Usable hosts30
  • Subnet mask255.255.255.224
  • Total addresses32
  • Prefix for hosts needed/27

A /27 (mask 255.255.255.224) holds 32 addresses, 30 usable, which covers 25 cameras, the recorder and a gateway. A /28 would only give 14 usable hosts.

Large campus or cloud subnet

A cloud architect needs room for 3,000 container or VM addresses in one subnet.

Inputs

  • CIDR prefix20
  • Hosts needed3000

Result

  • Usable hosts4,094
  • Subnet mask255.255.240.0
  • Total addresses4,096
  • Prefix for hosts needed/20

A /20 (255.255.240.0) gives 4,094 usable hosts. Note that cloud providers reserve a few extra addresses per subnet on top of the network and broadcast, so leave a margin.

CIDR prefix to subnet mask cheat sheet

Each extra prefix bit halves the block. Within the last octet, the mask value is always 256 minus the block size: a 64-address block has a last octet of 256 − 64 = 192.

Common IPv4 prefixes
PrefixSubnet maskTotal addressesUsable hosts
/8255.0.0.016,777,21616,777,214
/16255.255.0.065,53665,534
/20255.255.240.04,0964,094
/23255.255.254.0512510
/24255.255.255.0256254
/25255.255.255.128128126
/26255.255.255.1926462
/27255.255.255.2243230
/28255.255.255.2401614
/30255.255.255.25242

Finding the IP range of a subnet

Subnets always start on a multiple of their block size, which makes the address range easy to work out by hand:

  • Block size = total addresses from the calculator (for a /26, 64).
  • Network address: round the relevant octet of the IP down to a multiple of the block size. For 192.168.10.77/26, 77 rounds down to 64, so the network is 192.168.10.64.
  • Broadcast address: network + block size − 1, here 192.168.10.127.
  • Usable range: everything in between, 192.168.10.65 to 192.168.10.126 (62 hosts).

For prefixes shorter than /24 do the same in the third octet: 10.20.37.5/20 has a block of 16 in the third octet, so the range runs from 10.20.32.0 to 10.20.47.255.

Private address ranges and how they split

RFC 1918 sets aside three blocks for private networks: 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. Home routers usually hand out a /24 from 192.168.x.x, while companies and cloud VPCs typically carve subnets out of 10.0.0.0/8.

To split a block, borrow bits: a /24 divides into two /25s, four /26s or eight /27s. A larger parent block holds 2^(child − parent) subnets — a /16 contains 256 separate /24s.

How to use the Subnet Calculator

  1. 1Enter the CIDR prefix length without the slash — 24 for a /24. If you only have a dotted mask, count its 1 bits (255.255.255.0 is 24).
  2. 2Enter the number of devices that need an address, including the router or gateway.
  3. 3Read the subnet mask, total addresses and usable hosts for the prefix you entered.
  4. 4Compare with the suggested prefix for your host count; if it is shorter than yours, your subnet is too small.

Frequently asked questions

How many usable IP addresses are in a /24?

A /24 has 256 addresses, of which 254 are usable. The first (.0) is the network address and the last (.255) is the broadcast address.

What subnet mask is /28?

A /28 is 255.255.255.240. It holds 16 addresses with 14 usable hosts, a common size for small server or ISP static-IP blocks.

Why do you subtract 2 from the number of addresses?

The address with all host bits set to 0 names the network itself, and the one with all host bits set to 1 is the broadcast address. Neither can be assigned to a device on a normal subnet.

What is the difference between a subnet mask and a CIDR prefix?

They describe the same thing. The prefix counts the network bits (/24) and the mask writes those bits out in dotted decimal (255.255.255.0).

How do I find how many /24 subnets fit in a /16?

Raise 2 to the difference in prefix lengths: 2^(24 − 16) = 256 subnets. The same rule gives four /26s inside a /24.

Does this work for IPv6?

No, it uses 32-bit IPv4 addresses. IPv6 uses 128-bit addresses and standard LAN subnets are /64, which is so large that host counting is rarely a concern.

References

  • RFC 4632: Classless Inter-domain Routing (CIDR) — Internet Engineering Task Force (IETF)
  • RFC 1918: Address Allocation for Private Internets — Internet Engineering Task Force (IETF)
  • RFC 3021: Using 31-Bit Prefixes on IPv4 Point-to-Point Links — Internet Engineering Task Force (IETF)

About this calculator