How an IPv4 network is divided

An IPv4 address is a 32-bit number written as four groups of eight. The prefix, the number after the slash, says how many of those bits identify the network; the rest number the devices inside it. A /24 leaves 8 bits for hosts, which is 256 addresses, 254 of them usable.

The two excluded addresses are the first, which names the network itself, and the last, the broadcast, which reaches every host at once. The exceptions are /31 networks, used for point-to-point links, where both addresses are hosts, and /32, which names a single device.

The network address is a bitwise AND of address and mask; the broadcast is an OR of network and wildcard. It is all arithmetic on bits, which is why seeing the address in binary makes it obvious where the line between network and host falls.

Common mistakes

  • Counting the network and broadcast addresses as usable hosts: a /26 has 64 addresses but only 62 hosts.
  • Writing a mask with ones and zeros mixed, like 255.255.0.255: a valid mask has all its ones on the left.
  • Confusing an ACL wildcard with the mask: the wildcard is its complement, 0.0.0.255 for a /24.

Frequently asked questions

How many hosts are in a /24, /25, /26 subnet?

A /24 has 254 hosts, a /25 126, a /26 62, a /27 30, a /28 14, a /29 6 and a /30 2. In general it is 2 to the power of the host bits, minus 2.

What are private addresses?

The blocks 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16, reserved for internal networks and not routed on the Internet. They reach it through the router's NAT.

Are classes A, B and C still used?

No, since 1993 routing uses CIDR with prefixes of any length. The class is only useful for exercises and to understand the old default masks.

How this calculation works

Mask = prefix ones followed by 32 − prefix zeros. Network = address AND mask. Wildcard = NOT mask. Broadcast = network OR wildcard. Total addresses = 2^(32 − prefix). Usable hosts = total − 2, except /31 (2) and /32 (1).