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.

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.

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.