IPv4 Subnetting Guide
Subnetting is the practice of dividing a larger IP network into smaller, more efficient sub-networks. It lets you control broadcast domain size, conserve addresses, apply security policy at the network boundary, and summarize routes. This guide walks through the mechanics from first principles so you can subnet by hand and verify with the subnet calculator.
The 32-bit IPv4 address
An IPv4 address is 32 bits, written as four decimal octets separated by dots. Each octet represents 8 bits, so each ranges from 0 to 255. The address is split into two parts: the network prefix (shared by every host in the subnet) and the host portion (unique within the subnet). A subnet mask or CIDR prefix tells you where that split happens.
192.168.1.130 / 255.255.255.0 (or /24)
Binary:
11000000.10101000.00000001.10000010
^^^^^^^^ ^^^^^^^^ ^^^^^^^^ ← network prefix (24 bits)
^^^^^^^^ ← host portion (8 bits)Reading a subnet mask
A subnet mask is a 32-bit value where contiguous 1-bits mark the network portion and contiguous 0-bits mark the host portion. Masks must be contiguous — 255.255.255.0 is valid, 255.0.255.0 is not. The CIDR prefix is simply the count of 1-bits, written as /24.
| CIDR | Subnet mask | Binary |
|---|---|---|
| /24 | 255.255.255.0 | 11111111.11111111.11111111.00000000 |
| /25 | 255.255.255.128 | 11111111.11111111.11111111.10000000 |
| /26 | 255.255.255.192 | 11111111.11111111.11111111.11000000 |
| /30 | 255.255.255.252 | 11111111.11111111.11111111.11111100 |
The four addresses you must find
For any subnet, four values matter:
- Network address — host bits all 0. The subnet itself.
- First usable host — network address + 1.
- Broadcast address — host bits all 1. Last address in the subnet.
- Last usable host — broadcast address − 1.
Worked example: 192.168.1.130/26
A /26 leaves 6 host bits (32 − 26 = 6), so each subnet has 2⁶ = 64 addresses. The block size is 64. Find which block 192.168.1.130 falls in: 130 ÷ 64 = 2 with remainder 2, so the network address is 192.168.1.128.
Network: 192.168.1.128 (host bits 000000)
First host: 192.168.1.129
Last host: 192.168.1.190
Broadcast: 192.168.1.191 (host bits 111111)
Usable hosts: 64 - 2 = 62The core formulas
| Quantity | Formula |
|---|---|
| Host bits | h = 32 − prefix |
| Total addresses | 2^h |
| Usable hosts | 2^h − 2 (except /31 and /32) |
| Subnet count (from a larger block) | 2^(new_prefix − old_prefix) |
| Block size (last octet) | 256 − last_octet_of_mask |
Subnetting a /24 into smaller pieces
A common task: take 192.168.1.0/24 and carve it into /26s. Each /26 borrows 2 bits from the host portion (26 − 24 = 2), producing 2² = 4 subnets of 64 addresses each.
| Subnet | Network | Usable range | Broadcast |
|---|---|---|---|
| 1 | 192.168.1.0 | .1 – .62 | .63 |
| 2 | 192.168.1.64 | .65 – .126 | .127 |
| 3 | 192.168.1.128 | .129 – .190 | .191 |
| 4 | 192.168.1.192 | .193 – .254 | .255 |
Configuration snippets
Cisco IOS interface
interface GigabitEthernet0/0
description User VLAN
ip address 192.168.1.130 255.255.255.192
no shutdownLinux (iproute2)
ip addr add 192.168.1.130/26 dev eth0
ip link set eth0 upCommon pitfalls
- Forgetting the broadcast — the all-ones host address is reserved, not assignable.
- Miscounting on non-octet boundaries — a /23 spans 512 addresses across two octets; the block size is 512, not 256.
- Overlapping subnets — when carving, always start the next block at the previous broadcast + 1.
- Using .0 or .255 blindly — these are only network/broadcast on a /24. On a /26, .128 and .191 are the reserved ones.
Verify your work
Manual subnetting is error-prone under time pressure. Use the subnet calculator to check your math, the CIDR calculator for prefix conversions, and the DHCP scope calculator when laying out pools. For multi-subnet planning, use the VLSM calculator, and verify your design with the subnet overlap checker. For a quick reference of every prefix, see the subnetting cheat sheet or the CIDR cheat sheet.
Related guides
- CIDR Explained — how slash notation replaced classful addressing
- VLSM Explained — mixing subnet sizes in one network
- How Many Hosts Are in a /24?
- How to Choose a Subnet Size