completecalculator.com

How to Calculate Subnet Mask from IP Address

Network diagram showing IP addresses and subnet divisions

October 25, 2026

Disclaimer: This content is for informational and educational purposes only.

Every IP address comes with a subnet mask, and that mask decides which part of the address identifies the network and which part identifies devices on it. This guide shows you how to calculate a subnet mask from an IP address using the binary method, gives you a CIDR reference table, and works through a full example — including how many usable host addresses each subnet gives you.

What Is a Subnet Mask?

An IPv4 address has 32 bits, written as four numbers separated by dots (for example, 192.168.1.0). A subnet mask is a second 32-bit number that splits the address into two parts:

In the mask, network bits are 1s and host bits are 0s. Written in dotted form, a common mask looks like 255.255.255.0 — the first 24 bits are 1s (network), the last 8 bits are 0s (hosts).

The shorthand for this is CIDR notation: the number after the slash tells you how many bits are network bits. So 192.168.1.0/24 means "24 network bits," which is the same as mask 255.255.255.0.

The Binary Method: How Subnet Masks Are Calculated

Here is the method, step by step:

  1. Write the mask as 32 bits. Put a 1 for every network bit and a 0 for every host bit, in groups of 8.
  2. Convert each group of 8 bits to decimal. Each bit position is worth 128, 64, 32, 16, 8, 4, 2, 1 from left to right.
  3. Join the four decimal numbers with dots. That is your subnet mask.

Example — a /26 mask (26 network bits, 6 host bits):

11111111 . 11111111 . 11111111 . 11000000
   255   .    255   .    255   .  (128+64) = 192

So /26 = 255.255.255.192.

The reverse works too: given a mask like 255.255.255.240, convert the last octet (240 = 128+64+32+16 = four 1s) and count the total 1s: 8 + 8 + 8 + 4 = /28.

CIDR Reference Table

CIDRSubnet maskTotal addressesUsable hosts
/24255.255.255.0256254
/25255.255.255.128128126
/26255.255.255.1926462
/27255.255.255.2243230
/28255.255.255.2401614
/29255.255.255.24886
/30255.255.255.25242
/31255.255.255.25420 (special case, see below)
/32255.255.255.25511 (a single host)

The formulas behind the table:

Worked Example: 192.168.1.0/26

Let's calculate everything for the network 192.168.1.0/26, from scratch.

Step 1: Find the mask. /26 means 26 network bits: 11111111.11111111.11111111.11000000 = 255.255.255.192.

Step 2: Count host bits. 32 − 26 = 6 host bits.

Step 3: Count addresses. 2^6 = 64 total addresses, minus 2 reserved = 62 usable hosts.

Step 4: Find the range. The network address is 192.168.1.0 (host bits all 0). The broadcast address is 192.168.1.63 (host bits all 1). So:

Step 5: Check your answer. 62 usable hosts + 1 network + 1 broadcast = 64. It adds up.

A second quick check — 10.0.0.0/25: mask 255.255.255.128, 7 host bits, 128 total addresses, 126 usable hosts, range 10.0.0.1 to 10.0.0.126, broadcast 10.0.0.127.

Common Pitfalls

Forgetting to subtract 2

The most common beginner mistake is reporting 64 hosts for a /26 instead of 62. The network and broadcast addresses are real addresses in the range, but they cannot be assigned to devices. Always subtract 2 — except for the /31 and /32 special cases below.

Confusing the mask with the network address

255.255.255.192 is a mask, not an address you can assign. The network 192.168.1.0/26 is identified by its network address (192.168.1.0) plus its mask (255.255.255.192) together.

Assuming /31 gives zero usable hosts

Traditionally, /31 was unusable because both addresses were reserved. Modern point-to-point links (for example, between two routers) can use /31 with both addresses assigned, under RFC 3021. If you are studying for an exam, answer "0 usable" unless the question mentions point-to-point links; if you are configuring real routers, /31 is valid for that specific case.

Mixing up CIDR and mask

/26 and 255.255.255.192 describe the same subnet — one is not "bigger" than the other. A larger CIDR number means a smaller subnet (fewer hosts): /28 (14 hosts) is smaller than /24 (254 hosts).

Try It Yourself

You can check any calculation instantly with our free Subnet Calculator — enter an IP address and CIDR, and it returns the mask, network address, broadcast address, and usable host range.

Try the Subnet Calculator →

Frequently Asked Questions

How do I calculate a subnet mask from an IP address?

Count the network bits (the CIDR number), write that many 1s followed by 0s to make 32 bits, then convert each 8-bit group to decimal. For example, /26 gives 11111111.11111111.11111111.11000000 = 255.255.255.192.

How many usable hosts does a /26 subnet have?

62. A /26 has 6 host bits, giving 64 total addresses, minus the network address and the broadcast address.

What is the difference between a subnet mask and CIDR notation?

They describe the same thing two ways. CIDR (/26) counts the network bits; the mask (255.255.255.192) writes them out as a 32-bit number. Convert freely between them using the binary method above.

Why do we subtract 2 from the total addresses?

Because the first address in a subnet is the network address and the last is the broadcast address. Neither can be assigned to a host device.

What is a /32 subnet?

A single host address — all 32 bits are network bits, so there are no host bits. You will see /32 in firewall rules and routing tables when exactly one device is meant.

About the Author

Written by the completecalculator.com editorial team. We are dedicated to providing accurate, easy-to-understand tools and information to help you manage your health and finances effectively.