What is a subnet mask?

A subnet mask is a 32-bit number that separates the network part of an IP address from the host part. A mask like 255.255.255.0 says the first three octets are the network and the last octet is for hosts.

Last reviewed:

Looking for the complete table instead? Every prefix from /0 to /32, with mask, wildcard and host count, is on the CIDR reference.

What the mask actually does

An IPv4 address is 32 bits. On its own it does not say where the network ends and the host begins. The subnet mask supplies that boundary. Every bit set to 1 in the mask marks a network bit; every 0 marks a host bit. Line the mask up against the address and you can read off the network.

Because the 1 bits are always contiguous and on the left, a mask can be summarised by a single number: how many 1s it has. That count is the prefix length. So 255.255.255.0 is the same as /24, and 255.255.255.192 is /26.

Reading a mask octet by octet

Each octet of a mask is one of a fixed set of values: 0, 128, 192, 224, 240, 248, 252, 254, or 255. Those are the only bytes you can build from a run of leading 1s. If you see any other value, such as 255.255.255.100, it is not a valid contiguous mask.

255 means all eight bits are network bits. 0 means all eight are host bits. Values in between split an octet: 192 (11000000) uses the top two bits for the network and leaves the rest for hosts. The subnet mask calculator on this site converts any prefix to its mask and back.

Every valid subnet mask, and only those

There are exactly 33 valid IPv4 subnet masks, one per prefix length from /0 to /32. That is not a convention, it follows from the definition: the mask is a run of 1 bits followed by a run of 0 bits, so the only freedom is where the run ends. Anything else is not a mask.

This is the whole set. Anything not in this table is invalid, however plausible it looks.

The 33 valid IPv4 subnet masks with prefix, wildcard and usable host count
PrefixSubnet maskWildcard maskUsable hosts
/00.0.0.0255.255.255.2554,294,967,294
/1128.0.0.0127.255.255.2552,147,483,646
/2192.0.0.063.255.255.2551,073,741,822
/3224.0.0.031.255.255.255536,870,910
/4240.0.0.015.255.255.255268,435,454
/5248.0.0.07.255.255.255134,217,726
/6252.0.0.03.255.255.25567,108,862
/7254.0.0.01.255.255.25533,554,430
/8255.0.0.00.255.255.25516,777,214
/9255.128.0.00.127.255.2558,388,606
/10255.192.0.00.63.255.2554,194,302
/11255.224.0.00.31.255.2552,097,150
/12255.240.0.00.15.255.2551,048,574
/13255.248.0.00.7.255.255524,286
/14255.252.0.00.3.255.255262,142
/15255.254.0.00.1.255.255131,070
/16255.255.0.00.0.255.25565,534
/17255.255.128.00.0.127.25532,766
/18255.255.192.00.0.63.25516,382
/19255.255.224.00.0.31.2558,190
/20255.255.240.00.0.15.2554,094
/21255.255.248.00.0.7.2552,046
/22255.255.252.00.0.3.2551,022
/23255.255.254.00.0.1.255510
/24255.255.255.00.0.0.255254
/25255.255.255.1280.0.0.127126
/26255.255.255.1920.0.0.6362
/27255.255.255.2240.0.0.3130
/28255.255.255.2400.0.0.1514
/29255.255.255.2480.0.0.76
/30255.255.255.2520.0.0.32
/31255.255.255.2540.0.0.12
/32255.255.255.2550.0.0.01

Usable hosts is total addresses minus two, except a /31 (two, under RFC 3021) and a /32 (one). Those two rows are where most calculators go wrong.

Why 255.255.255.100 is not a valid subnet mask

This is the single most common mask question, and the answer is a bit-level one. Write 100 in binary and you get 01100100. Line that up as the fourth octet of a mask and the bits read 0, 1, 1, 0, 0, 1, 0, 0: the run of 1s is not at the front, and it is interrupted twice.

A mask has to be contiguous because of what it is used for. The router takes the address, applies the mask with a bitwise AND, and the result is the network address. That only produces a sensible, comparable network number if the 1 bits form one unbroken run from the left. A gapped mask would scatter the network identity across non-adjacent bits, and longest-prefix-match routing, which compares how many leading bits agree, would have nothing to compare.

If a device or a form accepted 255.255.255.100, what you almost certainly wanted was one of its neighbours. 255.255.255.128 is a /25 with 126 hosts, 255.255.255.192 is a /26 with 62 hosts. The calculator on this site rejects the invalid value and names the nearest valid mask rather than silently rounding.

The eight possible values of a partially masked octet, in binary
Octet valueBinaryNetwork bits in this octetExample prefix
0000000000/24 (fourth octet)
128100000001/25
192110000002/26
224111000003/27
240111100004/28
248111110005/29
252111111006/30
254111111107/31
255111111118/32

Any octet of a valid mask is one of these nine values. 100, 127, 200 and everything else are impossible, because they are not a run of leading 1s.

How to find your subnet mask

On Windows, run ipconfig and read the Subnet Mask line. On macOS or Linux, run ifconfig or ip addr; the mask appears as a prefix like /24 or as a dotted value. Your router's admin page also shows the LAN subnet mask, usually 255.255.255.0 for a home network.

Whatever form you find it in, you can paste it into the calculator to convert between the dotted mask and the prefix, and to see the host count it allows.

Frequently asked questions

What is the subnet mask 255.255.255.0?

255.255.255.0 is a /24 mask. It reserves the first three octets for the network and the last octet for hosts, giving 256 addresses with 254 usable.

How do I convert a subnet mask to a prefix?

Count the 1 bits in the mask. 255.255.255.0 has 24 ones, so it is /24. The subnet mask calculator does this conversion instantly in both directions.

What is a wildcard mask?

A wildcard mask is the bitwise inverse of a subnet mask, used in Cisco access lists. The inverse of 255.255.255.0 is 0.0.0.255. Use the wildcard mask calculator to convert.

Why are some masks invalid?

A valid subnet mask is a run of 1 bits followed by a run of 0 bits, with no gaps. A value like 255.0.255.0 has a gap, so it cannot be a standard subnet mask.

Sources

Everything technical on this page is checkable against the documents below. Where a document and common practice disagree, the guide says so rather than picking one quietly.

Spotted something wrong? Tell us and it gets corrected. How the data is maintained is described on the about page.