How IPv4 Subnetting Works: A Practical Guide With Worked Examples

Addressing and subnetting · Last updated 12 October 2026 · 6 min read

Learn to find the network, broadcast, and host range of any IPv4 address by hand, size subnets for a given number of hosts, and split a network into equal or variable-sized pieces.

Why subnet at all?

A flat network with thousands of devices on one broadcast domain wastes bandwidth, is hard to secure, and cannot be routed sensibly. Subnetting divides an address block into smaller networks so that you can place a router or firewall between groups of devices, limit how far broadcast traffic travels, give each department or VLAN its own address range, and avoid handing out more addresses than you need.

Everything in this guide comes down to one skill: given an address and a prefix length, work out which subnet it belongs to and what that subnet contains. Once you can do that, planning an address scheme is just repeating it. You can check each step with the Subnet Calculator.

The building blocks: address, mask, prefix

An IPv4 address is a 32-bit number, written as four 8-bit octets (for example 192.168.10.77). A subnet mask splits it in two: leading 1 bits mark the network portion, trailing 0 bits mark the host portion. The prefix length is the count of 1 bits, so 255.255.255.192 is written /26.

The network address is the address with every host bit set to 0; the broadcast address is the address with every host bit set to 1; the usable host addresses are everything in between. With h host bits, a subnet holds 2h addresses and 2h − 2 usable hosts. The binary view is useful at first; the IPv4 ↔ Binary Converter shows it for any address.

Prefix  Total addresses  Usable hosts
/24    256      254
/25    128      126
/26     64       62
/27     32       30
/28     16       14
/29      8        6
/30      4        2

Memorize the doubling pattern rather than the table: each bit you take from the host side halves the subnet.

The block-size method

You can find a subnet by hand without converting to binary. Work in the octet where the mask stops being 255 (the "interesting octet").

  1. Count the host bits: 32 minus the prefix.
  2. Work out the block size in the interesting octet: 256 minus the mask's value in that octet (or 2 to the power of the host bits that fall in that octet).
  3. List the multiples of the block size: these are the network addresses in that octet.
  4. Find the multiple that is less than or equal to your address's octet. That is the network address.
  5. The broadcast is one less than the next multiple. The usable range is network + 1 through broadcast − 1.

Worked example 1: 192.168.10.77/26

The mask for a /26 is 255.255.255.192, so the interesting octet is the fourth. The block size is 256 − 192 = 64, so networks in the fourth octet start at 0, 64, 128, and 192. The address's fourth octet is 77, and the largest multiple not exceeding 77 is 64. The answer:

Network:    192.168.10.64
First host: 192.168.10.65
Last host:  192.168.10.126
Broadcast:  192.168.10.127
Usable:     62

Check in binary: 77 is 01001101; the mask's last octet 192 is 11000000; ANDing gives 01000000, which is 64. A host at 192.168.10.130 belongs to the next block (128–191) and must go through a router to reach this subnet.

Worked example 2: a subnet that crosses an octet (172.16.5.130/23)

When the prefix is not on an octet boundary in the last octet, the interesting octet moves. A /23 has mask 255.255.254.0, so the third octet is the interesting one: 256 − 254 = 2. Networks begin at even third-octet values (0, 2, 4, 6, ...). The address has a third octet of 5; the largest multiple of 2 not exceeding 5 is 4.

Network:    172.16.4.0
First host: 172.16.4.1
Last host:  172.16.5.254
Broadcast:  172.16.5.255
Usable:     510

The broadcast is 172.16.5.255, not 172.16.4.255: the subnet spans two /24-sized ranges, and its last address has the whole fourth octet set to 255 and the third octet at 5. Subnets larger than /24 are where assuming ".0 is the network and .255 is the broadcast" goes wrong.

Choosing a prefix for a number of hosts

Count the devices you need now plus a growth allowance, then add the network address, broadcast address, and gateway. Pick the smallest block that fits. For example, 50 hosts do not fit in a /27 (30 usable) but fit in a /26 (62 usable). The next-larger block always has roughly twice the room, so rounding up is cheap insurance.

Remember that some platforms reserve extra addresses in every subnet (cloud networks commonly do), so the practical usable count can be smaller than the arithmetic result.

Splitting a network into equal subnets

Splitting a /24 into four equal subnets means borrowing two host bits (22 = 4), which gives a /26. Each subnet has 64 addresses:

Subnet 1: 192.168.1.0/26   hosts 192.168.1.1 - 192.168.1.62   broadcast 192.168.1.63
Subnet 2: 192.168.1.64/26   hosts 192.168.1.65 - 192.168.1.126   broadcast 192.168.1.127
Subnet 3: 192.168.1.128/26   hosts 192.168.1.129 - 192.168.1.190   broadcast 192.168.1.191
Subnet 4: 192.168.1.192/26   hosts 192.168.1.193 - 192.168.1.254   broadcast 192.168.1.255

Borrowing one bit gives two subnets, two bits give four, three bits give eight, and so on. The number of subnets doubles, and the size of each halves, every time.

Variable-length subnets (VLSM)

Real networks need different-sized subnets: a server VLAN might need 100 hosts while a point-to-point link needs two. VLSM allocates a different prefix to each. The method: sort requirements from largest to smallest, give each the smallest block that fits, and place each block on a boundary that is a multiple of its own size. For 192.168.10.0/24 with requirements of 100, 50, 25 and 10 hosts:

Sales        /25  192.168.10.0    hosts 192.168.10.1 - 192.168.10.126
Engineering  /26  192.168.10.128  hosts 192.168.10.129 - 192.168.10.190
Support      /27  192.168.10.192  hosts 192.168.10.193 - 192.168.10.222
Guest        /28  192.168.10.224  hosts 192.168.10.225 - 192.168.10.238
Unallocated addresses remaining: 16

Allocating largest-first keeps each block aligned and avoids gaps. Placing the 10-host subnet first would force the 100-host block to start at a larger offset and could leave it without room. The VLSM Calculator does this and reports when a plan cannot fit.

Special cases and reserved ranges

  • /31 — two addresses, both usable on a point-to-point link (RFC 3021). Support varies; confirm both devices handle it. /32 is a single host route. Neither has a network or broadcast address in the usual sense.
  • Private ranges (RFC 1918): 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16. These are not routed on the public internet.
  • Other special blocks: 127.0.0.0/8 loopback, 169.254.0.0/16 link-local (what a device assigns itself when DHCP fails), and 100.64.0.0/10 used by carrier-grade NAT. The IANA special-purpose registry lists them all.

Common mistakes

  • Forgetting the minus two, and counting the network and broadcast addresses as usable hosts.
  • Misaligned subnets. A /26 cannot start at .32; it must start at a multiple of 64.
  • Mismatched masks. Two hosts on the same cable with different masks disagree about who is local, so one can reach the other but not the reverse.
  • Overlapping subnets in different parts of a network, which breaks routing in confusing ways. Always document allocations.
  • Using a host address as a route. Write 192.168.10.64/26 in a route, not 192.168.10.77/26; some systems accept the latter and others reject it.
  • Confusing wildcard and subnet masks in ACLs. See the Wildcard Mask Calculator.

Practicing and verifying

Pick random addresses and prefixes, work them out by hand with the block-size method, and then check them with the Subnet Calculator. If your answer differs, look at the binary form to see which step went wrong. Once the method is automatic, move on to CIDR notation and route summarization.

Tools used in this guide

  • IPv4 Subnet Calculator — Calculate network, broadcast, usable range, mask, and wildcard from an IP + CIDR or subnet mask.
  • VLSM Calculator — Allocate variable-length subnets from a base network to meet multiple host-count requirements.
  • IPv4 ↔ Binary Converter — Convert an IPv4 address to its 32-bit binary form and back again, octet by octet.
  • CIDR Calculator — Break down a CIDR block into its network details, plus a full CIDR reference table.

References and further reading

References are primary sources (standards and official documentation). Commands and sample output are illustrative; behavior can vary by operating system and software version.

Keep reading