Ad slot — header (728x90)

How to Subnet IPv4

Last reviewed: May 2026

Subnetting is the skill of dividing a large IP address block into smaller networks. It's tested on every networking certification (CCNA, JNCIA, CompTIA Network+) and used daily by network engineers and cloud architects. This guide teaches you two methods: binary subnetting (exact, great for understanding) and the magic number method (fast, great for exams and real work).

Verify your subnets instantly →

Prerequisites: IPv4 Addressing Basics

An IPv4 address is 32 bits written as four decimal octets, e.g. 192.168.10.5. Every address has two parts:

The subnet mask (or CIDR prefix) divides the address into these two parts. All addresses with the same network portion are in the same subnet.

Method 1: The Magic Number Method (Fast)

The magic number method lets you find subnet ranges without binary math. It works in the "interesting octet" — the octet where the network-to-host boundary falls.

1 Find the interesting octet
Look at the subnet mask. The interesting octet is the one that is neither 255 (all network bits) nor 0 (all host bits).
Example: mask 255.255.255.192 — the fourth octet (192) is interesting.
2 Calculate the magic number
Magic number = 256 − interesting octet
Example: 256 − 192 = 64. Subnets increment by 64 in the fourth octet.
3 List the subnet boundaries
Starting from 0, add the magic number repeatedly: 0, 64, 128, 192, 256 (stop when you exceed 255).
These are your network addresses: .0, .64, .128, .192.
4 Find host range and broadcast for each subnet
Network address + 1 = first host. Next network address − 1 = broadcast.
Example for .0/26: hosts .1–.62, broadcast .63.

Worked Example: Divide 192.168.1.0/24 into /26 subnets

Mask: 255.255.255.192. Interesting octet: 4th. Magic number: 256 − 192 = 64.

SubnetNetworkFirst HostLast HostBroadcastUsable
#1192.168.1.0192.168.1.1192.168.1.62192.168.1.6362
#2192.168.1.64192.168.1.65192.168.1.126192.168.1.12762
#3192.168.1.128192.168.1.129192.168.1.190192.168.1.19162
#4192.168.1.192192.168.1.193192.168.1.254192.168.1.25562

Method 2: Binary Subnetting (Exact)

Binary subnetting converts everything to bits. It's slower but builds deep understanding of how subnetting actually works.

Worked Example: Find the subnet for host 10.0.52.130/20

1 Write the IP address in binary
10.0.52.130 → 00001010.00000000.00110100.10000010
2 Write the subnet mask in binary (/20 = 20 ones, 12 zeros)
11111111.11111111.11110000.00000000
3 AND the IP with the mask to get the network address
IP: 00001010.00000000.00110100.10000010 Mask: 11111111.11111111.11110000.00000000 AND: 00001010.00000000.00110000.00000000 = 10.0.48.0
Network address: 10.0.48.0
4 Find the broadcast (flip all host bits to 1)
00001010.00000000.00111111.11111111 = 10.0.63.255
Broadcast: 10.0.63.255. Host range: 10.0.48.1 – 10.0.63.254.

The Subnetting Formula

These three formulas cover every subnetting question:

What to findFormulaExample (/26)
Number of subnets from a /N split into /M2(M−N)/24 → /26: 22 = 4 subnets
Total host addresses per subnet2(32−M)/26: 26 = 64 addresses
Usable host addresses per subnet2(32−M) − 2/26: 64 − 2 = 62 hosts

VLSM — Variable Length Subnet Masking

VLSM lets you assign different-sized subnets to different segments, matching subnet size to actual need. This is how real networks are designed.

VLSM Rule: Always subnet largest-first

Allocate the biggest subnet first. Starting with the largest block prevents fragmentation and ensures each subnet stays within the parent block.

VLSM Example: Divide 10.1.0.0/24 for these requirements

Step 1 — Find minimum subnet sizes (need 2n − 2 ≥ required hosts):

SegmentHosts NeededSubnet SizeUsable Hosts
Floor 1 LAN100/25126
Floor 2 LAN50/2662
Server VLAN20/2730
Management6/296
WAN link2/302

Step 2 — Assign largest-first from 10.1.0.0/24:

SegmentAssigned CIDRRangeUsed / Avail
Floor 1 LAN10.1.0.0/2510.1.0.1 – 10.1.0.126100 / 126
Floor 2 LAN10.1.0.128/2610.1.0.129 – 10.1.0.19050 / 62
Server VLAN10.1.0.192/2710.1.0.193 – 10.1.0.22220 / 30
Management10.1.0.224/2910.1.0.225 – 10.1.0.2306 / 6
WAN link10.1.0.232/3010.1.0.233 – 10.1.0.2342 / 2

Total used: 10.1.0.0–10.1.0.235. Remaining: 10.1.0.236–10.1.0.255 (20 addresses for future growth).

Common Subnetting Mistakes

Quick Reference: Subnet Sizes and Block Increments

CIDRMask (last 2 octets)Magic Number (4th octet)Block SizeUsable Hosts
/24.255.0256256254
/25.255.128128128126
/26.255.192646462
/27.255.224323230
/28.255.240161614
/29.255.248886
/30.255.252442
Practice subnetting with SubnetSolver →

Related Guides

Ad slot — footer (728x90)