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.

Published

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. Worked example: for 192.168.1.130/26 the mask is 255.255.255.192, the network is 192.168.1.128, the broadcast is 192.168.1.191, and there are 62 usable host addresses.

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:

Bitwise AND of IP and mask in the last octet
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. The procedure is the one originally specified for subnetting in RFC 950, and it has not changed since.

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

Frequently asked questions

Why does /24 map to 255.255.255.0?

A /24 sets the first 24 of the 32 mask bits to 1 and the remaining 8 to 0. Written out per octet that is 11111111.11111111.11111111.00000000, and each octet read as a decimal number gives 255.255.255.0.

What does the subnet mask 255.255.255.255 mean?

All 32 bits are set, so the block holds exactly one address — a host route. Routing tables and ACLs use it to match a single IP rather than a range. The opposite extreme is 0.0.0.0/0, which matches every destination.

How many usable hosts does a /26 have?

A /26 has 26 network bits and 6 host bits, so it spans 64 addresses; reserving the first (network) and last (broadcast) leaves 62 usable hosts. Each /26 begins at a multiple of 64 in the fourth octet: .0, .64, .128 or .192.

What is the difference between a subnet mask and a wildcard mask?

The wildcard mask is the bitwise inverse of the subnet mask: where the mask has 1s the wildcard has 0s. A /26 is 255.255.255.192 as a subnet mask and 0.0.0.63 as a wildcard. Wildcards are used in Cisco-style ACLs, where a 0 bit means 'must match' and a 1 bit means 'don't care'.

Is the subnet mask sent with every packet?

No. The mask is local configuration only — it never leaves the device. Each host uses it internally to decide whether a destination address is on-link (deliver directly) or off-link (hand the packet to the default gateway).

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.