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 Internet scale networks.

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, the IP address.

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

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 authority being IANA.

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


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.


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 sub-networks 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-127 then you know it is a class A IP address. 128-191 is class B and 192-224 is class C.


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: / 16
i.e. 16 bits are turned on in the binary subnet mask format and this brings us to CIDR's.


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 subents because we are not bound by whole octets.

Let's say we want to divide 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 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -

Adnan Mujkanovic

Adnan Mujkanovic

Full Stack Overflow Developer / YAML Indentation Specialist / Yak Shaving Expert
Gotham City