Loading learning content...
You see an IP address: 172.25.193.147/21. Without any tools, can you determine:
These calculations appear daunting but become intuitive with practice. This page provides the formulas, techniques, and shortcuts that transform subnet math from tedious binary conversion to rapid mental arithmetic.
By the end of this page, you will master: (1) Core subnetting formulas, (2) The binary AND method for calculating network addresses, (3) The magic number shortcut for rapid calculations, (4) Finding broadcast addresses and host ranges, and (5) Working through complex subnetting problems step-by-step.
Before diving into calculation techniques, commit these fundamental formulas to memory. They form the foundation of all subnet mathematics.
| Formula | Description | Example (/24) |
|---|---|---|
| 2^n | Number of subnets (n = borrowed bits) | 2^0 = 1 subnet |
| 2^h - 2 | Usable hosts per subnet (h = host bits) | 2^8 - 2 = 254 hosts |
| 32 - prefix | Number of host bits | 32 - 24 = 8 host bits |
| 256 - mask_octet | Block size (increment) | 256 - 0 = 256 |
| block × floor(addr/block) | Network address (per octet) | Varies |
| network + block - 1 | Broadcast address (per octet) | Varies |
The '-2' in the usable hosts formula accounts for two reserved addresses in every subnet: (1) The network address (all host bits = 0), which identifies the subnet itself, and (2) The broadcast address (all host bits = 1), which addresses all hosts in the subnet. These cannot be assigned to individual devices.
Powers of 2 Reference:
You'll use these constantly—memorize them:
| 2^n | Value | Corresponding Prefix |
|---|---|---|
| 2^0 | 1 | /32 (host route) |
| 2^1 | 2 | /31 (point-to-point) |
| 2^2 | 4 | /30 |
| 2^3 | 8 | /29 |
| 2^4 | 16 | /28 |
| 2^5 | 32 | /27 |
| 2^6 | 64 | /26 |
| 2^7 | 128 | /25 |
| 2^8 | 256 | /24 |
| 2^9 | 512 | /23 |
| 2^10 | 1,024 | /22 |
| 2^11 | 2,048 | /21 |
| 2^12 | 4,096 | /20 |
For usable hosts, subtract 2 from any value above (except /31 and /32 which are special cases).
The most reliable (though not fastest) method for finding the network address is the binary AND operation. This is what routers actually do internally.
Method:
Example: Find the network address for 192.168.47.197/26
Step 1: Convert IP to binary
192 = 11000000
168 = 10101000
47 = 00101111
197 = 11000101
IP: 11000000.10101000.00101111.11000101
Step 2: Convert mask to binary
/26 = 255.255.255.192
255 = 11111111
192 = 11000000
Mask: 11111111.11111111.11111111.11000000
Step 3: Perform AND operation
IP: 11000000.10101000.00101111.11000101
Mask: 11111111.11111111.11111111.11000000
──────────────────────────────────────────
AND: 11000000.10101000.00101111.11000000
Step 4: Convert back to decimal
11000000 = 192
10101000 = 168
00101111 = 47
11000000 = 192
Network Address: 192.168.47.192/26
The binary method is guaranteed to work but is slow for mental math. Use it when learning, when verifying answers, or when dealing with unusual prefix lengths. For common prefixes (/24, /25, /26, /27, /28, /29, /30), the magic number method is faster.
The magic number (also called block size or increment) method is the fastest technique for subnet calculations. It exploits the fact that subnets always start at specific, predictable boundaries.
Calculating the Magic Number:
Magic Number = 256 - (value of the interesting octet in the mask)
The interesting octet is the octet where the mask transitions from 255 to something else (where subnet/host bits meet).
Examples:
| Prefix | Mask | Interesting Octet | Magic Number |
|---|---|---|---|
| /25 | 255.255.255.128 | 4th (128) | 256 - 128 = 128 |
| /26 | 255.255.255.192 | 4th (192) | 256 - 192 = 64 |
| /27 | 255.255.255.224 | 4th (224) | 256 - 224 = 32 |
| /28 | 255.255.255.240 | 4th (240) | 256 - 240 = 16 |
| /29 | 255.255.255.248 | 4th (248) | 256 - 248 = 8 |
| /30 | 255.255.255.252 | 4th (252) | 256 - 252 = 4 |
| /22 | 255.255.252.0 | 3rd (252) | 256 - 252 = 4 |
| /20 | 255.255.240.0 | 3rd (240) | 256 - 240 = 16 |
Using the Magic Number to Find Network Address:
Subnet boundaries are always at multiples of the magic number in the interesting octet.
Example: 172.25.193.147/21
Finding the Broadcast Address:
Broadcast = Network + Magic Number - 1 (in the interesting octet)
Network: 172.25.192.0
Magic: 8
Broadcast (3rd octet): 192 + 8 - 1 = 199
Broadcast (4th octet): 255 (all host bits = 1)
Broadcast Address: 172.25.199.255
To find the largest multiple of the magic number ≤ your value: divide, drop the decimal, multiply back. For 193 ÷ 8 = 24.125 → floor to 24 → 24 × 8 = 192. This is the network address boundary.
Let's work through a complete subnetting problem, finding all relevant information.
Given: 10.172.50.68/19
Find:
Solution:
1. Subnet Mask:
2. Network Address (Magic Number Method):
3. Broadcast Address:
4. First Usable Host:
5. Last Usable Host:
6. Number of Usable Hosts:
7. Total Subnets (from /8):
| Parameter | Value |
|---|---|
| Given Address | 10.172.50.68/19 |
| Subnet Mask | 255.255.224.0 |
| Network Address | 10.172.32.0 |
| First Usable | 10.172.32.1 |
| Last Usable | 10.172.63.254 |
| Broadcast | 10.172.63.255 |
| Usable Hosts | 8,190 |
| Total /19 Subnets in /8 | 2,048 |
Work through these problems before checking the solutions. Apply the magic number method for speed.
Problem 1: 192.168.73.212/27
Find: Network, Broadcast, First Host, Last Host, Usable Hosts
Mask: 255.255.255.224 | Magic: 32 | 212 ÷ 32 = 6.625 → 6 × 32 = 192 | Network: 192.168.73.192 | Broadcast: 192.168.73.223 (192+32-1=223) | First: 192.168.73.193 | Last: 192.168.73.222 | Hosts: 2^5 - 2 = 30
Problem 2: 172.31.128.100/22
Find: Network, Broadcast, Valid Host Range, Usable Hosts
Mask: 255.255.252.0 | Magic: 4 (in 3rd octet) | 128 ÷ 4 = 32 → 32 × 4 = 128 | Network: 172.31.128.0 | Broadcast: 172.31.131.255 (128+4-1=131 in 3rd octet, 255 in 4th) | First: 172.31.128.1 | Last: 172.31.131.254 | Hosts: 2^10 - 2 = 1,022
Problem 3: 10.50.200.17/28
Find: Network, Broadcast, Subnet Mask, Number of /28s possible in 10.50.200.0/24
Mask: 255.255.255.240 | Magic: 16 | 17 ÷ 16 = 1.0625 → 1 × 16 = 16 | Network: 10.50.200.16 | Broadcast: 10.50.200.31 (16+16-1=31) | /28 in /24: 2^(28-24) = 2^4 = 16 subnets
Problem 4: 163.82.97.188/18
Find: Network, Broadcast, Which /18 subnet is this (numbered from 0)?
Mask: 255.255.192.0 | Magic: 64 (in 3rd octet) | 97 ÷ 64 = 1.515 → 1 × 64 = 64 | Network: 163.82.64.0 | Broadcast: 163.82.127.255 (64+64-1=127 in 3rd, 255 in 4th) | Subnet number: 1 (subnets: .0.0, .64.0, .128.0, .192.0 → this is the second = index 1)
A common calculation task is determining whether two IP addresses are on the same subnet. This is exactly what a host does when deciding whether to send traffic directly (ARP) or via the gateway.
Method:
Example: Are these hosts on the same /26 subnet?
Host A: 192.168.10.67 Host B: 192.168.10.100 Mask: /26 (255.255.255.192)
Calculate network for Host A:
Calculate network for Host B:
Comparison: 192.168.10.64 = 192.168.10.64 ✓
Result: Same subnet — Host A can reach Host B directly via Layer 2.
Counter-Example: Different subnets
Host C: 192.168.10.67/26 Host D: 192.168.10.130/26
Network C: Magic = 64, 67 ÷ 64 = 1.x → 64 → Network: 192.168.10.64 Network D: 130 ÷ 64 = 2.x → 128 → Network: 192.168.10.128
Comparison: 192.168.10.64 ≠ 192.168.10.128 ✗
Result: Different subnets — Host C must route through gateway to reach Host D.
If hosts have different subnet masks configured, they may disagree about whether they're on the same subnet. Host A with /24 might think Host B is local, while Host B with /26 thinks Host A is remote. This causes asymmetric routing and connectivity failures. Always ensure consistent mask configuration across a subnet.
Beyond basic network/broadcast calculations, you'll encounter more complex scenarios requiring additional techniques.
Finding the Nth Subnet:
Given a parent network, find the network address of the Nth subnet.
Example: What is the 25th /28 subnet within 10.0.0.0/8?
Solution:
Verification: Subnets 0-15 are in 10.0.0.x, subnets 16-31 are in 10.0.1.x. Subnet 24 is the 9th subnet in 10.0.1.x: 8 × 16 = 128 → 10.0.1.128 ✓
Calculating Address Utilization:
Example: An organization has 10.0.0.0/16 with the following allocations:
What percentage of addresses are allocated?
Solution:
Total in /16: 2^16 = 65,536 addresses
Allocated:
20 × /24: 20 × 256 = 5,120 addresses
50 × /28: 50 × 16 = 800 addresses
15 × /30: 15 × 4 = 60 addresses
Total allocated: 5,980 addresses
Utilization: 5,980 / 65,536 = 9.1%
This organization has ~91% of their address space available for growth—excellent planning!
To summarize contiguous subnets: find the common prefix bits. If you have 192.168.0.0/24 through 192.168.3.0/24 (4 subnets), the summary is 192.168.0.0/22 because the first 22 bits are identical across all four networks. Four /24s = one /22.
Keep this reference handy for rapid subnet calculations.
| Prefix | Mask Octet | Magic # | Subnets | Hosts/Net | Boundaries |
|---|---|---|---|---|---|
| /24 | 0 | 256 | 1 | 254 | 0 |
| /25 | 128 | 128 | 2 | 126 | 0, 128 |
| /26 | 192 | 64 | 4 | 62 | 0, 64, 128, 192 |
| /27 | 224 | 32 | 8 | 30 | 0, 32, 64, 96, 128, 160, 192, 224 |
| /28 | 240 | 16 | 16 | 14 | 0, 16, 32, ...240 |
| /29 | 248 | 8 | 32 | 6 | 0, 8, 16, ...248 |
| /30 | 252 | 4 | 64 | 2 | 0, 4, 8, ...252 |
What's Next:
You now have the mathematical tools for any fixed-length subnetting problem. But real networks often require subnets of different sizes. The next page covers Variable-Length Subnet Masking (VLSM)—the technique that allows different subnets to have different sizes, maximizing address efficiency.
You now possess the calculation skills to determine any subnet parameter from an IP/mask combination. The magic number method enables rapid mental math for most practical scenarios. Practice until these calculations become automatic—they'll serve you in exams, interviews, and daily network operations.