One of the key concepts in network routing that any Linux professional should be familiar with is network notation. This article was inspired by a request from a reader of my article, An introduction to Linux network routing, to explain more about CIDR notation and how it works. CIDR stands for Classless-Inter Domain Routing; it defines a notation methodology for network addressing that is used to specify the network portion of an IP address.

Network classes

Before examining how CIDR actually works, let’s first look at the classful network notation that CIDR replaces. Introduced in 1981, the classful methodology defined five network classes to be used for identification and addressing devices on the Internet. The network class is defined by the four leading bits of the address.

Class

Leading bits

Start

End

Subnet Mask

CIDR

Networks

IP Addr / Network

A

0

0.0.0.0

127.255.255.255

255.0.0.0

/8

128

16,177,216 (224)

B

10

128.0.0.0

191.255.255.255

255.255.0.0

/16

16,384

65,536 (220)

C

110

192.0.0.0

223.255.255.255

255.255.255.0

/24

2,097,152

256 (28)

D

1110

224.0.0.0

239.255.255.255

Undefined

Undefined

E

1111

240.0.0.0

255.255.255.255

Undefined

Undefined

Table 1: Classful Internet addressing defines five classes.

Table 1 shows the five network classes defined by classful network addressing, including both the subnet mask and CIDR notation for each class. Classes A, B, and C are the commonly used unicast address ranges that were assigned to organizations. Unicast means that the data packets are sent to a single target host. Class D was the so-called multicast range of addresses. In this range, data packets would be sent to all hosts on a defined network. This range of IP addresses was essentially unused. The Class E address range was reserved for future expansion but was also never used.

Note that there are only three possible subnet masks that match each class of the classful networks, 255.0.0.0 (8 bits), 255.255.0.0 (16 bits), and 255.255.255.0 (24 bits), divided on the octet boundaries. This is one of the limiting factors in public address allocation due to the relatively limited number of networks that the classes define.

Unfortunately, classful networking assignments led to major waste. Organizations would apply for a number of addresses but if they needed more than the number of addresses in a class C network, for example, they would be applied for and be assigned an entire class B network whether they needed all of the addresses in that network or not. The same is true for class B networks; a few large organizations needed more than a class B network, so they were assigned class A networks. Thus a few large organizations became assigns of very large numbers of IP addresses. See the References, below, for a link to the complete list of the assigns of the current /8 blocks and historical Class A networks.

It is important to understand that the four leading (leftmost) bits of the address define the class of the network, not the subnet mask or the CIDR equivalent of the subnet mask. In practical terms, this meant that large networks could not be broken down into smaller subnets at the Internet level because the Internet routers could only have a single route to each assigned classful network. Further, although the large, classful networks could be divided into subnets by the organizations that owned them, routing packets to other geographical locations on the same network then required the organization to use private internal networks or public VPNs at a very high premium cost.

For a simple example, imagine that a company that has six departments and requires about 400 IP addresses for each. This requires more than a single class C network of 256 IP addresses, a total of 2,400 addresses. The company has a class B network of 65,536 addresses assigned to it. As a result, the remaining 63,136 IP addresses would be wasted because they could not be assigned to other organizations.

Note: For the purposes of this example, it is necessary to use a portion of the current private 10.0.0.0/8 CIDR block of addresses as if it were a public class B address. This is to protect public addresses that may belong to some organization.

I used the sipcalc command-line program to provide the network data for this randomly selected class B network from the pseudo-public address range. The sipcalc command provides a great deal of information about an IP address, or address ranges. As you will see later, it also has the capability to generate a list of subnets in a given address range given a subnet mask. You may have to install the sipcalc program; it was not installed by default on my Fedora system.

The output from the sipcalc command in Figure 1 shows, among other things, the network address, the netmask, the network address range as well as the available addresses in that range. The address 10.125.0.0 is the network address, and 10.125.255.254 is the broadcast address for this network. Those two addresses cannot be used for hosts.

Another option would have been to assign multiple class C networks to the company. That would significantly reduce the number of wasted IP addresses, but configuring the routing for this organization would be more complex than it would otherwise need to be with a single network. This option would also reduce the number of class C address blocks available for other organizations.

Along came a CIDR

CIDR notation was introduced in 1993 as a means of extending the lifetime of IPV4 which was running out of assignable addresses. It accomplishes this by making it possible for organizations to more fully utilize the public IPV4 address ranges assigned to them and by opening up some previously reserved address ranges.

In 1996, RFC1918 enhanced CIDR with the assignments of reserved, externally non-routable networks in each of the old A, B, and C, class ranges. These private networks can be used freely by any organization for their internal networks; no longer is it necessary for every computer to have an assigned public IP address. This feature provides a significant portion of the solution to multiple problems.

CIDR Block

Address Range

Number of IP Addresses

10.0.0.0/8

10.0.0.0 – 10.255.255.255

16,777,216

172.16.0.0/12

172.16.0.0 – 172.31.255.255

1,048,576

192.168.0.0/16

192.168.0.0 – 192.168.255.255

65,536

Table 2: Address ranges reserved for use as internal networks.

The use of these private internal networks allows organizations to be assigned one or possibly a few public IP addresses for access to the outside Internet while providing large private address spaces for internal networks. To be absolutely clear, each of these address ranges can be used by many different organizations because these private network addresses are not routable through the Internet; of course, organizations can route internally between private networks.

Returning to our example company, let’s make the assumption that it only requires a single public IP address to connect it to the outside world. The company’s Internet provider only assigns minimum blocks of 4 addresses, two of which are reserved for the network address and the broadcast address thus leaving 2 usable addresses. This provides a balance between unusable addresses due to excessive subnetting, wasted addresses, and cost to the customer.

The ISP assigns the company a public network address, 10.125.16.32/30. Remember that, for this example, we are using part of the 10.0.0.0/8 private network as if it were public. This assignment provides the company with the following public network.

Our example company can then choose to use any of the private network ranges for their internal networks. They can then use Network Address Translation (NAT) to access the outside world from their internal, private network.

At first glance, the straightforward thing to do might be to choose a network from the private 172.16.0.0/12 range to provide a large enough range for a single internal network. For our example, they could choose the 172.16.0.0/12 network which would provide the following internal network space for them.

Note that this network does not conform to the old B-class network as it has fewer network bits in the netmask, thus providing more space for host address bits. The 12 network bits leaves 20 bits for hosts, or 1,048,576 hosts total. That is far more hosts available than an old class B network would provide for a network. It is also far more space than they actually need for their network.

Variable length subnet masking (VLSM)

CIDR also brings with it a new approach to the old netmask, called variable length subnet masking, or VLSM. The use of a 12-bit netmask for the private address range defined by the CIDR block in Figure 3 hints at this.

VLSM allows our example company to easily create more manageable subnets from the large private address space available to them by adding bits to the netmask. Using the 12-bit netmask encompasses this entire available private address range, so in order to be more conservative about the address space that the company actually needs, they decide to increase the number of bits in the netmask they will use.

The sipcalc -s xx command, where xx is the number of bits in the subnet mask, can be used to calculate the subnets in this private address range. For example Figure 4, below, shows the 16 subnets of 172.16.0.0/12 that have a 16-bit subnet mask.

Figure 4: Using sipcalc to calculate the 16-bit subnets of the 172.0.0/12 private address range.

Using sipcalc to calculate the number of addresses provided by various numbers of bits in the netmask of the 172.16.0.0/12 network, they determine the following:

Bits in netmask

Number of addresses

12

1,048,576

16

65,536

17

32,768

18

16,384

19

8,192

20

4,096

Table 3: Number of addresses in various subnet ranges for network 172.16.0.0/12

As mentioned before, the company currently needs about 2400 IP addresses. To allow plenty of room for growth while reducing the total number of addresses to a manageable level, the company chooses to use a 19-bit netmask that provides 8,192 addresses. They calculate the available 19-bit subnets using sipcalc as shown in Figure 5, below.

Of course, this is only one possible 19-bit subnet out of 128 in the private address range. The company could have chosen any of the 19-bit subnets calculated in Figure 5, any of which would work equally well.

Another option would be to use the 192.168.0.0/16 private address range and select one of the 19-bit subnets available in that range. I leave the task of determining how many and which subnets would be available in that range as an exercise for the reader.

Conclusions

Using CIDR notation along with the reorganization of previously allocated addresses by CIDR block, as well as the use of VLSM provides more usable public IP addresses and increased flexibility in the assignment of public addresses. The design of CIDR notation with VLSM respects the old classful networking scheme while providing significantly more flexibility and IP address availability for private internal use by organizations of all sizes. Private address spaces, as well as assigned public address spaces, can be easily split into subnets by adding bits to the netmask without consideration for network classes.

CIDR notation can be used when referring to classful networks but only as a notational shorthand.