UseToolSuite UseToolSuite

IP Subnetting Demystified: A Practical Guide to CIDR and Subnet Masks

A practical guide to IP subnetting from the ground up: CIDR notation, the binary math behind subnet masks, VPC design on AWS, VLSM, and mental-math tricks to skip the subnet tables.

Necmeddin Cunedioglu Necmeddin Cunedioglu 9 min read
Part of the HTTP Status Codes: The Complete Guide for Developers series

Practice what you learn

IP/Subnet Calculator

Try it free →

IP Subnetting Demystified: A Practical Guide to CIDR and Subnet Masks

A common networking mistake looks like this: every workstation, server, printer, and access point in an office sits on a single flat /16 network. A /16 provides 65,534 host addresses — wildly oversized for a company of 80 people, and the broadcast traffic shows it. ARP requests, DHCP broadcasts, and discovery protocols pile up until the network hits intermittent latency spikes that are hard to trace. Understanding subnetting prevents this entirely.

Subnetting has a reputation for being intimidating. The moment binary conversions, bits, and CIDR blocks come up, a lot of developers tune out. But once the core idea clicks, it stops feeling complicated.

This guide is a developer-focused walkthrough of IPv4 subnetting: the binary structure of IP addresses, the move from classful routing to CIDR, the mental math for calculating subnets without a table, and how to design VPCs on AWS or Azure.

Skip the manual calculations. If you need to instantly calculate the Network Address, Broadcast Address, Usable Host Range, and Wildcard Mask for any CIDR block, use our free IP Subnet Calculator.

The Core Concept: What Is a Subnet, Really?

A subnet is a logical division of a larger IP network.

Think of it like a huge apartment building. The building itself has a single physical street address (The Network Address). However, inside that building, there are hundreds of individual units (The Host Addresses).

When the postal service delivers mail, they look at the street address to find the building. Once the mail arrives at the building’s lobby (The Router), the lobby attendant looks at the unit number to route the mail to the specific apartment.

An IPv4 address consists of 32 bits, typically represented as four octets (e.g., 192.168.1.100). A Subnet Mask is the mechanism that splits those 32 bits into two distinct parts:

  1. The Network Portion: Identifies the overall network (the “Building”).
  2. The Host Portion: Identifies the specific device on that network (the “Apartment Unit”).
IP Address:   192.168.1.100
Subnet Mask:  255.255.255.0

Network:      192.168.1.0     (The first 24 bits belong to the network)
Host:         .100            (The final 8 bits belong to the device)

The Fall of Classful Routing and the Rise of CIDR

In the 1980s, the internet was divided using “Classful Routing” (Class A, Class B, and Class C networks).

  • A Class C network gave you 254 usable addresses.
  • A Class B network gave you 65,534 usable addresses.

The mathematical gap between Class C and Class B was devastating. If a company needed 500 IP addresses, a Class C was too small. They were forced to apply for a Class B, which wasted over 65,000 IP addresses that nobody else could use. This inefficiency nearly exhausted the IPv4 address pool by the 1990s.

Enter CIDR (Classless Inter-Domain Routing)

CIDR solved this problem by abolishing the rigid classes. Instead, CIDR allows a network administrator to draw the line between the Network Portion and the Host Portion anywhere across the 32 bits.

This is denoted by a slash followed by a number (e.g., /24, /26). The number indicates exactly how many bits, counting from left to right, are “locked” to the network.

CIDR PrefixSubnet MaskTotal AddressesUsable HostsStrategic Use Case
/24255.255.255.0256254Standard office LAN
/25255.255.255.128128126Splitting a LAN in two
/26255.255.255.1926462Departmental separation
/27255.255.255.2243230Small server cluster
/28255.255.255.2401614DMZ or secure subnet
/29255.255.255.24886Small router links
/30255.255.255.25242Point-to-Point WAN link

The Mathematical Formula

To calculate the total number of usable hosts for any CIDR block, use this absolute formula:

Usable hosts = 2^(32 - CIDR Prefix) - 2

Why minus 2? Because every subnet reserves two specific addresses that cannot be assigned to a computer:

  1. The Network Address: All host bits are set to 0. This represents the network itself.
  2. The Broadcast Address: All host bits are set to 1. Sending a packet to this address blasts the packet to every single device on the subnet simultaneously.

The Mental Math Shortcut (No Calculator Needed)

If you are taking a networking certification (like the CCNA) or sitting in a technical interview, you cannot rely on an online calculator. You must master the mental math.

Here is the secret trick for calculating subnets in the 4th octet (prefixes /25 through /32):

Step 1: Find the Block Size (Total Addresses) Start with 256 (a standard /24) and divide by 2 for every bit you move to the right:

  • /24 = 256 addresses
  • /25 = 128 addresses (256/2)
  • /26 = 64 addresses (128/2)
  • /27 = 32 addresses (64/2)
  • /28 = 16 addresses (32/2)

Step 2: Calculate the Subnet Mask The subnet mask is always exactly 256 minus the Block Size.

  • If you have a /26 (Block Size 64), the mask is 256 - 64 = 192. Therefore, the mask is 255.255.255.192.
  • If you have a /28 (Block Size 16), the mask is 256 - 16 = 240. Therefore, the mask is 255.255.255.240.

Step 3: Finding the Network Boundaries Assume you are given the IP 192.168.1.155 /26. What is the Network Address?

  1. We know /26 has a Block Size of 64.
  2. Subnets therefore start at multiples of 64: .0, .64, .128, .192.
  3. Which block does 155 fall into? It falls into the .128 block.
Target IP: 192.168.1.155 /26
Block Size: 64

Network Address: 192.168.1.128
First Usable IP: 192.168.1.129
Last Usable IP:  192.168.1.190
Broadcast Addr:  192.168.1.191

Real-World Subnet Architecture

When connecting two core routers together across a WAN, you only need exactly two IP addresses. If you use a /24, you waste 252 IP addresses. The industry standard is to use a /30.

  • Total IPs: 4
  • Network Address: 1 (Reserved)
  • Router A: 1 (Usable)
  • Router B: 1 (Usable)
  • Broadcast Address: 1 (Reserved)

Note: Modern routers support RFC 3021, which allows the use of /31 for point-to-point links by completely disabling the Network and Broadcast addresses, preserving absolute maximum IP space.

2. Cloud VPC Architecture (AWS / Azure / GCP)

When creating a Virtual Private Cloud in AWS, your initial CIDR block is immutable. If you choose poorly, you cannot expand it later without migrating the entire infrastructure.

A catastrophic mistake is provisioning a /24 (254 hosts) for a VPC. The Professional Approach: Provision a /16 (65,534 hosts) for the VPC, and then carve it up into /24 subnets across different Availability Zones (AZs).

VPC CIDR: 10.0.0.0/16
├── Public Subnets (Internet Facing)
│   ├── AZ-A: 10.0.1.0/24 (254 hosts for Application Load Balancers)
│   └── AZ-B: 10.0.2.0/24 (254 hosts for Application Load Balancers)
├── Private Subnets (App Servers)
│   ├── AZ-A: 10.0.10.0/24 (254 hosts for EC2 Instances)
│   └── AZ-B: 10.0.11.0/24 (254 hosts for EC2 Instances)
└── Database Subnets (Strict Isolation)
    ├── AZ-A: 10.0.20.0/24 (254 hosts for RDS Databases)
    └── AZ-B: 10.0.21.0/24 (254 hosts for RDS Databases)

This architecture provides huge room for horizontal scaling, strict security group isolation, and intuitive network tracking.

3. Container Networks (Kubernetes / Docker)

If you are a DevOps engineer deploying Kubernetes clusters, subnetting is critical to prevent IP exhaustion and routing overlaps.

  • Node Network: The physical VMs might live on a 192.168.0.0/24.
  • Pod Network: Kubernetes usually assigns a large 10.244.0.0/16 to the cluster, and then slices out individual /24 subnets to each specific Node, allowing every Node to host up to 254 unique Pods.
  • Service Network: ClusterIP services require a dedicated, non-overlapping range, typically 10.96.0.0/12.

The Private IP Address Space (RFC 1918)

You cannot randomly assign public IP addresses inside your internal network. The Internet Engineering Task Force (IETF) reserved three large blocks of IPs exclusively for internal, private routing. These IPs cannot route over the public internet.

Range NameIP RangeCIDR NotationTotal AddressesCommon Use Case
Class A10.0.0.0 to 10.255.255.25510.0.0.0/816.7 MillionEnterprise networks, AWS VPCs, large ISPs.
Class B172.16.0.0 to 172.31.255.255172.16.0.0/121.04 MillionDocker container defaults (172.17.0.0/16).
Class C192.168.0.0 to 192.168.255.255192.168.0.0/1665,536Consumer routers, home networks, small offices.

Warning: There is also the 169.254.0.0/16 Link-Local block. If your computer receives an IP in this range, it means your DHCP server is broken or unreachable. It is a failure state, not a routable network.

Variable Length Subnet Masking (VLSM)

In the real world, you rarely slice a network into perfectly equal pieces. If the HR department has 10 computers, and the Engineering department has 120 computers, slicing a /24 into two equal /25 subnets is highly inefficient.

VLSM (Variable Length Subnet Masking) allows you to carve a single large network into subnets of wildly varying sizes.

  • Start with a 192.168.1.0/24.
  • Carve off a /25 (126 hosts) for Engineering: 192.168.1.0/25.
  • Take the remaining half (192.168.1.128/25) and carve it again into a /26 (62 hosts) for Sales: 192.168.1.128/26.
  • Take the remaining quarter (192.168.1.192/26) and carve it into a /28 (14 hosts) for HR: 192.168.1.192/28.

This minimizes wasted IP space.

Wildcard Masks: The Router’s Perspective

If you interact with Cisco networking gear, Access Control Lists (ACLs), or OSPF routing protocols, you will encounter the Wildcard Mask.

A Wildcard Mask is the exact mathematical inverse of a Subnet Mask. Where a Subnet Mask uses 1s to lock down the network bits, a Wildcard Mask uses 0s to lock down the network bits.

To find the Wildcard Mask, subtract your Subnet Mask from 255.255.255.255.

Subnet Mask:   255.255.255.192 (/26)
Subtraction:   255.255.255.255
               - 255.255.255.192
-----------------------------------
Wildcard Mask:   0.  0.  0. 63

In an ACL, a wildcard mask tells the router exactly which bits it is allowed to ignore when filtering packets.

Common Subnetting Disasters

  1. Overlapping Subnets: If you configure Site A with 10.0.0.0/23 and Site B with 10.0.1.0/24, you have created a catastrophic overlap. The .1 network exists in both locations. If you connect these sites via a VPN, the routers will not know where to send the packets, resulting in routing loops or dropped traffic.
  2. Assigning the Network Address: I have seen countless tickets where a junior admin statically assigns 192.168.1.0 or 192.168.1.255 to a Linux server, and then spends hours debugging why the server cannot reach the internet. You cannot assign the Network or Broadcast addresses.
  3. Hardcoding IP Literals: If you hardcode 192.168.1.100 into your application source code instead of relying on DNS, the moment the infrastructure team re-subnets the network, your application will permanently break.

Frequently Asked Questions

Q: Can I use CIDR /32? Yes. A /32 denotes a single, exact IP address. It is frequently used in firewall rules and routing tables to represent a specific host rather than a network.

Q: Why do consumer routers always use 192.168.1.1? It is merely a historical convention established by Linksys and Netgear in the early 2000s. There is no technical requirement; they simply chose the first usable IP address in the standard Class C private range.

Q: Does IPv6 use Subnet Masks? IPv6 entirely abandons traditional Subnet Masks (like 255.255.255.0). It relies exclusively on CIDR notation (e.g., 2001:db8::/32). Furthermore, because IPv6 has 128 bits, the sheer volume of available addresses makes conserving IPs via complex subnetting mostly obsolete. Standard IPv6 subnets are simply /64.

Further Reading


Do not risk an overlapping subnet in production. Ensure mathematical precision by using our free IP Subnet Calculator. Validate your routing domains instantly with the DNS Lookup Tool and verify endpoint security with the SSL Certificate Checker.

Necmeddin Cunedioglu
Necmeddin Cunedioglu Author
9 min read
-- views

Software developer and the creator of UseToolSuite. I write about the tools and techniques I use daily as a developer — practical guides based on real experience, not theory.