The mask 255.255.255.0, the prefix /24, "how many addresses are in a /27", "is 10.0.5.17 inside 10.0.4.0/23" — you cannot set up a router or write firewall rules without these. Let us see how IPv4 addresses and masks work and learn to calculate subnets in your head, with a calculator for checking.

Address and mask

An IPv4 address is 32 bits written as four numbers from 0 to 255. The mask says which part of the address denotes the network and which part a particular host. The prefix /24 means the first 24 bits are the network and the remaining 8 are hosts. The same mask in decimal is 255.255.255.0: every 8 one-bits make 255.

Two addresses in every network are taken:

So a /24 has 256 addresses, and 254 can be given to devices.

Prefix cheat sheet

PrefixMaskAddressesHostsTypical use
/30255.255.255.25242A link between two routers
/29255.255.255.24886A block of public addresses from a provider
/28255.255.255.2401614Servers, management
/27255.255.255.2243230A small department
/26255.255.255.1926462A floor, cameras
/24255.255.255.0256254A typical local network
/23255.255.254.0512510A larger network, guest Wi-Fi
/16255.255.0.065,53665,534A whole company network

The rule is simple: each prefix bit halves the network. A /25 is half of a /24, a /26 a quarter, a /27 an eighth.

How to calculate in your head

Take 192.168.10.77/27. We need to find the network the address belongs to and its boundaries.

  1. Block size: 232−27 = 32 addresses.
  2. Network start: /27 subnets start at multiples of 32 — 0, 32, 64, 96… The number 77 falls in the block starting at 64.
  3. Result: network 192.168.10.64, broadcast 192.168.10.95, hosts .65 to .94, mask 255.255.255.224.

The same trick works for any octet. For example, 10.0.5.17/23: the block in the third octet is 224−23 = 2, networks start at even numbers, so the network is 10.0.4.0/23, covering 10.0.4.0–10.0.5.255. The answer to the question at the top: yes, it is inside.

Wildcard mask

Cisco ACLs and OSPF settings use a wildcard mask instead of a mask: the mask with zeros and ones swapped. For /24 it is 0.0.0.255, for /27 0.0.0.31. Easy to compute: 255 minus each octet of the mask.

Private and special ranges

Common mistakes

Calculator and network lists

The subnet calculator shows the mask, host range, broadcast address and wildcard for IPv4 and IPv6, splits a network into subnets and picks a prefix by the number of hosts. When you need to merge a long list of addresses into a minimal set of networks, subtract some networks from others or check whether an address is in a list, use CIDR lists.