Timedora

2 Subnet and Host Range Calculations

Learn how IPv4 prefixes and subnet masks determine subnet boundaries, address counts, usable host ranges, and subnet membership, including prefix-specific exceptions.

IPv4 prefixes and masks

An IPv4 address is 3232 bits and is usually written as four decimal octets, such as 192.168.1.77. A such as /26/26 specifies how many leading bits identify the network; the remaining bits identify addresses within that network. CIDR uses this prefix length instead of the older address classes.

A prefix /p/p has pp network bits and 32−p32-p host bits. Its consists of pp leading 11 bits followed by 00 bits.

Address counts and block sizes

The total number of addresses in a prefix is determined by its host-bit count:

232−p2^{32-p}

For ordinary subnets from /0/0 through /30/30, the number of usable host addresses is typically:

232−p−22^{32-p}-2

The two excluded addresses are the , where all host bits are 00, and the directed , where all host bits are 11. For example, a /26/26 contains 6464 total addresses and typically 6262 usable host addresses.

To find the by hand, locate the first mask octet that is not 255 and subtract its value from 256256. For /26/26, the last mask octet is 192, so the is 256−192=64256-192=64. The subnet boundaries in that octet are 00, 6464, 128128, and 192192.

Finding subnet and host ranges

To find a subnet's , , and :

  1. Find the and .

  2. Locate the block containing the given address. The block's first address is the .

  3. Identify the block's last address; it is the .

  4. For an ordinary subnet, the runs from one address after the to one address before the .

For 192.168.1.77/26, the mask is 255.255.255.192, and the in the last octet is 6464. The blocks are .0–.63, .64–.127, .128–.191, and .192–.255. Since .77 falls in .64–.127, the is 192.168.1.64, the is 192.168.1.127, and the is 192.168.1.65–192.168.1.126, containing 6262 addresses.

A prefix can cross an octet boundary. For 172.16.35.123/20, the mask is 255.255.240.0. The in the third octet is 256−240=16256-240=16; the third-octet blocks include 16–3116–31, 32–4732–47, and 48–6348–63. Because 3535 is in 32–4732–47, the is 172.16.32.0, the is 172.16.47.255, and the is 172.16.32.1–172.16.47.254. This prefix has 212=40962^{12}=4096 total addresses and typically 40944094 usable hosts.

Subnet size and splitting a block

A longer prefix leaves fewer host bits and therefore creates smaller subnets. Splitting a /24/24 into /27/27 subnets borrows 33 bits, creating 23=82^3=8 subnets. Each /27/27 has 25=322^5=32 total addresses and typically 3030 usable host addresses.

Under modern subnetting practice, all definable subnets are usable, including the first and last.

Checking

An address belongs to a subnet if applying the to it produces that subnet's . In bitwise notation:

address∧mask=network address\text{address} \land \text{mask} = \text{network address}

Another way to check is to see whether the address falls between the subnet's network and broadcast addresses, inclusive. For example, 192.168.1.100 belongs to 192.168.1.64/26 because it falls within .64–.127; 192.168.1.130 does not.

Special prefixes

The usual rule of subtracting 22 from the total address count has exceptions. A /31/31 is used on point-to-point links, where both addresses are interpreted as host addresses and there is no conventional network/broadcast exclusion. A /32/32 identifies one address and is commonly used as a host route.