Subnet Mask Converter
A CIDR prefix length and a dotted-decimal subnet mask are two ways of writing the same thing: how many bits of an IPv4 address belong to the network. This converter takes a prefix length from 0 to 32 and returns the matching subnet mask, the wildcard (inverse) mask used in access control lists, the number of host bits, and the count of usable hosts. The conversion is purely positional: set the leftmost prefix-length bits to 1, group into octets, and read each octet as a decimal value.
Subnet mask formula
Subnet mask = 32-bit value, prefix-length leading 1 bits
Each octet ranges over: 0, 128, 192, 224, 240, 248, 252, 254, 255
Wildcard mask = 255 - each subnet mask octet
Host bits = 32 - prefix length
Usable hosts = (2 ^ host bits) - 2 (for /0 to /30)
The wildcard mask is the bitwise complement of the subnet mask. For 255.255.255.0 the wildcard is 0.0.0.255.
Subnet mask context
- Valid octet values are limited to nine numbers because the 1 bits must be contiguous from the left.
- 255.255.255.0 (/24) is the default mask for small office and home networks.
- 255.255.0.0 (/16) was historically a Class B network and holds 65,534 usable hosts.
- 255.0.0.0 (/8) was a Class A network with over 16 million addresses.
- Wildcard masks appear in router access control lists, where set bits mean 'match any value'.
Subnet mask converter: frequently asked questions
What is a subnet mask?
A subnet mask is a 32-bit value that separates the network portion of an IPv4 address from the host portion. Bits set to 1 mark the network, and bits set to 0 mark the host. A mask of 255.255.255.0 has 24 network bits, equivalent to a /24 CIDR prefix.
How do I convert a prefix length to a subnet mask?
Set the leftmost prefix-length bits to 1 and the rest to 0, then group the 32 bits into four octets and convert each to decimal. A /26 gives 11111111.11111111.11111111.11000000, which is 255.255.255.192.
What is a wildcard mask?
A wildcard mask is the bitwise inverse of the subnet mask: every 0 in the subnet mask becomes 1 and vice versa. For 255.255.255.0 the wildcard mask is 0.0.0.255. Wildcard masks are used in access control lists where 1 bits mean 'match any'.
Why are only certain decimal values valid in a subnet mask?
Because the 1 bits must be contiguous from the left, each octet can only be one of nine values: 0, 128, 192, 224, 240, 248, 252, 254, or 255. A value like 255.255.255.100 is not a valid mask because 100 is not a contiguous run of 1 bits.
How many hosts does a subnet mask allow?
Usable hosts equal 2 raised to the power of the host-bit count, minus 2 for the network and broadcast addresses (for prefixes /0 to /30). A /24 has 8 host bits, giving 256 addresses and 254 usable hosts.
Official sources
- RFC Editor (IETF): RFC 4632, Classless Inter-Domain Routing (CIDR).
- IANA: IPv4 Address Space Registry.
Reviewed by the CalculatorHub team, edited by James Graham, 17 June 2026. See our methodology.