Understanding IPv4: The Basics of Internet Protocol  (Part 1)

Understanding IPv4: The Basics of Internet Protocol (Part 1)

Let us understand the concept of Network Layer first before jumping on to the concept of IPV4.

Network Layer

The network layer is a layer in the OSI (Open Systems Interconnection) model and the TCP/IP protocol suite that is responsible for routing data packets from the source to the destination over a network. It is sometimes also referred to as the Internet layer.

Let me explain Network Layer with the help of an Example.

Suppose there is one Network in India and there is one host(which is your computer) within your network and within the Host, there are many processes, and the one process is you have opened www.facebook.com, Now you want to go to Facebook and open its WebPage.

Now Assume that there is a network somewhere in the USA, Now inside this network, one of the process is the Facebook server, which you want to connect. This means you want to connect the process from home to the process of Facebook to get the web page.

so what did you type in your web browser is www.facebook.com, so when you type the domain name, this domain name needs to be converted in such a way that you can identify the Network.

There are 3 steps involved here

  1. So first you will send the request to the network in the USA(which is your destination network).

  2. then your request needs to be reached the destination Host within the network

  3. after reaching the destination Host the request needs to be reached the destination process.

So to identify the destination network, and destination host, we have actually only given the domain name(www.facebook.com), so using this domain name we have to identify the destination network and destination host, so to do this we will have to convert this domain name into IP Address, Now you might be thinking why to convert the domain name into IP Address.

Now let me explain to you the concept of IP ADDRESS.

IPV4 Address

An IPV4 address is a 32-bit address that uniquely defines the connection of the host to the internet.

IPV4 addresses are unique to every host or device on the internet.

The primary function of the IP Address is to identify the destination network and destination Host, So to do this thing we will have to convert the domain name into an IP Address, and the service which is used to convert the domain name to IP Address is called Domain Name Service(DNS).

The IP Address is divided into two components:

Network ID: represents the IP Address of the network and is used to identify the network

Host ID: represents the IP Address of the host and is used to identify the host within the network.

Port Number is used to identify the particular process in the Host, for well-known services port Number is already predefined and fixed.

1)http⇒ portnumber = 80

2)SMTP⇒portnumber = 25

3)FTP⇒ portnumber = 21

So to answer the above question, why it is necessary to convert the domain name into an IP Address?

Because to identify the destination network and destination host.

Notations of IPV4 Address

There are three different notations used for representing IPV4 addresses:

  1. Binary Notation(base 2): In binary notation, an IPv4 address is displayed as 32 bits. each of the four octets of the IPv4 address is represented as a binary number of 8 bits. Each octet is often referred to as Byte.

  2. Dotted Decimal Notation(base 256): To make an IPV4 address more compact and easier to read, It is usually written in decimal format with a dot separating the bytes. This format is referred to as dotted decimal notation. Since each octet is only 8 bits, therefore each octet can have a value between 0 and 255.

  3. Hexadecimal Notation(base 16): In this notation, each octet of the IPv4 address is represented as a two-digit hexadecimal number, separated by dots. Each hexadecimal digit is equivalent to 4 bits. This means a 32-bit address has 8 hexadecimal digits.

Different Types of IPV4 Address

There are two types of IPV4 Addressing

  1. Classful Addressing

  2. Classless Addressing

Classful Addressing

When the internet started, an IPV4 address originally had fixed-length prefixes designed instead of one(n=8,n=16,n=24) to accommodate both small and big networks. The entire address space was classified into 5 classes:

Class A

In class A, the first 8 bits represent the network portion of the address and the remaining 24 bits represents the host portion of the address. since the first bit, which is 0, defines the class, we can have only seven bits as the network identifier.

  • NetID = 8 bits and HostID = 24 bits

  • How to identify Class A address:

    1. The first bit is reserved as 0 in Binary notation

    2. The range of 1st octet is [1-127] in dotted decimal notation

  • The total number of connections in class A is 2^31

  • There are 2^7 - 2 = 126 networks in the class A network

    • In class A, the total network available is 2 less, because:

      1. IP Address 0.0.0.0 is reserved for broadcasting requirements

      2. IP Address 127.0.0.2 is reserved for the loopback address for software testing.

      3. The range of 1st octet is [1-127], but since two addresses are reserved it is : [1-126]

  • The total number of HostID in class A is 2^24-2

    In all Classes, the total no. of hosts that can be configured is 2 less because:

    1. This is to account for the two IP addresses that are reserved in which all bits for hostID are either 0 or 1.

    2. When all the HostID bits are 0, it represents NetworkID for the network

    3. When all the HostID bits are 1, it represents Broadcast Address

  • Class A is used by organizations requiring very large size networks like NASA, Indian Railways etc.

Class B

In class B, the first 16 bits represent the network portion of the address and the remaining 16 bits represent the host portion of the address. since the first two bits, which are (10), define the class, we can have only 14 bits as the network identifier.

  • NetID = 16bits and HostID = 16bits

  • How to identify Class B address

    1. The first two bits are reserved as (10) in binary notation

    2. Range of 1st octet [128,191] in decimal dotted notation

  • The total number of connections in class B is 2^30

  • The total number of networks available in class B is 2^14

  • The total number of hosts that can be configured in every network in class B is 2^16-2

  • Class B is used by organizations requiring medium size networks like IRCTC, banks etc.

Class C

In class C, the first 24 bits represent the network portion of the address and the remaining 8 bits represent the host portion of the address. but since three bits define the class, we can have only 21 bits as the network identifier.

  • Netid = 24bits and HostID = 8bits

  • How to identify class C address:

    1. The first three bits are reserved as (110) in binary notation

    2. The range of 1st octet is [192,233] in dotted decimal notation

  • The total number of connections in class B is 2^29

  • The total number of networks available in class B is 2^21

  • The total number of hosts that can be configured in every network in class B is 2^8-2

  • Class C is used by organizations requiring small to medium size networks.

  • For example- engineering colleges, small universities, small offices etc.

Class D

  • Class D is not divided into netid and hostid

  • How to identify Class D address:

    1. The first four bits are reserved as 1110 in binary notation

    2. The range of 1st octet is [224,239] in dotted decimal notation

  • The total number of Ip addresses available in class D is 2^28

  • Class D is reserved for multicasting, In multicasting, there is no need to extract the host address from the IP Address, this is because data is not destined for a particular host.

Class E

  • Class E is not divided into netid and hostid

  • How to identify Class D address:

    1. The first four bits are reserved as 1111 in binary notation

    2. The range of 1st octet is [240,255] in dotted decimal notation

  • The total number of Ip addresses available in class E is 2^28

  • Class E is reserved for future or experimental purposes.

Problems with Classful Addressing

The most important problem with classful addressing is the "Wastage of IP Addresses", As we have discussed above, in class A the number of hosts in each network is 2^24 which is around 16,777,216 hosts which is very huge number more than 1 crore.

Now even if we talk about big MNCs or very large organizations don't have requirements for these many hosts. And in class B there are 2^16 hosts which are around 65k hosts in every network, it is also very huge but there are organizations that can use this but class A is very huge and in class A there is a limited number of networks which is 126 network, and each network has around 2^24 hosts.

And in class C there are only 2^8 which is around 256 hosts in every network which is a very low number, which means there is a problem of flexibility here.

Now suppose any organization comes to me and says to me I need let's say 1024 number IP Addresses, now to provide this many IP Addresses what solution do I have? Either I can give class C addresses but class c is insufficient, I can give class B addresses and yes it's possible to give class B addresses but the organization needs only 1024 IP Addresses so 64k Ip addresses of class B will get wasted, and the same for class A, if I give class A addresses then a huge number of IP Address will get wasted. It means according to user demand we are not providing IP Addresses, So there is also a problem of flexibility here with the wastage of IP Addresses.

In order to solve this problem, Classless addressing was introduced which is a temporary fix, which nevertheless makes use of IPv4 addresses. In other words, the class privilege was removed from the distribution to compensate for the address depletion.

Now let us understand Classless Addressing

Classless Addressing

Classless addressing, also known as Classless Inter-Domain Routing (CIDR), is a method of IP address allocation that allows for more efficient use of IP address space by allowing networks to be divided into variable-length subnets, rather than being restricted to fixed network sizes of the older classful addressing scheme.

So in Classless Addressing, wastage of IP addresses is very less because whatever is users demand, a block of size( block means how many IP addresses the user wants), will provide the user with only those IP Addresses, As it is handled by IANA(Internet Assigned Network Authority), The block size the user demand will be provided to the user.

Now block means, Block ID and Host ID, in classful addressing we had network id and host id, here we are talking about the Block. It follows 32 Bit IPV4 Addressing.

Notation of Classless Inter-Domain Routing(CIDR)

CIDR IP Addresses look like this-

a.b.c.d / n

  • They end with a slash followed by a number called an IP network prefix.

  • IP network prefix tells the number of bits used for the identification of the network.

  • The remaining bits are used for the identification of hosts in the network.

Example-

182.0.1.2 / 28

It suggests-

  • 28 bits are used for the identification of the network.

  • The remaining 4 bits are used for the identification of hosts in the network.

Extracting Information from an Address

Given any address in the block, we would like to know three pieces of information about the block to which the address belongs. Using the prefix length n we can easily find out these three pieces of information.

  1. The number of addresses in the block is found as N = 2^32-n.

  2. The first address in the block: To find the first address in the block, we keep n leftmost bits and set the (32 − n) rightmost bits all to 0s. This is also a network ID of a particular IP address, which means the IP Address belongs to which network.

  3. Last address in the block: To find the last address, we keep the n leftmost bits and set the (32 − n) rightmost bits all to 1s.

Example:

Suppose we have given the classless address as 167.199.170.82/27.

we can find the above three pieces of information as follows:

  • The number of addresses in the network is 2^32-n = 2^32-27 = 2^5 = 32 addresses

  • The first address can be found by keeping the first 27 bits and changing the rest of the bits to 0s.

Address: 167.199.170.82/27

10100111 11000111 10101010 01010010

First address: 167.199.170.64/27

10100111 11000111 10101010 01000000

  • The last address can be found by keeping the first 27 bits and changing the rest of the bits to 1s.

Address: 167.199.170.82/27

10100111 11000111 10101010 01011111

Last address: 167.199.170.95/27

10100111 11000111 10101010 01011111

Rules for Creating CIDR block

A CIDR block is created based on the following 3 rules-

Rule-01:

All the IP Addresses in the CIDR block must be contiguous.

Rule-02:

The size of the block must be presentable as the power of 2.

The size of the block is the total number of IP Addresses contained in the block.

The size of any CIDR block will always be in forms 21, 22, 23, 24, 25, and so on.

Rule-03:

The first IP Address of the block must be divisible by the size of the block.

any binary pattern is divisible by 2n, if and only if its least significant n bits are 0.

Example:-

Consider a binary pattern-

01100100.00000001.00000010.01000000

(represented as 100.1.2.64)

  • It is divisible by 25 since its least significant 5 bits are zero.

  • It is divisible by 26 since its least significant 6 bits are zero.

  • It is not divisible by 27 since its least significant 7 bits are not zero.

Conclusion

Hope you had fun reading this blog and understood the concept of Network Layer, IPV4, and its types, But it doesnt end here, one more Part of this topic is going to come soon, Stay Tuned.