CIDR Notation Explained: Subnetting for Developers - DataMorph
Learn CIDR notation, subnetting concepts, subnet masks, IP address calculations, and network configuration with clear examples.
CIDR Notation Explained: Subnetting for Developers
CIDR (Classless Inter-Domain Routing) is a method used to allocate IP addresses and route packets on the Internet. Introduced in 1993, CIDR replaced the older, inefficient Class-based IP addressing system (Classes A, B, and C). It allows for much more flexible IP allocation, which is essential for cloud computing networks (VPCs) and modern system architecture.
A CIDR block is written as an IP address followed by a slash and a number, such as 192.168.1.0/24. The number after the slash is the prefix length (subnet mask), indicating how many bits of the address are reserved for the network identifier, leaving the remaining bits for host addresses.
How CIDR Subnetting Works
An IPv4 address consists of 32 bits divided into 4 octets. In CIDR notation:
- /32 means all 32 bits are network bits, leaving 0 bits for hosts. This specifies a single, unique IP address.
- /24 means 24 bits are network bits (first 3 octets), leaving 8 bits for host addresses (32 - 24 = 8).
- With 8 host bits, you can have 28 = 256 total IP addresses in the subnet.
Calculating Usable Hosts
In any IP subnet, the total number of IP addresses is 2(32 - prefix). However, the number of usable hosts is always two less than the total count: Usable Hosts = Total IPs - 2. This is because two special addresses are always reserved by default:
- Network Address (First IP): Used to identify the subnet itself (e.g., 192.168.1.0).
- Broadcast Address (Last IP): Used to send packets to all hosts on the subnet simultaneously (e.g., 192.168.1.255).
Use Cases
- Define network subnets for virtual private clouds (VPCs) on AWS or GCP.
- Calculate usable IP addresses for host assignments in local networks.
- Set up routing table guidelines and firewall access control lists (ACLs).
Frequently Asked Questions
Why are there two unusable IP addresses in a subnet?
The first address in the subnet range is the network address, and the last address is the broadcast address. Neither can be assigned to an active device/host.
How many IPs are in a /24 subnet?
A /24 subnet contains 256 total IP addresses, of which 254 are assignable to hosts (servers, computers, routers).
What is a subnet mask?
A subnet mask is a 32-bit number that masks an IP address, dividing the IP address into network address and host address. For example, /24 corresponds to 255.255.255.0.