How to Calculate a Subnet Mask

A repeatable five-step method to turn any CIDR prefix into its mask, network address, broadcast address and host range — worked end to end with 192.168.1.130/26.

The short version: mask = first p bits set · host bits = 32 − p · block size = 2(32−p) · network = IP AND mask · broadcast = network + block size − 1.

The five steps

  1. Write the prefix as a binary mask. A /26 sets the first 26 bits to 1 and the rest to 0: 11111111.11111111.11111111.11000000, which in dotted decimal is 255.255.255.192.
  2. Count the host bits. Host bits = 32 − prefix = 32 − 26 = 6 bits. These are the zero positions in the mask.
  3. Compute the block size. Block size = 2host bits = 26 = 64 addresses. Every /26 covers a contiguous run of 64 addresses.
  4. Find the network address. Bitwise-AND the IP with the mask (see the octet math below). 192.168.1.130 AND 255.255.255.192 = 192.168.1.128.
  5. Broadcast and hosts. Broadcast = network + block size − 1 = 192.168.1.128 + 64 − 1 = 192.168.1.191. Everything strictly between is a usable host address.

The AND operation, octet by octet

Only the fourth octet differs between the IP and the mask here, so that is the only octet where the AND changes anything:

DecimalBinary
IP (last octet)13010000010
Mask (last octet)19211000000
AND result12810000000

Reading down each column: wherever the mask has a 1, the IP bit passes through; wherever it has a 0, the result is forced to 0. That is how the host portion is erased and the network boundary appears.

Worked example: 192.168.1.130/26

Applying the five steps above:

Subnet mask
255.255.255.192
Wildcard mask
0.0.0.63
Network address
192.168.1.128
Broadcast address
192.168.1.191
First usable host
192.168.1.129
Last usable host
192.168.1.190
Total addresses
64
Usable hosts
62

Quick reference: common prefixes

Frequently used prefix lengths with masks and host counts
PrefixSubnet maskTotal addressesUsable hostsLast host octet*
/24 255.255.255.0 256 254 .254
/25 255.255.255.128 128 126 .126
/26 255.255.255.192 64 62 .62
/27 255.255.255.224 32 30 .30
/28 255.255.255.240 16 14 .14
/30 255.255.255.252 4 2 .2

*Shown for a network whose fourth octet is 0 (e.g. 192.168.1.0/24). The full table for every prefix lives on the subnet cheat sheet.

Common mistakes

Check your work

Hand calculations are great practice — verify them before they reach production:

IPv4 Subnet Calculator

Full breakdown of any CIDR block: network, broadcast, host range, wildcard mask and binary view.

Subnet Cheat Sheet

Every prefix from /0 to /32 with mask, wildcard and host counts on one printable page.

Want the theory behind slash notation first? Start with CIDR notation explained, or see the deep dive on the /26 subnet mask.