Introduction to CIDR
An in-depth look at CIDR, a method for allocating IP addresses and routing IP packets more efficiently in networking.
Airyland
October 25, 2024
Introduction
Classless Inter-Domain Routing (CIDR) is a method for allocating IP addresses and routing Internet Protocol packets. Introduced in the mid-1990s, CIDR was developed to improve the allocation of IP addresses and to slow the growth of routing tables on routers across the Internet.
Background
Prior to CIDR, IP addresses were allocated based on classful addressing, which divided the address space into fixed classes (A, B, C, etc.) based on the first few bits of the address. This system led to inefficient allocation and rapid exhaustion of the available address space.
What is CIDR?
CIDR replaces the classful network design by allowing variable-length subnet masking (VLSM). It enables a more flexible division of IP address space, allowing for the allocation of IP addresses in blocks of sizes that better match the needs of organizations.
CIDR Notation
CIDR notation specifies an IP address and its associated routing prefix. It is written as the IP address, followed by a slash ("/"), and then the number of bits in the prefix. For example:
192.168.0.0/24
This notation indicates that the first 24 bits of the IP address are the network prefix.
Similarly, with IPv6:
2001:0db8::/32
How to Convert CIDR Notation
Converting CIDR notation involves determining the subnet mask and the range of IP addresses encompassed by the CIDR block. Here's how you can perform the conversion:
1. Calculate the Subnet Mask
The subnet mask can be derived by setting the first n
bits to 1, where n
is the prefix length, and the remaining bits to 0.
- For IPv4:
For example, to convert/24
:Prefix Length: 24 Subnet Mask: 255.255.255.0
Calculation:- 24 bits set to 1:
11111111.11111111.11111111.00000000
- Converted to decimal:
255.255.255.0
- 24 bits set to 1:
- For IPv6:
IPv6 uses a similar approach but with 128-bit addresses.
Example:Prefix Length: 32 Subnet Mask: ffff:ffff:ffff:ffff::
Calculation:- 32 bits set to 1:
11111111.11111111.11111111.11111111.00000000....
- Converted to hexadecimal:
ffff:ffff:ffff:ffff::
- 32 bits set to 1:
2. Determine the IP Address Range
- Starting IP Address:
The network address with all host bits set to 0.
Example:CIDR: 192.168.1.0/24 Starting IP: 192.168.1.0
- Ending IP Address:
The broadcast address with all host bits set to 1.
Example:CIDR: 192.168.1.0/24 Ending IP: 192.168.1.255
3. Total Number of IP Addresses
The total number of IP addresses in a CIDR block is 2^(32 - prefix length)
for IPv4 and 2^(128 - prefix length)
for IPv6.
Example:
CIDR: 192.168.0.0/24
Total IPs: 256 (from 192.168.0.0 to 192.168.0.255)
How CIDR Works
CIDR allows for the aggregation of multiple IP addresses into a single routing entry, reducing the size of routing tables and improving routing efficiency.
For example, instead of listing individual networks:
192.168.0.0/24
192.168.1.0/24
192.168.2.0/24
192.168.3.0/24
CIDR allows these to be aggregated into:
192.168.0.0/22
This represents the block from 192.168.0.0 to 192.168.3.255.
Benefits of CIDR
- Efficient IP Address Allocation: Reduces wastage by allowing allocation of IP blocks tailored to size requirements.
- Reduced Routing Table Size: Aggregation of routes decreases the number of entries in routing tables, leading to faster routing.
- Scalability: Makes the growth of the Internet's routing system more manageable.
CIDR and Subnetting
CIDR's use of variable-length subnet masks allows for both subnetting and supernetting, providing flexibility in network design.
Example
Suppose an organization requires 100 IP addresses. Classful addressing would require allocating a Class A or Class B address block, which are oversized. With CIDR, a block of 128 addresses can be allocated using a /25 prefix (since 2^(32-25)=128).
Conclusion
CIDR revolutionized IP address allocation and routing, addressing the limitations of classful addressing and paving the way for the efficient scaling of the Internet.