Networking Fundamentals 7 min read · Last verified 2026-11-25

How to Subnet IPv4 in Your Head: The Step-by-Step Binary & Magic Number Guide

Almost every computer networking student hits a wall the first time an instructor writes 172.16.45.73/26 on the whiteboard and asks for the network address, broadcast address, and usable host range without a calculator. The good news is that IPv4 subnetting is pure powers of twoβ€”once you understand the 32-bit binary split and the 10-second Magic Number shortcut, you can solve any prefix from /8 to /30 reliably in your head.

Primary References: RFC 4632 (CIDR), RFC 3021 (/31 Links), RFC 1918 Private Ranges · Author: NetDevKit Engineering Team

1. The One Binary Rule Behind Every Subnet Mask

An IPv4 address is 32 bits long, grouped into four 8-bit octets (each decimal number from 0 to 255). The CIDR prefixβ€”such as /26β€”simply tells you how many leading bits belong to the network portion, while the remaining 32 - prefix bits identify individual hosts inside that subnet. In a /26 network, the first 26 bits are locked as the network ID and the final 6 bits vary from all 0s (network address) to all 1s (broadcast address).

Because each octet holds 8 bits, prefixes /8, /16, and /24 land cleanly on dot boundaries. For every other prefix, only one 'interesting octet' is split between network bits and host bits. Finding that single octet immediately reduces a 32-bit problem to simple arithmetic between 0 and 255.

CIDR Interesting Octet Mask Octet Value Magic Number (Block Size) Usable RFC Hosts
/25 4th octet 128 256 - 128 = 128 126
/26 4th octet 192 256 - 192 = 64 62
/27 4th octet 224 256 - 224 = 32 30
/28 4th octet 240 256 - 240 = 16 14 (AWS: 11)
/29 4th octet 248 256 - 248 = 8 6 (GCP: 4)
/30 4th octet 252 256 - 252 = 4 2

2. The 4-Step Magic Number Method (Worked Example: 172.16.45.73/26)

Step 1 β€” Convert /26 to its dotted subnet mask: 26 ones fill the first three octets (255.255.255) plus 2 bits in the fourth octet (128 + 64 = 192), giving 255.255.255.192. Step 2 β€” Compute the Magic Number (block size): subtract the non-255 octet from 256, so 256 - 192 = 64. That tells you subnets step by multiples of 64 in the fourth octet: 0, 64, 128, 192.

Step 3 β€” Bracket the host octet (73): 73 falls between 64 and 128, so the network address is 172.16.45.64 and the next subnet starts at 172.16.45.128. Step 4 β€” Subtract 1 from the next subnet to get the broadcast address (172.16.45.127). The assignable RFC host range sits strictly between them: 172.16.45.65 through 172.16.45.126 (62 usable hosts).

Address:   172.16.45.73/26  ->  Mask: 255.255.255.192
4th Octet: 73  =  01 | 001001  (2 network bits | 6 host bits)
Block Size:       256 - 192 = 64  (multiples: 0, 64, 128, 192)
Network ID:       172.16.45.64    (01 | 000000)
First Usable:     172.16.45.65    (01 | 000001)
Last Usable:      172.16.45.126   (01 | 111110)
Broadcast ID:     172.16.45.127   (01 | 111111)
Usable Hosts:     2^6 - 2 = 62

3. Solving Class B & Class A Prefixes (/17 to /23) with the Exact Same Shortcut

Students often panic when a prefix like /22 or /20 lands in the third octet instead of the fourth. Nothing changes except which octet steps by the Magic Number, while every octet to the right resets to 0 for the network address and 255 for the broadcast address.

Take 10.20.30.41/22: 22 ones equal 8 + 8 + 6 bits, so the third-octet mask is 252 and the Magic Number is 256 - 252 = 4. Multiples of 4 in the third octet are 0, 4, 8 ... 24, 28, 32. Because 30 lies between 28 and 32, the network address is 10.20.28.0, the next subnet is 10.20.32.0, and the broadcast address is 10.20.31.255 (1,022 usable hosts).

4. Common Exam & Lab Traps to Watch Out For

T

r

a

p

1

β€”

C

o

n

f

u

s

i

n

g

t

h

e

h

o

s

t

I

P

w

i

t

h

t

h

e

n

e

t

w

o

r

k

I

D

:

1

9

2

.

1

6

8

.

1

0

.

6

4

/

2

7

i

s

a

n

e

t

w

o

r

k

a

d

d

r

e

s

s

(

n

o

t

a

u

s

a

b

l

e

h

o

s

t

!

)

,

w

h

e

r

e

a

s

1

9

2

.

1

6

8

.

1

0

.

6

4

/

2

5

i

s

a

v

a

l

i

d

u

s

a

b

l

e

h

o

s

t

i

n

s

i

d

e

1

9

2

.

1

6

8

.

1

0

.

0

/

2

5

.

T

r

a

p

2

β€”

F

o

r

g

e

t

t

i

n

g

/

3

1

p

o

i

n

t

-

t

o

-

p

o

i

n

t

l

i

n

k

s

(

R

F

C

3

0

2

1

)

:

o

n

r

o

u

t

e

r

-

t

o

-

r

o

u

t

e

r

l

i

n

k

s

,

/

3

1

h

a

s

2

u

s

a

b

l

e

h

o

s

t

s

w

i

t

h

z

e

r

o

b

r

o

a

d

c

a

s

t

w

a

s

t

e

.

T

r

a

p

3

β€”

C

l

o

u

d

e

x

a

m

s

(

A

W

S

/

A

z

u

r

e

)

:

a

l

w

a

y

s

r

e

m

e

m

b

e

r

c

l

o

u

d

V

P

C

s

u

b

n

e

t

s

r

e

s

e

r

v

e

5

I

P

s

p

e

r

b

l

o

c

k

r

a

t

h

e

r

t

h

a

n

2

,

w

h

i

c

h

t

u

r

n

s

a

1

4

-

h

o

s

t

/

2

8

i

n

t

o

1

1

.

Companion Offline NetDevKit Calculators

Apply the formulas from this guide immediately in your browser with zero server uploads:

Frequently Asked Questions

What is the Magic Number in IPv4 subnetting?

The Magic Number (also called block size or increment) equals 256 minus the interesting subnet mask octet. For example, mask 255.255.255.224 (/27) has Magic Number 256 - 224 = 32, meaning subnets start at .0, .32, .64, .96, and so on.

How do I quickly calculate usable hosts from a CIDR prefix?

Subtract the prefix from 32 to find host bits h, then compute 2^h - 2 for standard RFC subnets. For /26, h = 6, so 2^6 - 2 = 62 usable hosts.

How can I verify whether two IPv4 addresses belong to the same subnet?

Find the network address of both IPs using the Magic Number block size. If both IPs fall inside the same [network, broadcast] interval, they communicate directly over Layer 2 without crossing a router.

More Engineering Guides

Copied to clipboard