Skip to content
MasterMath

Subnet Calculator

Work out the mask, the address range and how many hosts fit in a subnet from an IP and its CIDR prefix.

Hosts it takes

—

Hosts it takes—
Subnet mask—
Network address—
Broadcast address—
First usable IP—
Last usable IP—
Total addresses—
Wildcard mask—
Address type—

How this was worked out

    The formula

    hosts = 2^(32 − prefix) − 2

    Where it comes from

    The prefix says how many bits identify the network; the rest identify each host. A /24 leaves 8 bits free, which is 256 addresses, less two: the first identifies the network and the last is the broadcast address.

    How to work it out by hand

    1. Subtract the prefix from 32 to see how many bits are left for hosts
    2. Raise 2 to that number: those are the total addresses
    3. Subtract 2 for the network and broadcast addresses
    4. The mask is as many ones as the prefix says, followed by zeros

    What is worth knowing

    Private addresses are the ones that are not routed over the internet and can be used freely on a local network: 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. The /31 and /32 prefixes are special cases: on point-to-point links no network or broadcast address is reserved, so every address is used.

    Frequently asked questions

    How many hosts fit in a /24?

    254. That is 256 addresses less the network and broadcast ones.

    What is a subnet mask?

    A bit pattern separating the network part from the host part. A /24 is 255.255.255.0.

    Which IP addresses are private?

    The ranges 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. They are not routed over the internet.

    Why are two addresses subtracted?

    The first identifies the whole network and the last is the broadcast address, which reaches every host at once. Neither can be assigned to a device.