Subnet mask calculator
Enter a prefix length and read off everything that follows from it.
Usable hosts
254
- Total addresses
- 256
- Mask octet 1
- 255
- Mask octet 2
- 255
- Mask octet 3
- 255
- Mask octet 4
- 0
- Smallest prefix that fits your hosts
- 24
- This prefix is big enough
- 1
Show the working
- Prefix length = 24
- Hosts you need = 200
- host_bits = 32 - 24 = 8
- Total addresses = 2^8 = 256
- Usable hosts = 24 >= 31 ? (24 == 31 ? 2 : 1) : 256 - 2 = 254
- mask_value = 2^32 - 2^8 = 4 294 970 000
- Mask octet 1 = floor(4 294 970 000 / 2^24) = 255
- Mask octet 2 = floor(4 294 970 000 / 2^16) % 256 = 255
- Mask octet 3 = floor(4 294 970 000 / 2^8) % 256 = 255
- Mask octet 4 = 4 294 970 000 % 256 = 0
- needed_bits = ceil(log2(200 + 2)) = 8
- Smallest prefix that fits your hosts = clamp(32 - 8, 0, 32) = 24
- This prefix is big enough = 254 >= 200 ? 1 : 0 = 1
Values are shown to six significant figures here; the arithmetic itself runs on exact fractions and is only rounded where a number is printed.
Scenarios & local history
Compare a saved scenario
Recent calculations
The formula
- usable = 2^(32 - prefix) - 2
- prefix needed = 32 - ceil(log2(hosts + 2))