CIDR to Subnet Mask
Subnet mask
255.255.255.0
Hosts
254
How it works
CIDR prefix notation (/24, /16, etc.) and dotted-decimal subnet masks (255.255.255.0, 255.255.0.0) are two representations of the same concept: the boundary between the network portion and the host portion of an IP address. Converting between them is a daily task for network engineers, sysadmins, and DevOps engineers configuring firewalls, routing tables, and cloud VPCs.
**The conversion algorithm** CIDR /N → subnet mask: write N ones followed by (32−N) zeros in a 32-bit number, split into four 8-bit octets, convert each to decimal. /24 = 11111111.11111111.11111111.00000000 = 255.255.255.0. /20 = 11111111.11111111.11110000.00000000 = 255.255.240.0. /17 = 11111111.11111111.10000000.00000000 = 255.255.128.0. Reverse: convert each octet to binary, count leading ones.
**Common prefix lengths and their uses** /8 (255.0.0.0): Class A legacy, used for large ISP allocations. /16 (255.255.0.0): typical VPC or campus network block. /24 (255.255.255.0): most common LAN subnet — 254 hosts. /25 (255.255.255.128): splits a /24 into two halves — 126 hosts each. /30 (255.255.255.252): point-to-point links — 2 usable hosts. /32: host route (specific single IP in routing tables).
**Wildcard masks** The wildcard mask (used in Cisco ACLs and OSPF area definitions) is the bitwise inverse of the subnet mask. 255.255.255.0 inverts to 0.0.0.255. Wildcard masks allow non-contiguous patterns, useful for summarizing non-aligned address blocks in access control lists.
Frequently Asked Questions
- Convert each octet of the subnet mask to binary and count the leading 1 bits. 255.255.255.0 = 11111111.11111111.11111111.00000000 → 24 ones → /24. 255.255.240.0 = 11111111.11111111.11110000.00000000 → 20 ones → /20. A shortcut for powers of 2: 255 = /8 bits, 254 = /7, 252 = /6, 248 = /5, 240 = /4, 224 = /3, 192 = /2, 128 = /1, 0 = /0 (for that specific octet's contribution).
- The wildcard mask is the bitwise inverse of the subnet mask: wildcard = 255.255.255.255 − subnet_mask. For 255.255.255.0, wildcard = 0.0.0.255. Wildcard masks are used in Cisco IOS ACLs and OSPF network statements. A 0 bit means 'must match,' a 1 bit means 'any value.' Unlike subnet masks, wildcard masks can be non-contiguous (e.g., 0.0.255.0) for matching non-standard address patterns.
- Subnet masks and CIDR notation are not affected by locale. The semicolon/comma CSV convention relates to decimal separators (Europeans use comma as decimal separator), but IP addresses always use periods as octet separators and CIDR always uses a slash. 192.168.1.0/24 and 255.255.255.0 format is universal regardless of locale settings.
- /8 (255.0.0.0): large ISP or enterprise allocations, Class A legacy. /16 (255.255.0.0): VPC/campus blocks with up to 65,534 hosts. /24 (255.255.255.0): standard LAN — 254 hosts, most common in enterprise and home networks. /25 (255.255.255.128): splits a /24 into two halves, 126 hosts each. /28 (255.255.255.240): small subnet, 14 hosts — typical for Azure/GCP minimum. /30 (255.255.255.252): point-to-point links, 2 hosts. /32 (255.255.255.255): host route.