← All guides

IPv4 subnetting explained

A subnet is a block of addresses that share the same leading bits. Once you can read a prefix like /24, every other number follows from it.

What a subnet is

An IPv4 address is 32 bits, written as four numbers from 0 to 255: 192.168.1.10. A subnet is a contiguous range of those addresses whose first bits — the network prefix — are the same.

Devices in the same subnet reach each other directly. Traffic for any other subnet goes through a router.

CIDR notation and the subnet mask

10.0.0.0/24 means the first 24 bits identify the network and the remaining 8 bits identify hosts inside it. That is 2⁸ = 256 addresses.

The subnet mask says the same thing in address form: 24 one-bits followed by 8 zero-bits, written 255.255.255.0. Prefix and mask are interchangeable.

Each bit you remove from the prefix doubles the block; each bit you add halves it.

Prefix sizes at a glance

Usable hosts is the address count minus two, for the reasons in the next section — except for /31 and /32.

PrefixSubnet maskAddressesUsable hosts
/16255.255.0.065,53665,534
/20255.255.240.04,0964,094
/22255.255.252.01,0241,022
/23255.255.254.0512510
/24255.255.255.0256254
/25255.255.255.128128126
/26255.255.255.1926462
/27255.255.255.2243230
/28255.255.255.2401614
/29255.255.255.24886
/30255.255.255.25242
/31255.255.255.25422
/32255.255.255.25511

Network and broadcast addresses

In a classic subnet, two addresses are never given to a host. The first one, with all host bits at zero, names the network itself. The last one, with all host bits at one, is the broadcast address that reaches every host at once.

Two exceptions: a /31 has only two addresses, and on point-to-point links both are used for the two ends (RFC 3021). A /32 is a single address, used for one host or a loopback.

Splitting a network

Splitting a subnet adds one bit to its prefix and gives two halves of equal size. Split one half again and you have quarters, while the other half stays whole.

Subnets in a plan do not have to be the same size. Each one simply has to start on a multiple of its own size, which splitting guarantees. Here 10.0.0.0/24 is split once, then its upper half again:

SubnetUsable rangeUsable hosts
10.0.0.0/2510.0.0.1 – 10.0.0.126126
10.0.0.128/2610.0.0.129 – 10.0.0.19062
10.0.0.192/2610.0.0.193 – 10.0.0.25462

Choosing a size

  1. Count the addresses you need now, including gateways, load balancers and other infrastructure.
  2. Add room for growth. Renumbering later is far harder than leaving space now.
  3. Pick the smallest prefix whose usable count covers the total, from the table above.
  4. In the cloud, subtract the provider’s reserved addresses before deciding.

Subnets in the cloud

Cloud providers keep more than two addresses in every subnet, for the router, DNS and future use, and some set a minimum subnet size. Reserved IP addresses in cloud subnets has each provider’s rules.

Plan a network in the Subnet Calculator