SeaMeWe4 Net Tools Subnet calculator

How to Calculate a Subnet Mask (step by step, with examples)

To calculate a subnet mask from an IP address and prefix by hand: write the prefix as that many 1 bits followed by 0 bits, convert each 8-bit group to decimal, then use a bitwise AND between the address and that mask to find the network address — the steps below walk through one worked example end to end.

Diagram of network bits versus host bits, the basis for every step in this guide

Worked example throughout this guide: 192.168.10.37/26.

Step 1: write the prefix as bits

A /26 prefix means the first 26 bits of the 32-bit address are fixed (“network” bits) and the remaining 6 bits are free for hosts. Write that out as 26 ones followed by 6 zeros, split into four 8-bit groups:

OctetBits
1st (bits 1–8)11111111
2nd (bits 9–16)11111111
3rd (bits 17–24)11111111
4th (bits 25–32)11000000 (only 2 of 8 bits are 1 — bits 25 and 26)

Step 2: convert to a dotted mask

Convert each 8-bit group to its decimal value: 11111111 = 255, and 11000000 = 128 + 64 = 192. So /26 is 255.255.255.192 — that’s the subnet mask.

Step 3: find the network and broadcast address

Apply a bitwise AND between the IP address and the mask, one octet at a time. The first three octets of the mask are all 1s, so they pass through unchanged (192.168.10). For the last octet, write 37 in binary and AND it with the mask’s last octet:

BinaryDecimal
IP address (last octet)0010010137
Subnet mask (last octet)11000000192
AND result → network000000000

So the network address is 192.168.10.0. The broadcast address is the network address with every host bit set to 1: the last octet becomes 00111111 = 63, giving a broadcast address of 192.168.10.63.

Step 4: count the usable hosts (2n − 2)

Diagram showing where an address sits between a subnet's network and broadcast address

With 6 host bits, the block holds 26 = 64 total addresses. Subtract 2 for the network and broadcast addresses, which are never assigned to a host, leaving 62 usable addresses: 192.168.10.1 through 192.168.10.62.

You can check every step of this example instantly with the IP subnet calculator — enter 192.168.10.37 with a /26 prefix and compare its output to the numbers above.

Self-check exercises

Work through each one by hand using the four steps above, then open the answer to check yourself.

1. Find the network address, broadcast address and usable host count for 10.5.9.200/27.

Mask: 255.255.255.224. Last octet of the IP (200 = 11001000) AND the mask’s last octet (224 = 11100000) = 11000000 = 192, so the network address is 10.5.9.192. Broadcast: 10.5.9.223. Usable hosts: 2⁵ − 2 = 30.

2. Find the network address, broadcast address and usable host count for 172.20.100.10/20.

Mask: 255.255.240.0. Network address: 172.20.96.0. Broadcast: 172.20.111.255. Usable hosts: 2¹² − 2 = 4,094.

3. Find the network address, broadcast address and usable host count for 203.0.113.77/29.

Mask: 255.255.255.248. Network address: 203.0.113.72. Broadcast: 203.0.113.79. Usable hosts: 2³ − 2 = 6.

Plan several different-sized subnets out of one block at once with the VLSM calculator.

Frequently asked questions

What’s the fastest way to convert a prefix to a mask without binary math?

Memorize the 8 possible values in one octet: 128, 192, 224, 240, 248, 252, 254, 255, corresponding to 1–8 of that octet’s bits set to 1. Our subnet mask cheat sheet lists every /0–/32 mask if you’d rather look it up than calculate it.

Do I always need to do the AND by hand?

No — understanding the steps helps on exams and in troubleshooting, but day to day the IP subnet calculator does the same math instantly.

What if the prefix doesn’t land on a whole octet, like /26?

That’s exactly the case worked through above — the AND still works one octet at a time; it’s only the last partially-masked octet (position 4 for a /26) where you need to do the binary math instead of just copying 255 or 0.

This guide is part of SeaMeWe4 Net Tools, an independent set of free networking calculators.

Was this page helpful?

One tap tells us which guides need more detail.