Skip to content
Subnet Math

IPv4 subnet calculator

Enter an IPv4 address and either a prefix length or a subnet mask. You get the network address, the broadcast address, the first and last usable host, the mask and wildcard, how many addresses the subnet holds and the binary behind every step.

For example 192.168.1.10, or 192.168.1.10/24 to fill both fields at once.

For example 24, /24 or 255.255.255.0.

Example: 192.168.1.0/24 has 254 usable addresses

192.168.1.10 is in the subnet 192.168.1.0/24, mask 255.255.255.0. Usable hosts run from 192.168.1.1 to 192.168.1.254.

Network address 192.168.1.0
Broadcast address 192.168.1.255
First usable host 192.168.1.1
Last usable host 192.168.1.254
Subnet mask 255.255.255.0
Wildcard mask 0.0.0.255
Prefix length /24
Total addresses 256
Usable hosts 254
Address type Private (192.168.0.0/16, RFC 1918)

The same in binary

Address 11000000.10101000.00000001.00001010
Subnet mask 11111111.11111111.11111111.00000000
Network (address AND mask) 11000000.10101000.00000001.00000000
Broadcast (network OR wildcard) 11000000.10101000.00000001.11111111

This is address arithmetic from the IPv4 and IPv6 standards. It shows how a block divides up; it does not plan, configure or protect a network.

The formula, with a worked example

What the results mean

An IPv4 address is 32 bits, written as four numbers from 0 to 255. The prefix length says how many of those bits, counted from the left, name the network. The rest name a host inside it. In 192.168.1.10/24 the first 24 bits (192.168.1) are the network part and the last 8 bits (.10) are the host part.

The network address is the first address of the subnet, with every host bit set to 0. The broadcast address is the last, with every host bit set to 1; a packet sent there goes to every host on the subnet. Everything in between is the usable host range, the addresses that can be given to devices. The subnet mask and the wildcard mask are two ways of writing the same split: the mask has ones over the network bits, and the wildcard has ones over the host bits.

The address type line says whether the address sits in one of the special-purpose ranges listed by IANA, such as the private ranges from RFC 1918 or the documentation ranges used in examples. Anything outside them is shown as public.

Working it out by hand, step by step

Take 10.20.30.40/22. A /22 mask is 22 ones and 10 zeros: 11111111.11111111.11111100.00000000, which is 255.255.252.0. Only the third number is split, so only the third number needs real work. 30 in binary is 00011110. AND it with the mask byte 11111100 and you get 00011100, which is 28. The network address is 10.20.28.0.

The block size in the third number is 256 − 252 = 4, so this subnet covers 28, 29, 30 and 31 in that position. The broadcast address is therefore 10.20.31.255, the usable range runs from 10.20.28.1 to 10.20.31.254, and the subnet holds 2^10 = 1,024 addresses, 1,022 of them usable.

That "256 minus the mask number" shortcut works for any prefix. In the octet where the mask stops being 255, subtract the mask value from 256 to get the block size, then find the multiple of the block size at or below the address's value in that octet. That multiple is where the network starts.

Prefix length or subnet mask: either works

The second field takes a prefix length (24 or /24) or a dotted mask (255.255.255.0). They mean the same thing. A valid mask is always a run of ones followed by a run of zeros, so the only numbers that can appear in a mask are 0, 128, 192, 224, 240, 248, 252, 254 and 255, and once one octet is below 255 every octet after it is 0. A mask like 255.0.255.0 has gaps, and the calculator says so instead of guessing.

You can also type the whole thing in CIDR notation in the first field, for example 172.16.5.130/26. The prefix after the slash then wins over whatever is in the second field.

Edge cases: /31, /32, /0 and the special ranges

A /31 holds two addresses. Under the old rule both would be lost to the network and broadcast addresses, leaving none for hosts. RFC 3021 lets both addresses be used on a point-to-point link, so the calculator counts 2 usable addresses and shows the range as the whole block. For 203.0.113.7/31 that is 203.0.113.6 to 203.0.113.7.

A /32 is a single address on its own, sometimes called a host route. The network, broadcast, first and last address are all the same, and it counts as 1 usable address. At the other end, a /0 covers every IPv4 address, all 4,294,967,296 of them, with a mask of 0.0.0.0.

The address type is a label from the IANA registry, nothing more. 100.64.0.0/10, for example, is shared address space set aside for carrier-grade NAT, and 169.254.0.0/16 is link-local, the range a device picks from when it has no other address.

Reference: prefixes /16 to /32

Prefix Subnet mask Wildcard Total addresses Usable hosts
/16 255.255.0.0 0.0.255.255 65,536 65,534
/17 255.255.128.0 0.0.127.255 32,768 32,766
/18 255.255.192.0 0.0.63.255 16,384 16,382
/19 255.255.224.0 0.0.31.255 8,192 8,190
/20 255.255.240.0 0.0.15.255 4,096 4,094
/21 255.255.248.0 0.0.7.255 2,048 2,046
/22 255.255.252.0 0.0.3.255 1,024 1,022
/23 255.255.254.0 0.0.1.255 512 510
/24 255.255.255.0 0.0.0.255 256 254
/25 255.255.255.128 0.0.0.127 128 126
/26 255.255.255.192 0.0.0.63 64 62
/27 255.255.255.224 0.0.0.31 32 30
/28 255.255.255.240 0.0.0.15 16 14
/29 255.255.255.248 0.0.0.7 8 6
/30 255.255.255.252 0.0.0.3 4 2
/31 255.255.255.254 0.0.0.1 2 2
/32 255.255.255.255 0.0.0.0 1 1

Frequently asked questions

How many usable hosts are in a /24?

A /24 has 256 addresses. Take away the network address and the broadcast address and 254 are usable. In 192.168.1.0/24 they run from 192.168.1.1 to 192.168.1.254.

What is the subnet mask for /24?

255.255.255.0. Twenty-four ones fill the first three octets (255 each) and the last octet is all zeros. The wildcard mask, its opposite, is 0.0.0.255.

How do I find the network address from an IP and mask?

AND each octet of the address with the same octet of the mask. Where the mask is 255 the address octet stays as it is, and where it is 0 the result is 0. For a partial octet, AND the two in binary, or round the address down to the nearest multiple of 256 minus the mask value.

Why are two addresses subtracted from the host count?

The first address of a subnet (all host bits 0) names the network itself and the last (all host bits 1) is the broadcast address. Neither is given to a device, so usable hosts are 2^(32 − prefix) − 2. The exceptions are /31, which counts 2 under RFC 3021, and /32, which counts 1.

What is a wildcard mask?

The subnet mask with every bit flipped. Where the mask has a one the wildcard has a zero, and the other way round, so a /24 mask of 255.255.255.0 becomes 0.0.0.255. Each octet of the wildcard is 255 minus the same octet of the mask. Some router software writes address ranges with a wildcard instead of a mask.

Is 192.168.1.10 a private address?

Yes. 192.168.0.0/16 is one of the three private ranges in RFC 1918, along with 10.0.0.0/8 and 172.16.0.0/12. Addresses in these ranges are not routed on the public internet.

Need to cut this block into smaller pieces? The subnet divider splits it by subnet count or by hosts per subnet. Subnet divider

Other subnet tools on this site