📐 CIDR Notation and How to Calculate a Subnet Mask

Convert CIDR notation like /24 into a subnet mask

You've probably seen notation like 192.168.1.0/24 in a network settings screen. What does the /24 actually mean, and how do you turn it into a subnet mask? This article walks through what CIDR notation means, how it relates to a subnet mask, and how to calculate the number of usable hosts with a real worked example.

What CIDR notation means

CIDR (Classless Inter-Domain Routing) is a notation that appends /number to an IP address to indicate how many bits make up the network portion. An IPv4 address is 32 bits long, and CIDR splits those bits into a "network" portion at the front and a "host" portion at the back. /24 means the first 24 bits identify the network, leaving the remaining 8 bits (32-24) to identify individual hosts within it. CIDR replaced the older, rigid class-based system (Class A/B/C), letting networks be sized as flexibly as needed rather than in fixed chunks.

Converting CIDR to a subnet mask

A subnet mask is what you get when you set that many leading bits to 1 (and the rest to 0) across all 32 bits, then write it out in dotted-decimal form, 8 bits at a time. For /24, the first 24 bits are all 1 and the remaining 8 are 0, so in binary that's 11111111.11111111.11111111.00000000, which converts to 255.255.255.0. A few common ones, for reference:

When a prefix isn't a multiple of 8, the last octet ends up being a value like 128, 192, 224, 240, 248, 252, or 254 — the decimal value of however many leading bits are set to 1 within that octet. For example, /25 sets just one bit in the last octet (10000000), which is 128.

Calculating usable host count

How many addresses fit in a network depends on the number of host bits. The total address count is 2^(32-prefix), and out of that block, the very first address is reserved as the network address (identifying the network itself) and the very last is reserved as the broadcast address (used to address everyone on the network at once). So the number of addresses actually assignable to hosts is 2^(32-prefix) - 2. Take /24 as an example: with 8 host bits, the total is 2^8 = 256 addresses, and subtracting the network and broadcast addresses leaves 254 usable addresses. For 192.168.1.0/24, the network address is 192.168.1.0, the broadcast address is 192.168.1.255, and usable addresses run from 192.168.1.1 through 192.168.1.254. There are exceptions to this rule at the extremes — /31 (used for point-to-point links, where both addresses in the pair are usable) and /32 (identifying a single host) don't follow the network/broadcast split.

A bigger example to double-check the math

For a /16, there are 16 host bits, so the total address count is 2^16 = 65,536, with 65,534 usable — and the subnet mask works out to 255.255.0.0. A single prefix number is enough to derive the network range, the subnet mask, and the usable host count, but doing the binary math by hand every time is tedious and easy to get wrong. Plugging any CIDR block into a calculator that instantly returns the network address, broadcast address, and usable range is a lot faster and more reliable.

Full CIDR reference table (/0 – /32)

A quick reference of the subnet mask, wildcard mask, and address count for every prefix length. Values are computed (verified with node), so you can use them directly when designing subnets or writing firewall rules.

CIDRSubnet maskWildcard maskTotal addressesUsable hosts
/00.0.0.0255.255.255.2554,294,967,2964,294,967,294
/1128.0.0.0127.255.255.2552,147,483,6482,147,483,646
/2192.0.0.063.255.255.2551,073,741,8241,073,741,822
/3224.0.0.031.255.255.255536,870,912536,870,910
/4240.0.0.015.255.255.255268,435,456268,435,454
/5248.0.0.07.255.255.255134,217,728134,217,726
/6252.0.0.03.255.255.25567,108,86467,108,862
/7254.0.0.01.255.255.25533,554,43233,554,430
/8255.0.0.00.255.255.25516,777,21616,777,214
/9255.128.0.00.127.255.2558,388,6088,388,606
/10255.192.0.00.63.255.2554,194,3044,194,302
/11255.224.0.00.31.255.2552,097,1522,097,150
/12255.240.0.00.15.255.2551,048,5761,048,574
/13255.248.0.00.7.255.255524,288524,286
/14255.252.0.00.3.255.255262,144262,142
/15255.254.0.00.1.255.255131,072131,070
/16255.255.0.00.0.255.25565,53665,534
/17255.255.128.00.0.127.25532,76832,766
/18255.255.192.00.0.63.25516,38416,382
/19255.255.224.00.0.31.2558,1928,190
/20255.255.240.00.0.15.2554,0964,094
/21255.255.248.00.0.7.2552,0482,046
/22255.255.252.00.0.3.2551,0241,022
/23255.255.254.00.0.1.255512510
/24255.255.255.00.0.0.255256254
/25255.255.255.1280.0.0.127128126
/26255.255.255.1920.0.0.636462
/27255.255.255.2240.0.0.313230
/28255.255.255.2400.0.0.151614
/29255.255.255.2480.0.0.786
/30255.255.255.2520.0.0.342
/31255.255.255.2540.0.0.122 *
/32255.255.255.2550.0.0.011 *

* /31 uses both addresses for point-to-point links (RFC 3021). /32 designates a single host. For every other prefix, "usable hosts" excludes the network and broadcast addresses (2 total).

📐 Try it yourself with the tool

CIDR Notation and How to Calculate a Subnet Mask — Convert CIDR notation like /24 into a subnet mask

More guides

🔁
How to Find a Domain's IP Address
Find the real server IP a domain points to
🛰️
How to Check DNS Propagation (What Is TTL?)
Understand TTL and check propagation after a nameserver change
📡
The Easiest Way to Find Your IP Address
Public vs private IP, and how to check yours
🩺
How to Check an SSL Certificate's Expiration Date
Check a certificate's expiry without opening a browser
🪪
Understanding JWT Structure and How to Decode It
The Header, Payload & Signature — explained
🗝️
How to Create an Apache .htpasswd File for Basic Auth
Generate an APR1-MD5 hashed .htpasswd file
🔑
What Makes a Strong Password (and How to Generate One)
Length, character sets & entropy explained
🔐
What Is Base64 Encoding and When to Use It
Why it's used in email attachments & data URIs
📘
Using a JSON Formatter to Read API Responses
Turn minified JSON into something readable
🗓️
How to Convert a Unix Timestamp to a Date
Turn seconds-since-1970 into a readable date
🗃️
How to Format Messy SQL Queries
Break a one-line SQL statement into readable clauses
🎨
Converting Between HEX, RGB, and HSL Color Codes
The difference between the three formats
🔠
camelCase, snake_case & Other Naming Conventions
When to use each naming style
🆚
How to Compare Two Text Files (Diff Checker)
Quickly spot differences between two versions