Network Layer (Internet Protocol), IP's, Subnets and CIDR's

On a local network computers can communicate using their MAC addresses. This solution is great for local networks but is not scalable to an Internet scale network.

Internet Protocol to the rescue. IP was introduced by Vint Cerf and Bob Kahn in 1974.

IP Addresses (v4)

If you want to communicate with a relative in another country, you could do it via telephone but first you need to know their number. The same thing is true for computer networks. If you want to communicate with another computer in another country you need to know its number or in the case of computer networks, IP address.

IP address are numbers assigned to computers in a network (their network interfaces).

IP addresses are 32 bit long numbers made up of 4 octets (8 bits). IPv4 dotted-decimal notation and its binary counterpart look as follows:

176 . 16 . 230 . 1
10101100 . 00010000 . 11100110 . 00000001

You will never see one of the numbers in decimal notation bigger than 255 or smaller than 0. That's because each part of the IP consists of 8 bits (Octet). The highest number you can get from 8 bits is 255.

Public IP addresses and ranges are hierarchically distributed with the highest authority being IANA.

IP addresses belong to the network and the network assigns (DHCP or a manual process) them to individual computers.

Datagrams

Datagrams are the units used in IP network communications. Two main components of a datagram are the header and the payload.

The payload is the data being transmitted over the network. The header is used by routers and contains information (source IP, destination IP...) necessary for the datagram to reach its destination independently.

Classes

IP addresses consist of two parts. The network id and the host id. There are three main classes of IP addresses.

  • Class A
    First octet is the network and the 3 remaining are octets are used for the host
  • Class B
    First two octets are used for the network and the 2 remaining for the host
  • Class C
    First three octets are used for the network and the one remaining for the host

The IP address class is what determines the maximum number of subnetworks and hosts. In a class A network there is a 16.777.216 maximum number of hosts. In a class C there are only 254. That is because the higher the class the more host bits are available and vice versa.

You can recognize classes by their range. In dotted-decimal notation, if the first of 4 parts of the IP address starts with a number ranging from 0 to 126 then you know it is a class A IP address. 128-191 is class B and 192-224 is class C.

Subnetting

As the name suggests, subnetting is the process of dividing networks into smaller networks also called subnets.

We mentioned above that IP addresses are divided into the network part and the host part. In this case the question would be "How are they divided" or "What determines which part of the IP address will be the network id and which part will be the host id"?

Subnet masks determine which part of the IP address is the network id and which part is the host id.

IP 172 . 31 . 5 . 7
Subnet Mask 255 . 255 . 0 . 0
Subnet Mask in Binary 11111111 . 11111111 . 00000000 . 00000000

For me the easiest way to see where an IP address is divided is by looking at the subnet mask in binary i.e. where do the 1's stop and the 0's start. In the table above the network id is 172.31 and the host id is 5.7.

Another useful way of representing the subnet mask is by a slash and then the number of 1's in the binary subnet mask format. In the case above this would be:

172.31.0.0 / 16
i.e. 16 bits are turned on in the binary subnet mask format.

CIDR

We mentioned how IP addresses are divided into classes. Well, the classes approach can be useful but it is out of date. The current approach of dividing IP addresses into groups or blocks is called "Classless Inter-Domain Routing".

CIDR gives us more flexibility with our networks and their subnetworks because we are not bound by whole octets.

Let's say we want to divide 172.31.0.0/16 into 8 subnets each having a maximum number of 8192 hosts. For this task we would use /19 for our subnet mask. In table this would look as follows:

Subnet ID Subnet Address Host Address Range
1 172.31.0.0 172.31.0.1 - 172.31.31.254
2 172.31.32.0 172.31.32.1 - 172.31.63.254
3 172.31.64.0 172.31.64.1 - 172.31.95.254
4 172.31.96.0 172.31.96.1 - 172.31.127.254
5 172.31.128.0 172.31.128.1 - 172.31.159.254
6 172.31.160.0 172.31.160.1 - 172.31.191.254
7 172.31.192.0 172.31.192.1 - 172.31.223.254
8 172.31.224.0 172.31.224.1 - 172.31.255.254
Adnan M.

Adnan M.