0
0
Computer-networksConceptBeginner · 4 min read

What is CIDR Notation: Explanation and Examples

CIDR notation is a compact way to represent IP addresses and their network size using a format like 192.168.1.0/24. The number after the slash shows how many bits are used for the network part, helping define the range of IP addresses in that network.
⚙️

How It Works

CIDR stands for Classless Inter-Domain Routing. It helps organize IP addresses by combining an IP address with a number that shows how many bits are fixed for the network part. Think of it like a street address with a zip code: the zip code narrows down the area, and the street address points to a specific house.

In CIDR, the number after the slash (called the prefix length) tells you how many bits of the IP address are used to identify the network. The remaining bits are for devices within that network. This method replaces the older system that used fixed classes, allowing more flexible and efficient use of IP addresses.

💻

Example

This example shows how to calculate the range of IP addresses from a CIDR notation.

python
import ipaddress

cidr = ipaddress.ip_network('192.168.1.0/24')
print(f'Network: {cidr.network_address}')
print(f'Netmask: {cidr.netmask}')
print(f'Broadcast: {cidr.broadcast_address}')
print(f'Number of addresses: {cidr.num_addresses}')
print('Usable IP addresses:')
for ip in cidr.hosts():
    print(ip)
Output
Network: 192.168.1.0 Netmask: 255.255.255.0 Broadcast: 192.168.1.255 Number of addresses: 256 Usable IP addresses: 192.168.1.1 192.168.1.2 192.168.1.3 ... 192.168.1.254
🎯

When to Use

CIDR notation is used whenever you need to define or understand IP address ranges in networks. It is essential for network administrators to allocate IP addresses efficiently without wasting them. For example, internet service providers use CIDR to assign blocks of IP addresses to customers.

It is also used in configuring routers, firewalls, and servers to specify which IP addresses belong to a network or should be allowed or blocked. CIDR helps manage networks of all sizes, from small home networks to large enterprise or internet-wide systems.

Key Points

  • CIDR notation combines an IP address and a prefix length to define a network.
  • The prefix length shows how many bits are fixed for the network part.
  • It replaces older fixed-class IP addressing for more flexible allocation.
  • Used widely in network configuration and IP address management.

Key Takeaways

CIDR notation efficiently represents IP address ranges using a prefix length.
The number after the slash indicates how many bits define the network portion.
It allows flexible and precise allocation of IP addresses beyond fixed classes.
CIDR is essential for network setup, routing, and IP management.
Understanding CIDR helps in configuring networks and security rules.