CIDR (Classless Inter-Domain Routing)

A bit about binary

IP addresses are just numbers, each host on a network must have a different, unique number so it knows that data sent over the network belongs to it and not any other host. Human beings count in “decimal” probably because most of us have ten digits on our hands, so the number 26 really means 2 lots of 10, plus 6 lots of 1’s. Computers count in binary because internally they use transistors that are either ON or OFF so they can only have two states 1 or 0. Whereas in our decimal world each time we add a new column of numbers to the left we increase the value of that column by ten, in binary each time we add a new column to the left we increase the value of that column by 2.

For example: The number 123 has three columns, the right most column depicts how many 1’s there are in the number (3 in this example), the middle column depicts how many tens there are (2 in this example) and the left most column depicts how many hundreds there are (1 in this example). So each time we move to the left we multiply the value the column represents by ten – 1, 10, 100 and so on.

The same principle applies to binary, the right most column represents how many 1’s there are in the number, the next column to the left represents how many 2’s there are in the number, then 4’s, 8’s, 16’s, 32’s and so on. So the binary number 100110 actually means (starting at the right most column) 0 lots of 1’s, plus 1 lot of 2’s, plus 1 lot of 4’s, 0 lots of 8’s, plus 0 lots of 16’s, plus 1 lot of 32’s. If you add those up: in order 0 + 2 + 4 + 0 + 0 + 32 = 38

In mathematical terms it is easier to represent this calculation using powers, so in binary if we say the first (right most) bit is position zero, the next one to the left is position 1, then position 2, and so on. We can calculate the value each bit’s position represents by raising 2 to the power of it’s position, for example:

The right most bit (position zero): 2 to the power of 0 = 1, so the right most position represents how many 1’s there are in the overall number.

The next bit to the left (position 1): 2 to the power of 1 = 2, so this bit represents how many 2’s there are in the overall number.

The next bit to the left (position 2): 2 to the power of 2 = 4, so this bit represents how many 4’s there are in the overall number, and so on.

We normally write “to the power of” using the shorthand ^ So 2 to the power of 3 would be written as 2^3 which equals 8

In computer parlance each “digit” is called a bit. So 100110 is a binary number consisting of 6 bits and represents the number 38 in decimal.

Computers arrange numbers internally in blocks of 8 bits, such a block is called a byte. So the example above could be written (in binary) as 00100110

IPv4 addresses

The first official IPv4 address standard was published in 1980 and specified that 32 bits were to be used to uniquely address every host on a World wide network (what was to become The Internet). 32 bits can represent 2^32 which equates to 4,294,967,296 addresses in decimal. This is nearly 4.3 billion addresses, and it was thought at the time that this would be more than enough. How wrong they were!

Now reading 32 bits of binary digits might be easy for a computer, but the humans brain is not really geared up to reading binary numbers, although if you work in digital electronics long enough you get used to them! So when it comes to representing IPv4 addresses, the 32 bits were split up into four blocks of 8 bits, or four bytes. Each byte was to be written in decimal with a dot between each number, this became known as the ubiquitous dotted quad, for example: 44.55.66.77

IPv4 networks

The global internet consists of many “networks of networks”, within each of these individual networks, the hosts within them need to know which network they are connected to, so when we specify a network, the overall IP address is split up into two parts: The network address and the host address. The network address is the most significant bits on the left, the host address is the remaining bits on the right. Here are some examples written in binary:

                            NETWORK- HOST----------------------
                            00101100 00110111 01000010 01001101
                        

If you do the calculations you will see that this represents the IPv4 address: 44.55.66.77 the network part is 44 and the host part is 55.66.77

                            NETWORK---------- HOST-------------
                            00101100 00110111 01000010 01001101
                        

Again this represents the IPv4 address: 44.55.66.77 but this time the network part is 44.55 and the host part is 66.77

Different classes

When The Internet was first created IP addresses were split up into discrete blocks or "classes". Three different classes were originally specified:

Class A: This consisted of a network who’s most significant bit was set to zero. The next 7 bits then defined the network part of the address, followed by 24 bits for the host part of the address. This allows for 2^7 = 128 networks, each comprising of 2^24 = 16,777,216 hosts.

Class B: This consisted of a network mask with 16 bits, IPv4 addresses contain 32 bits, therefore each Class B network consisted of 32 - 16 = 16 bits, 2 to the power of 16 = 65,536 addresses.

Class C: This consisted of a network mask with 24 bits, IPv4 addresses contain 32 bits, therefore each Class C network consisted of 32 - 24 = 8 bits, 2 to the power of 8 = 256 addresses.

Later on it was realised that specifying only three classes was too restrictive so there had to be some way of defining different sized networks, enter Classless Inter-Domain Routing or CIDR.

The CIDR specification allows for a variable number of bits to define the size of the network. As IPv4 addresses are 32 bits long, by definition this means the CIDR value can be anything from “32” to “0”, although in practice the smallest CIDR value is generally “8”. The CIDR part of the network is suffixed to the network address (first IP address of the network) with a forward slash, e.g. /24

In order to calculate the size of a CIDR network you use the same logic detailed above, for example a CIDR value of /32 consists of a network 32 – 32 = 0, 2 to the power of 0 = 1 IP address. A /28 network would consist of 32 – 28 = 4, 2 to the power of 4 = 16 IP addresses, and so on.

The network address has to be on a “bit boundary” appropriate to the size of the network, for example if you are specifying a /29 (8 IP addresses) then valid network addresses are every 8 (starting at zero). Here is an example:

Network address (first IP in the network): 44.55.66.0 CIDR: /29 (8 IP addresses) This would define a network starting at 44.55.66.0 and ending at 44.55.66.7 (0 to 7 = 8 IP addresses).

You can visualise this quite easily by looking at the bits that make up the address: Each byte has 8 bits (value of 0 to 255). An IPv4 address is made up of 32 bits, or 4 bytes (4 x 8 = 32). That is why IPv4 addresses are written as four bytes separated by dots, e.g. 44.55.66.77

If we show the bits in each byte it looks like this:

                            Decimal:        44       55       66       77
                            Binary:      00101100 00110111 01000010 01001101
                            Netmask:     11111111 11111111 11111111 11111000