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:
- the network address — all host bits are zero (192.168.1.0);
- the broadcast address — all host bits are one (192.168.1.255).
So a /24 has 256 addresses, and 254 can be given to devices.
Prefix cheat sheet
| Prefix | Mask | Addresses | Hosts | Typical use |
|---|---|---|---|---|
| /30 | 255.255.255.252 | 4 | 2 | A link between two routers |
| /29 | 255.255.255.248 | 8 | 6 | A block of public addresses from a provider |
| /28 | 255.255.255.240 | 16 | 14 | Servers, management |
| /27 | 255.255.255.224 | 32 | 30 | A small department |
| /26 | 255.255.255.192 | 64 | 62 | A floor, cameras |
| /24 | 255.255.255.0 | 256 | 254 | A typical local network |
| /23 | 255.255.254.0 | 512 | 510 | A larger network, guest Wi-Fi |
| /16 | 255.255.0.0 | 65,536 | 65,534 | A 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.
- Block size: 232−27 = 32 addresses.
- Network start: /27 subnets start at multiples of 32 — 0, 32, 64, 96… The number 77 falls in the block starting at 64.
- 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
10.0.0.0/8,172.16.0.0/12,192.168.0.0/16— private networks, not routed on the internet.100.64.0.0/10— addresses behind the provider's NAT (CGNAT). If your router has such an address, port forwarding from outside will not work. You can see your external address on the My IP page.169.254.0.0/16— the computer did not get an address via DHCP and assigned one to itself.127.0.0.0/8— the computer itself (localhost).
Common mistakes
- Different masks on devices of the same network. A computer with /24 and a router with /25 disagree on who is "local", and some addresses stop answering.
- A gateway outside the network. The gateway must be in the same subnet as the device's address.
- Overlapping networks on different router interfaces or in offices that are later joined.
- A network or broadcast address assigned to a device by hand.
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.