3
upImage may be NSFW.
Clik here to view.

Image credits :
Pixabay
One of the key concepts in network routing that any Linux professional should be familiar with is networknotation. 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 classesBefore 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 (2 24 ) B 10 128.0.0.0 191.255.255.255 255.255.0.0 /16 16,384 65,536 (2 20 ) C 110 192.0.0.0 223.255.255.255 255.255.255.0 /24 2,097,152 256 (2 8 ) D 1110 224.0.0.0 239.255.255.255 Undefined Undefined E 1111 240.0.0.0 255.255.255.255 Undefined UndefinedTable 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.
$ sipcalc 10.125.0.0/16 -[ipv4 : 10.125.0.0/16] - 0 [CIDR] Host address - 10.125.0.0 Host address (decimal) - 175964160 Host address (hex) - A7D0000 Network address - 10.125.0.0 Network mask