IP addresses are used throughout the Internet and in private networks to represent individual devices, such as laptops, smartphones, printers, servers, and routers. In order to participate in a network, a device must have a unique IP address. Computer networks can be viewed as collections of hosts, each with a unique IP address, that can communicate with each other.
Networks of IP addresses can be represented in different forms. In this article, I will clarify the CIDR notation for IP addresses and show how you can convert between IP ranges and CIDR block notation.
What is CIDR Notation
CIDR notation was developed in the early 1990s as a more flexible way of defining subnets. The previous system for IPv4 networks consisted of classes - class A, B, and C - each a different size and able to support a different number of hosts. The class system for networks is summarized in the table below.
|IP Address Class||# Subnet Bits||Subnet Mask||# Addresses||Example IP Address Range|
|Class A||8||255.0.0.0||16,777,216||10.0.0.0 - 10.255.255.255|
|Class B||16||255.255.0.0||65,534||192.168.1.0 - 192.168.1.255|
|Class C||24||255.255.255.0||254||10.5.1.0 - 10.5.1.255|
CIDR notation consists of an IP address followed by a forward slash followed by the number of subnet bits. CIDR notation gives a compact format for specifying the size of a subnet. Using CIDR notation, we can define blocks of IP addresses of any size, whereas the class system only allows for three sizes.
How to Convert an IP Range to CIDR Notation
I'll take you through the process of converting IP ranges to CID notations and CIDR notation to IP address ranges. The process is pretty straightforward.
To convert an IP range to CIDR notation, select an IP address from the subnet (ideally the network address) and add a forward slash (/) followed by the number of bits representing the subnet mask (example: 192.168.1.0/24). If you're not familiar with subnets and masks, I have a good article on subnetting that will walk you through the details.
Let's look at an example. Suppose you have the IP address range 192.168.1.0 through 192.168.1.255. The subnet mask for this subnet is 255.255.255.0. If we convert the subnet mask to its binary representation, we would get a sequence of 24 ones and 8 zeroes:
11111111111111111111111100000000. The number of ones is the same as the number of subnet bits, 24. The CIDR notation for the IP range 192.168.1.0 - 192.168.1.255 is 192.168.1.0/24.
Let me summarize what we just did to make it clear. To convert an IP address range to CIDR notation, convert the subnet mask to binary, count the number of ones, and add this number to the IP address following a forward slash. This process can be reversed to obtain the IP range again.
That's all there is to it! The CIDR notation is a more compact format than an IP address range and I find it much easier to read. It is trivial to convert between CIDR notation and IP ranges, especially with the help of an online subnet calculator like the one below.
Online Subnet Calculator
Resources for More Information
Below are a few resources for more information about Classless Inter-Domain Routing.
|What Is CIDR Notation?||WhatIsMyIPAddress|
|What is subnetting?||NetworkCalc|
|CIDR Notation - Explained & Examples||ShellHacks|