1. Library
  2. Computer Networks
  3. IP Addresses
  4. Network Addressing

Updated 8 hours ago

When you see 192.168.1.0/24, you're looking at a question: which addresses belong together? Subnet calculation isn't abstract math—it's what every device does, constantly, to answer: "Can I talk to this address directly, or do I need a router?"

What Subnet Ranges Tell You

Given an IP address with CIDR notation like 192.168.5.0/24, you want to find:

  • Network address — Where this neighborhood starts (can't assign to hosts)
  • Broadcast address — Where it ends (can't assign to hosts)
  • Usable host range — Every address between them that actual devices can use
  • Total capacity — How many devices fit in this space

The Binary Foundation

IP addresses are 32-bit binary numbers. The dotted decimal format exists for humans, but networks think in binary. When you understand this, everything else becomes obvious.

What CIDR Notation Really Means

The /24 in 192.168.5.0/24 means "the first 24 bits identify the network." The remaining bits (32 - 24 = 8) identify hosts within that network.

192.168.5.0/24 in binary:
11000000.10101000.00000101.00000000
                            ^^^^^^^^
                            8 bits for hosts = 2⁸ = 256 addresses

The subnet mask marks this division:

255.255.255.0 in binary:
11111111.11111111.11111111.00000000
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24 network bits (all 1s)    8 host bits (all 0s)

The subnet mask is a stencil. Lay it over any IP address, and it reveals which neighborhood that address belongs to.

Finding the Network Address

The network address has all host bits set to 0. You find it by performing a binary AND between the IP address and subnet mask—wherever the mask has a 1, keep the IP bit; wherever the mask has 0, the result is 0.

Example: What network does 192.168.5.85/24 belong to?

IP Address:    192.168.5.85
               11000000.10101000.00000101.01010101

Subnet Mask:   255.255.255.0
               11111111.11111111.11111111.00000000
               ----------------------------------------
AND Result:    11000000.10101000.00000101.00000000

Network:       192.168.5.0

The host bits (last 8) became 0. This is the network address—the start of the range.

Finding the Broadcast Address

The broadcast address has all host bits set to 1. Take the network address and flip every host bit to 1.

Network:       192.168.5.0
               11000000.10101000.00000101.00000000
                                           ^^^^^^^^
                                           Set these to 1

Broadcast:     11000000.10101000.00000101.11111111
               192.168.5.255

Finding Usable Hosts

Everything between network and broadcast can be assigned:

Network:       192.168.5.0    (reserved)
First host:    192.168.5.1    ← Can assign
Last host:     192.168.5.254  ← Can assign
Broadcast:     192.168.5.255  (reserved)

Total: 256 addresses
Usable: 254 hosts (256 - 2)

When the Subnet Boundary Isn't Obvious

Let's work through 10.50.100.75/22—where the subnet splits the third octet.

Step 1: Convert to binary
10.50.100.75
00001010.00110010.01100100.01001011

Step 2: /22 means first 22 bits are network
Subnet mask: 255.255.252.0
11111111.11111111.11111100.00000000
                      ^^
                      These 2 bits belong to the network

Step 3: AND operation finds network
00001010.00110010.01100100.01001011  (10.50.100.75)
11111111.11111111.11111100.00000000  (255.255.252.0)
----------------------------------------
00001010.00110010.01100100.00000000  (10.50.100.0)

Network: 10.50.100.0

Step 4: Set all 10 host bits to 1 for broadcast
00001010.00110010.01100100.00000000
                  ^^^^^^^^ ^^^^^^^^
                  Host bits → set to 1
00001010.00110010.01100111.11111111

Broadcast: 10.50.103.255

Result:
Network:       10.50.100.0/22
First host:    10.50.100.1
Last host:     10.50.103.254
Broadcast:     10.50.103.255
Usable hosts:  1,022 (2¹⁰ - 2)

Notice the range spans from 100 to 103 in the third octet. The binary view shows why—those last 2 bits of the third octet are part of the host portion, so they count through four values (00, 01, 10, 11). Subnet boundaries don't respect octet boundaries.

The Quick Math Method

Once you understand the binary foundation, you can calculate most subnets mentally.

The Block Size Pattern

Subnet ranges divide address space into equal blocks. The block size comes from the number of host bits.

/24: 32 - 24 = 8 host bits → 2⁸ = 256 addresses per block
/27: 32 - 27 = 5 host bits → 2⁵ = 32 addresses per block
/22: 32 - 22 = 10 host bits → 2¹⁰ = 1,024 addresses per block

The block size tells you where subnet boundaries fall:

/24 (block size 256): Subnets at .0, .1, .2, .3 (changes in 4th octet)
/27 (block size 32):  Subnets at .0, .32, .64, .96 (32-address chunks)
/22 (block size 1024): Subnets every 4 in 3rd octet (.0, .4, .8, .12)

Finding Which Subnet an IP Belongs To

Divide the relevant octet by the block size.

Example: 192.168.5.85/27

Host bits: 32 - 27 = 5
Block size: 2⁵ = 32
Divide: 85 ÷ 32 = 2 remainder 21

This IP is in the 3rd block (starting at 64):
- Block 0: 0-31
- Block 1: 32-63
- Block 2: 64-95 ← Our IP is here
- Block 3: 96-127

Network:      192.168.5.64
First host:   192.168.5.65
Last host:    192.168.5.94
Broadcast:    192.168.5.95
Usable hosts: 30 (32 - 2)

Quick Reference for Common Subnets

/30 — 4 addresses, 2 hosts (point-to-point links)
/29 — 8 addresses, 6 hosts
/28 — 16 addresses, 14 hosts
/27 — 32 addresses, 30 hosts
/26 — 64 addresses, 62 hosts
/25 — 128 addresses, 126 hosts
/24 — 256 addresses, 254 hosts
/23 — 512 addresses, 510 hosts
/22 — 1,024 addresses, 1,022 hosts
/16 — 65,536 addresses, 65,534 hosts

Note: /31 networks (2 addresses) are a special case for point-to-point links only (RFC 3021). They don't reserve network and broadcast addresses—both can be assigned to the two endpoints.

Dividing an Office Network

You have 10.20.30.0/24 and need 4 departmental subnets.

Need 4 subnets → need 2 bits (2² = 4)
Original: /24
Add 2 bits: /26

Each subnet gets:
- 32 - 26 = 6 host bits
- 2⁶ = 64 addresses
- 64 - 2 = 62 usable hosts

The division:

HR:          10.20.30.0/26   → hosts .1 through .62
Engineering: 10.20.30.64/26  → hosts .65 through .126
Sales:       10.20.30.128/26 → hosts .129 through .190
Guest WiFi:  10.20.30.192/26 → hosts .193 through .254

Each department is its own broadcast domain with 62 usable addresses. They can talk to each other through a router, but broadcasts stay local to each subnet.

Reference Tables

Which Octet Changes?

  • /24 or larger (/25-/32) — Only the 4th octet changes
  • /16 to /23 — The 3rd octet changes
  • /8 to /15 — The 2nd octet changes
  • Less than /8 — The 1st octet changes

Partial Octet Mask Values

10000000 = 128  (1 bit)
11000000 = 192  (2 bits)
11100000 = 224  (3 bits)
11110000 = 240  (4 bits)
11111000 = 248  (5 bits)
11111100 = 252  (6 bits)
11111110 = 254  (7 bits)
11111111 = 255  (8 bits)

Powers of 2

2¹ = 2        2⁶ = 64       2¹¹ = 2,048
2² = 4        2⁷ = 128      2¹² = 4,096
2³ = 8        2⁸ = 256      2¹³ = 8,192
2⁴ = 16       2⁹ = 512      2¹⁴ = 16,384
2⁵ = 32       2¹⁰ = 1,024   2¹⁵ = 32,768

Verify Your Work

After calculating, check:

  1. Network address has all host bits = 0
  2. Broadcast address has all host bits = 1
  3. First usable = Network + 1
  4. Last usable = Broadcast - 1
  5. Total addresses = 2^(host bits)

Frequently Asked Questions About Subnet Calculation

Was this page helpful?

😔
🤨
😃