# CIDR Notation
## What is CIDR
CIDR stands for Classless Inter-Domain Routing. It is a method for allocating IP addresses and for routing that replaced the older classful addressing system in 1993. CIDR eliminates the fixed boundaries between address classes and allows the network portion of an IP address to be of any length from 1 to 32 bits. This flexibility allows IP addresses to be allocated more efficiently and enables route aggregation, both of which help manage the limited IPv4 address space.
## CIDR Notation Format
CIDR notation represents an IP address and its associated network prefix length as a single compact expression. It is written as an IP address followed by a forward slash and a number representing the number of bits in the network portion of the address. For example, 192.168.1.0/24 indicates a network where the first 24 bits represent the network address and the remaining 8 bits are available for host addresses. The number after the slash is called the prefix length.
## Common CIDR Prefixes
The /8 prefix, equivalent to the old Class A default subnet mask of 255.0.0.0, covers 16,777,216 addresses. The /16 prefix, equivalent to the old Class B mask of 255.255.0.0, covers 65,536 addresses. The /24 prefix, equivalent to the old Class C mask of 255.255.255.0, covers 256 addresses with 254 usable hosts. The /30 prefix covers 4 addresses with only 2 usable hosts and is commonly used for point-to-point links between routers. The /32 prefix identifies a single host address.
## Converting Between CIDR and Subnet Mask
Converting from CIDR prefix length to subnet mask involves writing a 32-bit number where the first n bits, where n is the prefix length, are all 1 and the remaining bits are all 0, then converting to dotted decimal. A /24 in binary is 11111111.11111111.11111111.00000000, which is 255.255.255.0. A /25 in binary is 11111111.11111111.11111111.10000000, which is 255.255.255.128. Converting from subnet mask to CIDR prefix length involves counting the number of 1 bits in the subnet mask.
## CIDR and Efficient Address Allocation
Before CIDR, addresses had to be allocated in blocks matching the class boundaries. An organization needing 500 addresses had to receive a Class B block of 65,536 addresses, wasting over 65,000. With CIDR, an organization needing 500 addresses can receive a /23 block providing 512 addresses, wasting only 10 addresses. This more efficient allocation slowed the exhaustion of IPv4 addresses significantly.
## CIDR in Routing
CIDR enables route aggregation at arbitrary boundaries. An internet service provider with the address block 203.0.113.0/24 can allocate subnets like /25, /26, /27, or /28 to customers, and advertise only the single /24 route to the rest of the internet. This keeps the global routing table much smaller than if every customer subnet were advertised individually.Back to Course