SUBNETTING EXPLAINED

Published: (February 24, 2026 at 12:22 PM EST)
6 min read
Source: Dev.to

Source: Dev.to

What is Subnetting?

Think of it like splitting a large apartment building into separate floors. Each floor (subnet) has its own numbered units (hosts), and the building’s address (network ID) identifies which floor you’re on.

IPv4 Address Structure

Example address: 192.168.1.10

Every IPv4 address is split into two logical parts:

  • Network portion – determined by the subnet mask.
  • Host portion – the remaining bits.

A /24 mask means the first 24 bits are the network portion and the last 8 bits are for hosts.

IP: 192.168.1.10

The Subnet Mask

255.255.255.0 = /24

Devices use the subnet mask to decide whether a destination IP is on the same local network (send directly) or on a different network (send to the gateway router).

How Devices Use the AND Operation

The rule is simple:

  • 1 AND 1 = 1
  • Anything AND 0 = 0

The result of the AND operation is the Network ID.

Source IP: 192.168.1.10
Binary:   11000000.10101000.00000001.00001010
Mask:     11111111.11111111.11111111.00000000
Result:   11000000.10101000.00000001.00000000  → 192.168.1.0 (Network ID)

The device performs this AND operation on both the source and destination IPs.

  • If both results match, the devices are on the same subnet and communicate directly.
  • If they differ, the packet is sent to the default gateway.

This logic is performed in hardware at wire speed on every packet.

Network ID and Broadcast Address

  • Network ID – all host bits are 0.
  • Broadcast Address – all host bits are 1 (the last address in the subnet).

Usable Host Addresses

Usable Hosts = 2^H − 2

where H is the number of host bits remaining after subnetting.

Example for /24

  • H = 8 → 2^8 − 2 = 254 usable hosts (addresses 192.168.1.1192.168.1.254).

Subnetting Formulas

  • Number of subnets needed: 2^N where N = bits borrowed from the host portion.
  • Hosts per subnet: 2^H − 2 where H = remaining host bits.

You borrow N bits from the host portion of the original mask, which increases the prefix length by N. The remaining H bits define how many hosts each subnet can hold.

Borrowing Bits — What It Actually Means

Original network: 192.168.1.0/24

Borrow 2 bits:

11111111.11111111.11111111.11000000
  • Borrowing 2 bits gives 2² = 4 subnets.
  • Each subnet has 2^6 − 2 = 62 usable hosts.

More subnets → fewer hosts per subnet. This is the fundamental trade‑off.

Block Size — The Most Useful Trick

Block Size = 256 − (interesting octet value)

The interesting octet is the octet where the subnet mask is neither 255 (fully network) nor 0 (fully host).

Example: /26

  • Mask: 255.255.255.192
  • Interesting octet value: 192
  • Block Size: 256 − 192 = 64

Subnets start at: 0, 64, 128, 192

Memorize Common Block Sizes

CIDRBlock Size
/25128
/2664
/2732
/2816
/298
/304

These values appear in almost every subnetting problem.

Solving Subnet Problems — Step by Step

The 6‑Step Method

  1. Identify the prefix length (/x) from the problem.
  2. Find the interesting octet.
  3. Calculate the block size.
  4. List the subnet ranges.
  5. Determine which range contains the given host address.
  6. Read off the Network ID, Broadcast address, and usable host range.

Worked Example 1 — /26 Subnet

Problem: Given IP address 192.168.1.70/26, find the Network ID, Broadcast address, and usable host range.

StepAction
1Prefix = /26
2Interesting octet = 4th octet (mask 192)
3Block size = 256 − 192 = 64
4Subnet ranges: 0‑63, 64‑127, 128‑191, 192‑255
570 falls in the 64‑127 range
6Network ID: 192.168.1.64
Broadcast: 192.168.1.127
Usable hosts: 192.168.1.65192.168.1.126

Worked Example 2 — /22 Subnet

Problem: Given IP address 10.205.79.90/22, find the Network ID, Broadcast address, and host range.

StepAction
1Prefix = /22
2Interesting octet = 3rd octet (mask 252)
3Block size = 256 − 252 = 4
4Subnet ranges in the 3rd octet: 0‑3, 4‑7, 8‑11, …, 76‑79, 80‑83, …
53rd octet 79 falls in the 76‑79 range
6Network ID: 10.205.76.0
Broadcast: 10.205.79.255
Usable hosts: 10.205.76.110.205.79.254

When the interesting octet is not the last one (as in /22), the full host range spans multiple values of the last octet. The network starts at (block_start).0 and ends at (block_end).255.

Worked Example 3 — Subdividing a /24

Problem: A company has the network 192.168.1.0/24 and needs at least 3 subnets.

StepAction
1Determine bits to borrow: need ≥3 subnets → borrow 2 bits (2² = 4 subnets)
2New mask: /26255.255.255.192
3List available subnets: 192.168.1.0/26, 192.168.1.64/26, 192.168.1.128/26, 192.168.1.192/26

Result: 4 subnets (one spare), each supporting 62 usable hosts. Assign three to departments and keep one as a spare.

CIDR Notation

192.168.1.0/24 means 24 network bits and 8 host bits.

CIDR (Classless Inter‑Domain Routing) is used everywhere—routing tables, firewall rules, cloud security groups, and IP allocation. Understanding /x notation instantly tells you the block size and host capacity of any subnet.

Quick Reference Table

CIDRSubnet MaskBlock SizeTotal IPsUsable Hosts
/24255.255.255.0256256254
/25255.255.255.128128128126
/26255.255.255.192646462
/27255.255.255.224323230
/28255.255.255.240161614
/29255.255.255.248886
/30255.255.255.252442

Key Takeaways

  • Subnetting divides one network into many by borrowing host bits – more subnets means fewer hosts per subnet.
  • Devices find their subnet using bitwise AND: IP AND Mask = Network ID.
  • The Network ID (all host bits 0) and Broadcast (all host bits 1) are always reserved and never assignable to hosts.
  • Block size = 256 − mask octet value – the fastest tool for finding subnet ranges.
  • Usable hosts = 2^H − 2 where H is the number of host bits.
  • CIDR /x notation tells you how many bits are network bits; everything else are host bits.
  • When designing subnets, prioritize the number of networks first, then the hosts per network.
0 views
Back to Blog

Related posts

Read more »

DevOps and Vibe Coding: A Journey

Things to Do Map Your Application - Map your application on paper, in a spreadsheet, or using graphics/flowcharts. This is the first step. - Understanding the...

OpenAI just raised $110 billion. Wow

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as we...