Wednesday, 19 July 2023

CIDR: The Modern Way to Handle Subnets

What is CIDR?
CIDR (Classless Inter-Domain Routing) is a method for allocating IP addresses and routing that replaced the old "classful" system. It uses a slash notation to specify how many bits are used for the network portion.
Format: IP Address/Network Bits
Example: 192.168.1.0/24

How CIDR Notation Works
The Number After the Slash
The /24 tells us how many bits (from left) represent the network:
192.168.1.0/24
├── Network bits: 24 (first 24 bits)
└── Host bits: 8 (remaining 8 bits)

Binary view:
11000000.10101000.00000001.00000000
|--------Network (24 bits)-------|Host|

Common CIDR Examples
CIDR    Subnet Mask               Network Bits    Host Bits    Available IPs
/8     255.0.0.0          8       24     16,777,214
/16    255.255.0.0        16      16     65,534
/24    255.255.255.0      24      8      254
/25    255.255.255.128    25      7      126
/26    255.255.255.192    26      6      62
/27    255.255.255.224    27      5      30
/28    255.255.255.240    28      4      14
/30    255.255.255.252    30      2       2

How CIDR Helps with Subnetting
1. Flexible Subnet Sizing
Instead of fixed Class A, B, C sizes, you can create any size you need:
Old way (Classful):
- Class C: 192.168.1.0 = exactly 254 hosts
- No flexibility

New way (CIDR):
- /25 = 126 hosts
- /26 = 62 hosts  
- /27 = 30 hosts
- /28 = 14 hosts

2. Efficient Address Usage
Example: You need 50 IP addresses
Without CIDR: Forced to use Class C (254 IPs) - waste 204 addresses
With CIDR: Use /26 (62 IPs) - waste only 12 addresses

3. Easy Subnet Calculation
Subnetting 192.168.1.0/24 into smaller subnets:
Original: 192.168.1.0/24 (254 hosts)

Split into /25:
├── 192.168.1.0/25   (126 hosts: .1-.126)
└── 192.168.1.128/25 (126 hosts: .129-.254)

Split into /26:
├── 192.168.1.0/26   (62 hosts: .1-.62)
├── 192.168.1.64/26  (62 hosts: .65-.126)
├── 192.168.1.128/26 (62 hosts: .129-.190)
└── 192.168.1.192/26 (62 hosts: .193-.254)

4. Quick Binary Math
To find subnet info:
Network bits: First X bits (from CIDR)
Host bits: Remaining 32-X bits
Subnet size: 2^(host bits) - 2
Subnets possible: 2^(borrowed bits)

Practical CIDR Examples
Example 1: Office Network Planning

Company gets: 10.0.0.0/16

Departments needed:
- Sales (100 users): 10.0.1.0/25 (126 IPs)
- Engineering (200 users): 10.0.2.0/24 (254 IPs)  
- HR (20 users): 10.0.3.0/27 (30 IPs)
- Printers (10 devices): 10.0.4.0/28 (14 IPs)

Example 2: ISP Address Allocation
ISP has: 203.0.113.0/24

Customer allocations:
- Large business: 203.0.113.0/26 (62 IPs)
- Medium business: 203.0.113.64/27 (30 IPs)
- Small business: 203.0.113.96/28 (14 IPs)
- Home users: 203.0.113.112/28 to 203.0.113.240/28

CIDR vs Old Classful System
Old Way (Classful)
Class A: /8  - 16M addresses (usually too big)
Class B: /16 - 65K addresses (often too big) 
Class C: /24 - 254 addresses (often too small)

New Way (CIDR)
Any size from /1 to /32
Perfect fit for actual needs
No address waste

Quick CIDR Calculation Tricks
Finding Subnet Size
Formula: 2^(32-CIDR) - 2

/24: 2^(32-24) - 2 = 2^8 - 2 = 254 usable IPs
/26: 2^(32-26) - 2 = 2^6 - 2 = 62 usable IPs
/30: 2^(32-30) - 2 = 2^2 - 2 = 2 usable IPs

Finding Number of Subnets
To subnet /24 into /26:
Borrowed bits = 26 - 24 = 2
Number of subnets = 2^2 = 4 subnets

Real-World Benefits
Reduced Routing Tables - ISPs can aggregate routes
Flexible Allocation - Match network size to actual needs
Address Conservation - Use only what you need
Simplified Management - Consistent notation across all networks



No comments:

Post a Comment