Skip to main content

CIDR and Subnet Mask Cheatsheet

By Dejan Panovski •Updated on • Download PDF

IPv4 CIDR prefix to subnet mask table from /0 to /32 with address and host counts, subnet boundaries, reserved ranges, IPv6 prefix sizes, and CIDR in Linux commands.

A CIDR prefix such as /24 tells you how many leading bits of an IP address identify the network. This cheatsheet maps every IPv4 prefix to its subnet mask and host count, and covers subnet boundaries, reserved ranges, common IPv6 prefix sizes, and the places CIDR shows up in Linux commands.

CIDR Basics

An IPv4 address has 32 bits. The prefix counts the bits that belong to the network. Host counts assume conventional unicast subnets and subtract only network and broadcast addresses; reserved ranges and provider reservations can reduce availability.

TermMeaning
192.168.10.0/24Network 192.168.10.0 with a 24-bit prefix
Prefix lengthLeading network bits, from /0 to /32
Host bits32 - prefix; a /24 leaves 8
Total addresses2^(32 - prefix); a /27 has 32
Usable hostsTotal minus 2 (network and broadcast) for /0 to /30
Block size256 minus the mask octet where the prefix ends; for /27, 256 - 224 = 32
Wildcard mask255.255.255.255 minus the mask; a /26 is 0.0.0.63
Subnets from a split2^(new prefix - old prefix); a /24 holds four /26 blocks

Prefixes /25 to /32

The prefix ends in the last octet. These sizes cover small LANs, point-to-point links, and host routes.

Prefix and maskSize
/25 255.255.255.128128 addresses, 126 usable hosts
/26 255.255.255.19264 addresses, 62 usable hosts
/27 255.255.255.22432 addresses, 30 usable hosts
/28 255.255.255.24016 addresses, 14 usable hosts
/29 255.255.255.2488 addresses, 6 usable hosts
/30 255.255.255.2524 addresses, 2 usable hosts
/31 255.255.255.2542 addresses, both usable on point-to-point links (RFC 3021)
/32 255.255.255.2551 address, a single host route

Prefixes /17 to /24

The prefix ends in the third octet. Each step to a shorter prefix doubles the block.

Prefix and maskSize
/17 255.255.128.032,768 addresses, 32,766 usable hosts
/18 255.255.192.016,384 addresses, 16,382 usable hosts
/19 255.255.224.08,192 addresses, 8,190 usable hosts
/20 255.255.240.04,096 addresses, 4,094 usable hosts
/21 255.255.248.02,048 addresses, 2,046 usable hosts
/22 255.255.252.01,024 addresses, 1,022 usable hosts
/23 255.255.254.0512 addresses, 510 usable hosts
/24 255.255.255.0256 addresses, 254 usable hosts

Prefixes /9 to /16

The prefix ends in the second octet. A /16 holds 256 /24 networks.

Prefix and maskSize
/9 255.128.0.08,388,608 addresses, 8,388,606 usable hosts
/10 255.192.0.04,194,304 addresses, 4,194,302 usable hosts
/11 255.224.0.02,097,152 addresses, 2,097,150 usable hosts
/12 255.240.0.01,048,576 addresses, 1,048,574 usable hosts
/13 255.248.0.0524,288 addresses, 524,286 usable hosts
/14 255.252.0.0262,144 addresses, 262,142 usable hosts
/15 255.254.0.0131,072 addresses, 131,070 usable hosts
/16 255.255.0.065,536 addresses, 65,534 usable hosts

Prefixes /0 to /8

The prefix ends in the first octet. A /0 matches every IPv4 address.

Prefix and maskSize
/0 0.0.0.04,294,967,296 addresses, every IPv4 address (the default route)
/1 128.0.0.02,147,483,648 addresses, 2,147,483,646 usable hosts
/2 192.0.0.01,073,741,824 addresses, 1,073,741,822 usable hosts
/3 224.0.0.0536,870,912 addresses, 536,870,910 usable hosts
/4 240.0.0.0268,435,456 addresses, 268,435,454 usable hosts
/5 248.0.0.0134,217,728 addresses, 134,217,726 usable hosts
/6 252.0.0.067,108,864 addresses, 67,108,862 usable hosts
/7 254.0.0.033,554,432 addresses, 33,554,430 usable hosts
/8 255.0.0.016,777,216 addresses, 16,777,214 usable hosts

Subnet Boundaries in a /24

A network address must start on one of these values in the last octet.

PrefixBlock size, subnets, and network addresses
/25Block of 128, 2 subnets: .0, .128
/26Block of 64, 4 subnets: .0, .64, .128, .192
/27Block of 32, 8 subnets: .0, .32, .64 … .224
/28Block of 16, 16 subnets: .0, .16, .32 … .240
/29Block of 8, 32 subnets: .0, .8, .16 … .248
/30Block of 4, 64 subnets: .0, .4, .8 … .252

Find the Network for an Address

Round the octet where the prefix ends down to a multiple of the block size, then set all following octets to zero. A /20 has a block of 16 in the third octet, so 45 rounds down to 32.

AddressResult
192.168.10.34/27Network 192.168.10.32, broadcast 192.168.10.63, hosts .33 to .62
172.16.45.10/20Network 172.16.32.0, broadcast 172.16.47.255
10.20.30.40/12Network 10.16.0.0, broadcast 10.31.255.255

Split and Combine Networks

Splitting borrows host bits. Combining (route aggregation) needs contiguous blocks that start on the larger prefix boundary.

TaskResult
Split 192.168.10.0/24 in two/25: .0 and .128
Split 192.168.10.0/24 in four/26: .0, .64, .128, .192
Split 10.0.0.0/16 into /24 blocks256 networks, 10.0.0.0/24 to 10.0.255.0/24
Combine two /24 blocksOne /23 when the first third octet is even
Combine 192.168.0.0/24 to 192.168.3.0/24192.168.0.0/22
Combine 192.168.1.0/24 to 192.168.4.0/24No single /22; summarizes as 192.168.1.0/24, 192.168.2.0/23, 192.168.4.0/24
Check a /22 startThe third octet is a multiple of 4

Private and Reserved IPv4 Ranges

Ranges you will meet in configs, routing tables, and documentation.

RangeUse
10.0.0.0/8Private network (RFC 1918)
172.16.0.0/12Private network, 172.16.0.0 to 172.31.255.255 (RFC 1918)
192.168.0.0/16Private network (RFC 1918)
100.64.0.0/10Carrier-grade NAT shared space (RFC 6598)
127.0.0.0/8Loopback
169.254.0.0/16Link-local; cloud metadata services listen on 169.254.169.254
0.0.0.0/0Every address; the default route
224.0.0.0/4Multicast
192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24Documentation examples (RFC 5737)
255.255.255.255/32Limited broadcast

IPv6 Prefixes

IPv6 addresses have 128 bits and no broadcast address.

PrefixUse
/128Single address
/127Point-to-point link (RFC 6164)
/64Standard subnet; SLAAC needs a /64
/56Common delegation to a home or small site; 256 /64 subnets
/48Common delegation to a site; 65,536 /64 subnets
::/0Default route
::1/128Loopback
fe80::/10Link-local
fc00::/7Unique local addresses (fd00::/8 in practice)
ff00::/8Multicast
2001:db8::/32Documentation examples

CIDR in Linux Commands

Commands and rules that take or print a prefix.

CommandDescription
ip -brief addressShow each interface address with its prefix
sudo ip addr add 192.168.10.34/27 dev eth0Assign an address with a /27 prefix
ip route showShow routes; the connected route is the network, 192.168.10.32/27
sudo ip route add 10.20.0.0/16 via 192.168.10.33Route a block through a gateway
sudo ufw allow from 192.168.10.0/24 to any port 22Allow SSH from one subnet
sudo nmap -sn 192.168.10.0/24Find live hosts in a subnet
ipcalc 192.168.10.34/27Print the network, broadcast, and host range (ipcalc package)
python3 -c "import ipaddress; print(ipaddress.ip_network('192.168.10.34/27', strict=False))"Print the network for an address; prints 192.168.10.32/27

Troubleshooting

Quick checks for common CIDR mistakes.

IssueCheck
Error: Invalid prefix for given prefix length.ip route add needs the network address; use 192.168.10.32/27, not 192.168.10.34/27
Error: Nexthop has invalid gateway.The gateway is outside every connected subnet; check the prefix on the interface
WARN: Rule changed after normalizationufw cleared the host bits; 192.168.10.34/27 became 192.168.10.32/27
ValueError: ... has host bits setPython ipaddress is strict; pass strict=False or use the network address
Address added without a prefixip addr add 10.0.0.5 dev eth0 assigns a /32 and adds no connected route
Two hosts on one LAN cannot reach each otherCompare prefixes; with a mismatched mask, one host sends the traffic to its gateway

Use these guides for full addressing and firewall workflows.

GuideDescription
CIDR Notation and Subnetting ExplainedHow prefixes, masks, and host counts work
Subnet CalculatorCalculate ranges and split a block in the browser
IPv4 vs IPv6Differences between the two protocols
ip Command in LinuxManage addresses and routes
How to Find Your IP Address in LinuxCheck interface addresses and prefixes
ufw Command in LinuxAllow and deny traffic by subnet
IP Command Cheatsheetip addresses, routes, and links at a glance