How to Calculate a Subnet: CIDR, Network and Broadcast
Last updated: · 4 min read
A network administrator assigning an IP address to a server or planning a cloud network keeps asking the same questions: which network does this address belong to, how many devices fit in it, and what is the broadcast address? The answers come from reading the IP address together with the prefix length written after the slash, such as /24. This guide walks through IPv4 subnet calculation step by step: mask, network address, broadcast address, first and last usable host, and the special cases /31 and /32. The values in the example are the real output of the Subnet Calculator.
Formula
p = prefix length (0–32), host bits = 32 − p Subnet mask = 2^32 − 2^(32−p) (the first p bits are 1) Network address = IP AND mask Broadcast address = network address OR (NOT mask) Wildcard = NOT mask Total addresses = 2^(32−p) Usable hosts = 2^(32−p) − 2 (p ≤ 30) First host = network + 1, last host = broadcast − 1 p = 31 → 2 hosts, no broadcast (RFC 3021); p = 32 → a single address Class (by first octet): 0–127 A, 128–191 B, 192–223 C, 224–239 D, 240+ E
CIDR notation (Classless Inter-Domain Routing, RFC 4632) separates the network part from the host part with a bit count. The mask has ones in the network part and zeros in the host part. An AND operation gives the network address, and NOT of the mask combined with OR gives the broadcast address. Private ranges (10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16) are defined in RFC 1918; all other addresses are public.
What the inputs mean
- IP / CIDR
- An IPv4 address with its prefix, for example 192.168.1.10/24. The number after the slash is 0 to 32, or a mask such as 255.255.255.0 can be written instead.
- Subnet mask (if no CIDR)
- When the address is written without a prefix, enter the subnet mask here, for example 255.255.255.0. Take it from the network plan or from the device's network settings.
Worked example: Calculating 192.168.1.10/24
- Input: 192.168.1.10/24. Prefix p = 24, so the host bits are 32 − 24 = 8.
- The mask is 255.255.255.0 and the wildcard is 0.0.0.255. Tool output: Subnet mask: 255.255.255.0, Wildcard mask: 0.0.0.255.
- Network address = 192.168.1.10 AND 255.255.255.0 = 192.168.1.0; CIDR: 192.168.1.0/24.
- Broadcast address = 192.168.1.0 OR 0.0.0.255 = 192.168.1.255. First host 192.168.1.1, last host 192.168.1.254.
- Total addresses 2^8 = 256; usable hosts 256 − 2 = 254. The first octet is 192, so the class is C, and the address lies in 192.168.0.0/16, so the type is Private (RFC 1918).
Result: The tool shows Network address 192.168.1.0, Broadcast address 192.168.1.255, usable range 192.168.1.1 to 192.168.1.254 and 254 usable hosts. For 10.20.30.40/22 the same method gives network 10.20.28.0 and broadcast 10.20.31.255, with 1,022 usable hosts.
How to read the result
The network and broadcast addresses cannot be assigned to a device, so usable hosts are always two fewer than the total. On /31 point-to-point links (RFC 3021) both addresses are usable. A private address is not routed on the public internet, so check the router and gateway addresses as well when you apply the calculation to your own plan.
Common mistakes
- Assigning the broadcast address to a device. Addresses such as 192.168.1.255 reach every host on the segment and cannot be used as a host address.
- Confusing the total with the usable hosts. A /24 network has 256 addresses, but only 254 are usable.
- Mixing up the CIDR and the mask. /24 is the same as 255.255.255.0, while /16 means 255.255.0.0.
- Taking the network address for the device address. With 192.168.1.10/24 the device is 192.168.1.10 and the network is 192.168.1.0.
- Ignoring the private ranges. Addresses outside 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 are treated as public.
Frequently asked questions
What does CIDR /24 mean?
The first 24 bits of the IPv4 address are the network part and the remaining 8 bits are the host part. The mask is 255.255.255.0 and the block holds 256 addresses.
Why are two addresses lost from the usable count?
The first address of the block is the network address and the last is the broadcast address; neither can be given to a device.
How do /31 and /32 work?
/31 is defined for point-to-point links with two addresses (RFC 3021), and both are usable. /32 names a single address and is used for host routes and loopback interfaces.
Does this calculation work for public addresses too?
The arithmetic is the same, but who owns a public block and how it is routed is a separate question. The calculator only computes the address arithmetic.
The result is not exact or binding and is for information only; it is not an official document and cannot be used in official procedures. Confirm it with the competent authority or a professional before acting; no liability is accepted for losses arising from its use.