How to Calculate Subnets — CIDR, Mask & IP Ranges
Introduction
In the world of networking, subnetting is the foundational skill that enables efficient IP address allocation, network segmentation, and traffic control.
Why Learn Subnetting?
- Certification preparation (CompTIA Network+, Cisco CCNA)
- Network design and infrastructure planning
- Troubleshooting connectivity and routing issues
- Security implementation through network segmentation
- Career advancement in IT and networking roles
Manual vs Calculator Methods
A subnet calculator provides instant results, but mastering the manual method gives you:
- Deeper insight into network design principles
- Troubleshooting capabilities when tools aren't available
- Interview confidence for technical positions
- Understanding of security and traffic flow
- Professional credibility in networking roles
What You'll Master
This guide teaches you to calculate:
- Network addresses and broadcast addresses
- Usable host ranges for any subnet
- Subnet masks in CIDR and dotted-decimal formats
- Binary logic behind subnetting decisions
- Network planning for VLANs and enterprise infrastructure
By the end, you'll look at /26 and instantly know it provides 62 usable hosts—a skill that separates competent technicians from true networking professionals.
The Binary Foundation of Subnetting
Every IPv4 address is a 32-bit binary number, typically written in dotted-decimal notation (e.g., 192.168.1.10). Subnetting divides this 32-bit space into two parts:
- Network portion: Identifies the subnet
- Host portion: Identifies devices within that subnet
The subnet mask (or CIDR prefix) defines where this split occurs.
CIDR Notation vs. Subnet Mask
- CIDR (Classless Inter-Domain Routing): Written as
/N, whereNis the number of network bits (e.g.,/24). - Subnet Mask: A 32-bit number with
Nleading 1s and(32−N)trailing 0s, written in dotted-decimal (e.g.,255.255.255.0for/24).
Key Conversion:
/24→11111111.11111111.11111111.00000000→255.255.255.0/26→11111111.11111111.11111111.11000000→255.255.255.192
Step-by-Step Subnet Calculation
Given an IP and CIDR (e.g., 192.168.10.50/26):
1. Determine the Subnet Mask
Convert /26 to dotted-decimal:
- First 24 bits =
255.255.255 - Next 2 bits =
11000000= 192 - Subnet Mask =
255.255.255.192
2. Find the Block Size (Increment)
The block size is the value of the least significant bit in the subnet mask’s last octet.
- For
/26, last octet =11000000 - Least significant 1 is in the 64s place (128, 64, 32, 16, 8, 4, 2, 1)
- Block Size = 64
3. Identify the Network Address
Find the largest multiple of the block size ≤ the IP’s last octet.
- IP last octet = 50
- Multiples of 64: 0, 64, 128…
- 0 ≤ 50 below 64 → Network =
192.168.10.0
4. Find the Broadcast Address
Broadcast = Network + Block Size − 1
→ 192.168.10.0 + 64 − 1 = 192.168.10.63
5. Determine Usable Host Range
- First Usable Host: Network + 1 →
192.168.10.1 - Last Usable Host: Broadcast − 1 →
192.168.10.62 - Total Usable Hosts:
2^(32−N) − 2→2⁶ − 2 = 62
Common CIDR Prefixes & Host Counts
| CIDR | Subnet Mask | Host Bits | Usable Hosts | |------|-------------------|-----------|--------------| | /30 | 255.255.255.252 | 2 | 2 | | /29 | 255.255.255.248 | 3 | 6 | | /28 | 255.255.255.240 | 4 | 14 | | /27 | 255.255.255.224 | 5 | 30 | | /26 | 255.255.255.192 | 6 | 62 | | /25 | 255.255.255.128 | 7 | 126 | | /24 | 255.255.255.0 | 8 | 254 |
Subnetting for Network Design
- Point-to-Point Links: Use
/30(2 hosts) for router-to-router connections. - Small Offices:
/26(62 hosts) for departments. - Large Networks:
/24(254 hosts) for entire sites. - VLANs: Assign a subnet per VLAN for security and broadcast control.
IPv6 Subnetting (Brief Overview)
IPv6 uses 128-bit addresses and typically uses /64 subnets for all local networks (even if only 2 devices are present). The vast address space makes conservation unnecessary, simplifying design. Prefixes like 2001:db8::/32 are common for documentation.
Worked Examples & Practice Scenarios
Example 1: Basic Subnet Calculation
Problem: Find the network, broadcast, and usable range for 10.5.123.88/28.
Solution:
- Subnet Mask:
/28→255.255.255.240 - Block Size: Last octet =
11110000→ 16 - Network: Largest multiple of 16 ≤ 88 → 80 →
10.5.123.80 - Broadcast:
80 + 16 − 1 = 95→10.5.123.95 - Usable Hosts:
10.5.123.81to10.5.123.94(14 hosts)
Example 2: Point-to-Point Link
Problem: You need a subnet for two routers. What’s the most efficient CIDR?
Solution:
- Need 2 usable hosts →
/30(2 hosts) - Example:
192.168.100.4/30- Network:
192.168.100.4 - Broadcast:
192.168.100.7 - Usable:
.5and.6
- Network:
Example 3: Subnetting a /24 into /26s
Problem: How many /26 subnets fit in 172.16.0.0/24?
Solution:
- Host bits in /24 = 8
- Host bits in /26 = 6
- Subnet bits = 8 − 6 = 2
- Number of subnets =
2² = 4 - Subnets:
172.16.0.0/26172.16.0.64/26172.16.0.128/26172.16.0.192/26
Practice Problems (Try These!)
- What is the broadcast address for
192.168.1.100/27? - How many usable hosts in a
/29network? - What subnet mask corresponds to
/22? - Is
10.0.0.15/28a valid host address?
Answers:
- Block = 32; 100 → 96–127 → 127
2³ − 2 = 6255.255.252.0- Network =
10.0.0.0; broadcast =15→ No, it’s the broadcast address
What is the difference between a network address and a broadcast address?
- Network Address: The first address in a subnet (all host bits = 0). It identifies the subnet itself and cannot be assigned to a device.
- Broadcast Address: The last address in a subnet (all host bits = 1). It’s used to send a message to all devices in the subnet and cannot be assigned to a device.
Why subtract 2 for usable hosts?
The network address and broadcast address are reserved, leaving 2^n − 2 usable addresses for hosts (where n = host bits). The exception is /31 (used in point-to-point links per RFC 3021), which allows 2 hosts with no broadcast.
How do I quickly convert CIDR to subnet mask?
Memorise the 8-bit values:
/25= 128/26= 192/27= 224/28= 240/29= 248/30= 252/31= 254/32= 255
For/22: 22 = 8+8+6 →255.255.252.0
What is VLSM and why is it important?
Variable Length Subnet Masking (VLSM) allows using different subnet sizes within the same network (e.g., /26 for a large department, /28 for a small one). This prevents IP waste and is essential for efficient address planning.
Can two devices have the same IP in different subnets?
Yes. Subnets are isolated at Layer 3. 192.168.1.10/24 and 192.168.2.10/24 are unique because their network portions differ.
How does a router use subnet masks?
A router uses the subnet mask to determine whether a destination IP is on the local network (forward via ARP) or a remote network (forward to default gateway).
What’s the wildcard mask, and how is it used?
Wildcard mask = inverse of subnet mask. Used in ACLs and OSPF.
Example: Subnet mask 255.255.255.0 → Wildcard 0.0.0.255
Is subnetting still relevant with IPv6?
Yes, but simpler. IPv6 uses /64 for all LANs, and subnetting is done at the site level (e.g., 2001:db8:acad::/48 allows 65,536 /64 subnets). The principles are the same, but address abundance reduces complexity.