How to Use CIDR Notation: Complete Subnet Calculator Guide
Rudra Chauhan, Senior Systems Architect
How to Use CIDR Notation: Complete Subnet Calculator Guide
Introduction
Classless Inter-Domain Routing (CIDR) replaced legacy Classful networking (Class A, B, and C) in 1993 under RFC 1519. It revolutionized IP address allocation by allowing variable-length subnet masks (VLSM) and route summarization across the internet.
Whether you are designing a Kubernetes cluster VPC, configuring VLANs on Cisco Catalyst switches, or troubleshooting routing tables, understanding CIDR math is an essential network engineering skill.
What is CIDR Notation?
CIDR notation represents an IP address and its associated routing prefix (subnet mask) in a compact format: IP_ADDRESS/PREFIX_LENGTH.
For example: 192.168.1.0/24
The slash number (/24) denotes the number of continuous high-order bits set to 1 in the 32-bit subnet mask:
- /24 means 24 network bits and 8 host bits.
- Decimal equivalent mask:
255.255.255.0 - Binary representation:
11111111.11111111.11111111.00000000
Common CIDR Subnet Cheat Sheet
| CIDR Prefix | Subnet Mask | Total Addresses | Usable Hosts | Use Case |
|---|---|---|---|---|
| /32 | 255.255.255.255 | 1 | 1 | Single host / Loopback interface |
| /30 | 255.255.255.252 | 4 | 2 | Point-to-point WAN router link |
| /29 | 255.255.255.248 | 8 | 6 | Small server cluster / Firewall DMZ |
| /28 | 255.255.255.240 | 16 | 14 | Small office branch / K8s node subnet |
| /27 | 255.255.255.224 | 32 | 30 | Department VLAN |
| /26 | 255.255.255.192 | 64 | 62 | Medium enterprise department |
| /24 | 255.255.255.0 | 256 | 254 | Standard LAN network / Pod Network |
| /23 | 255.255.254.0 | 512 | 510 | Combined campus LAN |
| /16 | 255.255.0.0 | 65,536 | 65,534 | Large Enterprise VPC / AWS Cloud CIDR |
How to Calculate Subnet Ranges (Step-by-Step)
Given an IP address 10.0.14.50/22:
Step 1: Determine Host Bits
Total IPv4 bits = 32. Host bits = 32 - 22 = 10 bits.
Step 2: Calculate Total & Usable Hosts
- Total addresses = 2^10 = 1024
- Usable hosts = 1024 - 2 = 1022 (Network address and Broadcast address reserved)
Step 3: Find Block Size & Subnet Boundary
- The prefix
/22spans into the 3rd octet (22 - 16 = 6bits in 3rd octet). - Block size in 3rd octet = 2^(8-6) = 2^2 = 4.
- 3rd octet multiples: 0, 4, 8, 12, 16...
- Since 14 falls between 12 and 16, the network address is 10.0.12.0.
Result Summary:
- Network ID:
10.0.12.0 - First Usable Host:
10.0.12.1 - Last Usable Host:
10.0.15.254 - Broadcast Address:
10.0.15.255 - Subnet Mask:
255.255.252.0
Interactive Diagnostics with Teksolvr
To calculate subnets automatically without manual binary math, use Teksolvr's free tools:
- Try our online Subnet & CIDR Calculator for instant IP range decomposition.
- For Variable Length Subnet Masking, use the VLSM Calculator.
- Verify IP addresses with our IP Address Lookup.
Troubleshooting Checklist
- Verify the IP address and prefix length are correct.
- Calculate the subnet mask using the prefix length.
- Determine the network ID by finding the first address in the subnet.
- Calculate the first and last usable hosts by subtracting 2 from the total addresses.
- Verify the broadcast address by adding 1 to the last usable host.
Frequently Asked Questions
Why are 2 IP addresses subtracted from total hosts?
The first address is the Network Address (identifies the subnet itself) and the last address is the Broadcast Address (used to broadcast packets to all hosts in that subnet). Neither can be assigned to network interfaces.
What is the RFC governing CIDR?
CIDR was originally standardized in RFC 1519 and updated in RFC 4632.
Advanced CIDR Calculations
- CIDR to Subnet Mask Conversion: Given a CIDR prefix
/24, convert it to a subnet mask:255.255.255.0. - Subnet Mask to CIDR Conversion: Given a subnet mask
255.255.255.0, convert it to a CIDR prefix:/24. - CIDR Subnet Summarization: Given a list of CIDR prefixes, summarize them into a single CIDR prefix.
Example Use Case: Configuring VLANs on Cisco Catalyst Switches
To configure VLANs on a Cisco Catalyst switch, you need to calculate the subnet mask for each VLAN. Let's say you have a VLAN with IP address 192.168.1.0/24. To calculate the subnet mask, use the following steps:
- Determine the host bits:
32 - 24 = 8 bits. - Calculate the total and usable hosts:
2^8 = 256,256 - 2 = 254. - Find the block size and subnet boundary:
2^(8-8) = 2^0 = 1,192.168.1.0is the network address.
The subnet mask for this VLAN is 255.255.255.0.
Conclusion
Understanding CIDR notation is essential for network engineers to design and troubleshoot IP networks. By following the steps outlined in this guide, you can calculate subnet ranges and determine the subnet mask for each subnet. Remember to use Teksolvr's free tools to automate CIDR calculations and troubleshoot IP address issues.
References
- RFC 1519: Classless Inter-Domain Routing (CIDR)
- RFC 4632: Classless Inter-Domain Routing (CIDR) An Address Assignment and Registry Structure for the Internet
Code Example
bash#!/bin/bash # Define the IP address and prefix length IP_ADDRESS="10.0.14.50" PREFIX_LENGTH=22 # Calculate the host bits HOST_BITS=$((32 - PREFIX_LENGTH)) # Calculate the total and usable hosts TOTAL_ADDRESSES=$((2 ** HOST_BITS)) USABLE_HOSTS=$((TOTAL_ADDRESSES - 2)) # Find the block size and subnet boundary BLOCK_SIZE=$((2 ** (8 - HOST_BITS))) SUBNET_BOUNDARY=$((PREFIX_LENGTH - 16)) # Calculate the network ID NETWORK_ID=$(echo "scale=0; $IP_ADDRESS & $((1 << (32 - $SUBNET_BOUNDARY)))") # Print the result echo "Network ID: $NETWORK_ID" echo "First Usable Host: $((NETWORK_ID + 1))" echo "Last Usable Host: $((NETWORK_ID + $USABLE_HOSTS - 1))" echo "Broadcast Address: $((NETWORK_ID + $USABLE_HOSTS))" echo "Subnet Mask: 255.255.252.0"
Diagram
Diagram Name
Table Comparison
| Tool | Subnet Mask Calculation | CIDR to Subnet Mask Conversion | Subnet Summarization |
|---|---|---|---|
| Teksolvr Subnet Calculator | |||
| Teksolvr VLSM Calculator | |||
| Teksolvr IP Address Lookup |
Note: The table above is a comparison of Teksolvr's tools for subnet mask calculation, CIDR to subnet mask conversion, and subnet summarization. The | symbol indicates that the tool supports the corresponding feature.