CIDR Notation: Complete Guide to Classless Inter-Domain Routing
CIDR (Classless Inter-Domain Routing) notation is a compact method for specifying IP addresses and their associated network masks. Understanding CIDR is essential for network configuration, subnetting, and efficient IP address management. This comprehensive guide explains everything you need to know about CIDR notation.
What is CIDR Notation?
CIDR notation is a way to represent an IP address and its subnet mask using a slash followed by a number. Instead of writing out the full subnet mask, you specify how many bits are used for the network portion.
Format
IP_ADDRESS/PREFIX_LENGTH
Examples:
192.168.1.0/24
10.0.0.0/8
172.16.0.0/16
203.0.113.0/25
Components
IP Address: The network or host address Slash (/): Separator Prefix Length: Number of bits in the network portion (0-32 for IPv4)
CIDR vs Traditional Subnet Masks
Traditional Notation
IP Address: 192.168.1.0
Subnet Mask: 255.255.255.0
CIDR Notation
192.168.1.0/24
Why /24? - 255.255.255.0 in binary: 11111111.11111111.11111111.00000000 - Count the 1s: 8 + 8 + 8 + 0 = 24 bits - Therefore: /24
Common CIDR Blocks
Standard Subnet Sizes
| CIDR | Subnet Mask | Usable Hosts | Common Use | |------|-------------|--------------|------------| | /32 | 255.255.255.255 | 1 (host) | Single host | | /31 | 255.255.255.254 | 2 | Point-to-point links | | /30 | 255.255.255.252 | 2 | Point-to-point links | | /29 | 255.255.255.248 | 6 | Very small networks | | /28 | 255.255.255.240 | 14 | Small office | | /27 | 255.255.255.224 | 30 | Small network | | /26 | 255.255.255.192 | 62 | Small to medium | | /25 | 255.255.255.128 | 126 | Medium network | | /24 | 255.255.255.0 | 254 | Standard small network | | /23 | 255.255.254.0 | 510 | Medium network | | /22 | 255.255.252.0 | 1,022 | Large network | | /21 | 255.255.248.0 | 2,046 | Large network | | /20 | 255.255.240.0 | 4,094 | Very large network | | /16 | 255.255.0.0 | 65,534 | Class B equivalent | | /8 | 255.0.0.0 | 16,777,214 | Class A equivalent |
Classful Equivalents
Class A: /8
10.0.0.0/8 = 10.0.0.0 with mask 255.0.0.0
Class B: /16
172.16.0.0/16 = 172.16.0.0 with mask 255.255.0.0
Class C: /24
192.168.1.0/24 = 192.168.1.0 with mask 255.255.255.0
Understanding Prefix Length
What the Number Means
The number after the slash indicates how many bits (from left to right) are used for the network portion.
Example: /24
Binary representation of /24:
11111111.11111111.11111111.00000000
└────────────────────────┘ └──────┘
Network (24 bits) Host (8 bits)
Example: /16
Binary representation of /16:
11111111.11111111.00000000.00000000
└──────────────┘ └──────────────┘
Network (16) Host (16)
Calculating Hosts
Formula:
Number of hosts = 2^(32 - prefix_length) - 2
Why subtract 2? - Network address (all host bits 0) - Broadcast address (all host bits 1)
Examples:
/24: 2^(32-24) - 2 = 2^8 - 2 = 256 - 2 = 254 hosts
/16: 2^(32-16) - 2 = 2^16 - 2 = 65,536 - 2 = 65,534 hosts
/30: 2^(32-30) - 2 = 2^2 - 2 = 4 - 2 = 2 hosts
Converting Between Notations
CIDR to Subnet Mask
Method: 1. Write prefix length as binary 1s 2. Fill remaining bits with 0s 3. Convert to decimal
Example: /26 ``` Step 1: 26 ones 11111111.11111111.11111111.11000000
Step 2: Already filled with zeros
Step 3: Convert to decimal 11111111 = 255 11111111 = 255 11111111 = 255 11000000 = 192
Result: 255.255.255.192 ```
Subnet Mask to CIDR
Method: 1. Convert subnet mask to binary 2. Count the 1s 3. That's your prefix length
Example: 255.255.240.0 ``` Step 1: Convert to binary 255 = 11111111 255 = 11111111 240 = 11110000 0 = 00000000
Step 2: Count 1s 11111111.11111111.11110000.00000000 8 + 8 + 4 + 0 = 20
Result: /20 ```
CIDR Block Calculations
Network Address
The network address has all host bits set to 0.
Example: 192.168.1.100/24 ``` IP: 192.168.1.100 Mask: /24 (255.255.255.0)
Network portion: 192.168.1 Host portion: 100
Network address: 192.168.1.0 ```
Broadcast Address
The broadcast address has all host bits set to 1.
Example: 192.168.1.0/24 ``` Network: 192.168.1.0 Mask: /24 (last 8 bits are host)
Set all host bits to 1: 192.168.1.11111111 = 192.168.1.255
Broadcast: 192.168.1.255 ```
Usable IP Range
Example: 192.168.1.0/24 ``` Network: 192.168.1.0 (not usable) First usable: 192.168.1.1 Last usable: 192.168.1.254 Broadcast: 192.168.1.255 (not usable)
Usable range: 192.168.1.1 - 192.168.1.254 ```
Number of Subnets
When subnetting, calculate how many subnets you can create:
Formula:
Number of subnets = 2^(new_prefix - old_prefix)
Example: Subnet 192.168.1.0/24 into /26 networks ``` 2^(26-24) = 2^2 = 4 subnets
Subnet 1: 192.168.1.0/26 (192.168.1.0 - 192.168.1.63) Subnet 2: 192.168.1.64/26 (192.168.1.64 - 192.168.1.127) Subnet 3: 192.168.1.128/26 (192.168.1.128 - 192.168.1.191) Subnet 4: 192.168.1.192/26 (192.168.1.192 - 192.168.1.255) ```
Practical Examples
Example 1: Small Office Network
Requirement: 50 hosts
Calculation: ``` Need: 50 hosts Formula: 2^n - 2 ≥ 50 2^6 - 2 = 62 hosts ✓
Host bits needed: 6 Network bits: 32 - 6 = 26
CIDR: /26 Subnet mask: 255.255.255.192 Usable hosts: 62 ```
Configuration:
Network: 192.168.1.0/26
First IP: 192.168.1.1 (gateway)
Last IP: 192.168.1.62
Broadcast: 192.168.1.63
Example 2: Point-to-Point Link
Requirement: Connect two routers
Calculation: ``` Need: 2 hosts (2 routers) Formula: 2^n - 2 ≥ 2 2^2 - 2 = 2 hosts ✓
CIDR: /30 Subnet mask: 255.255.255.252 Usable hosts: 2 ```
Configuration:
Network: 10.0.0.0/30
Router A: 10.0.0.1
Router B: 10.0.0.2
Broadcast: 10.0.0.3
Example 3: Large Enterprise Network
Requirement: 5,000 hosts
Calculation: ``` Need: 5,000 hosts Formula: 2^n - 2 ≥ 5,000 2^13 - 2 = 8,190 hosts ✓
Host bits needed: 13 Network bits: 32 - 13 = 19
CIDR: /19 Subnet mask: 255.255.224.0 Usable hosts: 8,190 ```
Configuration:
Network: 172.16.0.0/19
Range: 172.16.0.1 - 172.16.31.254
Broadcast: 172.16.31.255
Subnetting with CIDR
Dividing a Network
Original network: 192.168.1.0/24
Divide into 4 equal subnets: ``` Need 4 subnets: 2^2 = 4 Borrow 2 bits: /24 + 2 = /26
Subnet 1: 192.168.1.0/26 Range: 192.168.1.1 - 192.168.1.62 Broadcast: 192.168.1.63
Subnet 2: 192.168.1.64/26 Range: 192.168.1.65 - 192.168.1.126 Broadcast: 192.168.1.127
Subnet 3: 192.168.1.128/26 Range: 192.168.1.129 - 192.168.1.190 Broadcast: 192.168.1.191
Subnet 4: 192.168.1.192/26 Range: 192.168.1.193 - 192.168.1.254 Broadcast: 192.168.1.255 ```
Variable Length Subnet Masking (VLSM)
Scenario: Different departments need different sizes
Network: 10.0.0.0/16
Requirements: - Sales: 500 hosts → /23 (510 hosts) - Engineering: 200 hosts → /24 (254 hosts) - HR: 50 hosts → /26 (62 hosts) - IT: 10 hosts → /28 (14 hosts)
Allocation: ``` Sales: 10.0.0.0/23 Range: 10.0.0.1 - 10.0.1.254
Engineering: 10.0.2.0/24 Range: 10.0.2.1 - 10.0.2.254
HR: 10.0.3.0/26 Range: 10.0.3.1 - 10.0.3.62
IT: 10.0.3.64/28 Range: 10.0.3.65 - 10.0.3.78 ```
CIDR for IPv6
IPv6 CIDR Notation
Format: Same as IPv4 but with /0 to /128
Examples:
2001:db8::/32 - Large allocation
2001:db8:1234::/48 - Site allocation
2001:db8:1234:5678::/64 - Subnet (standard)
2001:db8:1234:5678::/128 - Single host
Common IPv6 Prefixes
| CIDR | Purpose | |------|---------| | /128 | Single host | | /64 | Standard subnet | | /56 | Home network allocation | | /48 | Site allocation | | /32 | ISP allocation | | /3 | Global unicast |
CIDR in Routing
Route Aggregation (Supernetting)
Combine multiple networks into one route:
Individual routes:
192.168.0.0/24
192.168.1.0/24
192.168.2.0/24
192.168.3.0/24
Aggregated route:
192.168.0.0/22
Benefits: - Smaller routing tables - Faster routing decisions - Reduced memory usage - More efficient
Longest Prefix Match
Routers use longest prefix match for routing decisions.
Example routing table:
192.168.1.0/24 → Router A
192.168.0.0/16 → Router B
0.0.0.0/0 → Default gateway
Packet to 192.168.1.50: ``` Matches: 192.168.1.0/24 ✓ (24 bits) Matches: 192.168.0.0/16 ✓ (16 bits) Matches: 0.0.0.0/0 ✓ (0 bits)
Longest match: /24 Route via: Router A ```
CIDR Tools and Calculators
Online Calculators
Popular CIDR calculators: - ipcalc.org - subnet-calculator.com - cidr.xyz - jodies.de/ipcalc
Features: - Calculate subnet details - Convert between notations - Visualize subnets - Plan IP allocation
Command Line Tools
ipcalc (Linux): ```bash ipcalc 192.168.1.0/24
Output:
Address: 192.168.1.0
Netmask: 255.255.255.0 = 24
Wildcard: 0.0.0.255
Network: 192.168.1.0/24
HostMin: 192.168.1.1
HostMax: 192.168.1.254
Broadcast: 192.168.1.255
Hosts/Net: 254
```
sipcalc: ```bash sipcalc 10.0.0.0/8
Detailed subnet information
```
Python: ```python import ipaddress
network = ipaddress.IPv4Network('192.168.1.0/24') print(f"Network: {network.network_address}") print(f"Broadcast: {network.broadcast_address}") print(f"Netmask: {network.netmask}") print(f"Hosts: {network.num_addresses - 2}")
Iterate hosts
for ip in network.hosts(): print(ip) ```
Common Mistakes
Mistake 1: Wrong Network Address
Wrong:
192.168.1.100/24 as network address
Correct:
192.168.1.0/24 as network address
192.168.1.100/24 as host address
Mistake 2: Forgetting Unusable IPs
Wrong calculation:
/24 = 256 hosts
Correct:
/24 = 256 addresses
Usable hosts = 256 - 2 = 254
(minus network and broadcast)
Mistake 3: Overlapping Subnets
Wrong:
Subnet 1: 192.168.1.0/25 (0-127)
Subnet 2: 192.168.1.64/26 (64-127) ← Overlaps!
Correct:
Subnet 1: 192.168.1.0/25 (0-127)
Subnet 2: 192.168.1.128/25 (128-255)
Mistake 4: Incorrect Prefix Length
Wrong:
255.255.255.0 = /32
Correct:
255.255.255.0 = /24
(Count the 1 bits: 8+8+8=24)
Best Practices
Planning Networks
- Start with requirements - How many hosts needed?
- Allow for growth - Add 20-30% capacity
- Use standard sizes - /24, /25, /26 when possible
- Document everything - Keep CIDR allocation records
- Avoid waste - Don't allocate more than needed
Subnetting
- Use VLSM - Different sizes for different needs
- Align on boundaries - Use clean subnet boundaries
- Reserve space - Keep some subnets for future use
- Consistent scheme - Follow logical patterns
- Test calculations - Verify before implementation
Security
- Smallest necessary - Use smallest CIDR that fits needs
- Segment networks - Use subnets for security zones
- Document ACLs - Keep firewall rules with CIDR
- Regular audits - Review IP allocations
- Monitor usage - Track subnet utilization
Conclusion
CIDR notation is a fundamental concept in modern networking, providing an efficient way to represent IP addresses and subnet masks. Understanding CIDR is essential for network design, subnetting, routing, and IP address management.
Key takeaways: - CIDR uses /prefix_length to indicate network bits - More efficient than classful addressing - Enables flexible subnetting and route aggregation - Formula: Hosts = 2^(32-prefix) - 2 - Longer prefix = smaller network - Essential for modern IP networking - Used in routing, firewalls, and network configuration - Supports both IPv4 and IPv6
Mastering CIDR notation empowers you to design efficient networks, troubleshoot connectivity issues, and manage IP address space effectively.
Related Articles
Subnetting and IP Management
- IPv4 Subnetting - Network division fundamentals
- Subnet Mask - Understanding network masks
- IP Calculator - Calculate CIDR ranges and subnets
- IP Address Classes - Traditional classful addressing
IPv4 Fundamentals
- What is an IPv4 Address? - IPv4 basics
- IPv4 Private Ranges - RFC 1918 addresses
- Broadcast Address - Network-wide communication
- Private vs Public IP - Address types
Network Configuration
- Routing - How CIDR affects routing
- BGP - Route aggregation with CIDR
- Firewall Basics - Using CIDR in rules
- Network Scanning - Scanning CIDR ranges
Explore More
- IPv4 Guide - Complete IPv4 resource hub
- Networking Basics - Essential concepts
- Tools & Utilities - Network diagnostic tools