Tuesday, 23 May 2017

IP addressing

 

What is an IP address?

Consider the two houses shown below. If someone in house A wants to send a letter to someone in house B, it's very obvious that he should know the address of house B.


fig1 

Similarly, two communicating nodes in a network should know each other's address and that address is called IP address



router-ip-57f4024a3df78c690fa4561b

Before I go further into detail about IP addresses let me tell you it's only IPv4 addresses I am talking about not IPv6. 



Formally IP address is a 32-bit number, represented using dotted decimal representation and it is unique globally.

The below image shows how a 32-bit number is broken down to form a valid IP address.
  ip_decimal_notation

The IP address is divided into two parts:
  • Network ID - Helps in identifying to which network the host belongs.
  • Host ID - It specifies within the network which is the host to which the packet has to be delivered.
We had the solution to route the packet in the network by dividing it into two parts. But the problem was how many bits should be assigned to network ID and host ID. Some of the solutions were to divide the 32 bits into half such that n/w ID and host ID both get 16 bits each or to give n/w ID 8 bits and 24 bits to host ID. But all these ideas had some flaw in it. 

Assume if we had given 16 bits each to both n/w ID and host ID then we would have 2^16 networks in total and each network would be of same size i.e 2^16. This model was unaccepted as the organisation like NASA and PENTAGON needs a bigger network (when I say bigger n/w I mean they need more hosts) and similarly smaller organisation don't need 2^16 hosts. 


This is where the class-full addressing scheme came into picture.

Why did we divide IP address into n/w ID and host ID?→ We wanted to route the packet to its destination and the easiest way was to find out to which network the packet belongs, go to that network using network ID and then in the network find out to which host the packet belongs using host ID and finally deliver it.
Where did the idea come from?→ The idea of dividing the IP address into two parts came from the telephonic network. In the telephonic network, we divide the telephone number into two parts, STD code and phone number. For example: 0123(std code)-7364868(phone number). In fact, whenever we encounter any problem in the current network we always look back in time and try to find how we solved the similar problem in earlier networks.

Class-full IP addressing:

The IP address is divided into 5 classes:
  • Class A - (0 to 127)
  • Class B - (128 to 191)
  • Class C - (192 to 223)
  • Class D - (224 to 239)
  • Class E - (240 to 255)
The following diagram shows how the IP addresses are divided into classes:

IMG_20170523_100229 

IP address classification

We have 32 bits in the IP address when we choose the MSB(most significant bit) of the IP address we are actually dividing the entire set of IP addresses i.e all 2^32 addresses into two sets. 

The first set contains 0 in the MSB and the next set contains 1 in the MSB. All the IP addresses which contain zero in the MSB are called as class A IP addresses. This is the reason behind the rule that all class A IP addresses should start with zero. 

There are in total 2^31 IP addresses in class A. But as I have told you that IP addresses are divided into two parts Network ID and Host ID so these 2^31 addresses are no exceptions.

  IP.Address.Classes1

The first 8 bits are assigned to network Id and last 24 bits are assigned to host ID. Now with 8 bits to n/w ID and 24 to host ID, you might think there are 2^8 (256 n/w's) and 2^24 (16777216 hosts), but it's wrong. 

The first and the last network i.e "0.X.X.X" and "127.X.X.X" are used for What is my IP and Loopback address respectively. Now we have 254 n/w's but remember our first bit is reserved so we cannot generate any new number with the MSB, we have only 7 bits which we can modify to generate the IP's. 
So that leaves us with 128 networks among which two are reserved so in total we have 126 networks in Class A. 

Now coming to the number of IP addresses they are 16777216 (2^24) but the number of hosts is two less again. 1st IP of the network is given to network ID (first IP is used to represent the network) and the last address is given to DBA(Directed broadcast address). These types of networks are huge and are used by bigger organisations who need a large number of hosts. 

Now again consider the IP address classification figure. Till now we have only discussed half of the IP addresses. The next 2^31 set is again further divided into more classes. Remember these IP addresses have 1 in the MSB. 

Next, we consider the 2nd bit from the MSB all the IP's which starts with 10 are grouped into class B IP addresses. There are 2^30 IP's in Class B. The following diagram shows the division of class B IP addresses.

  IP.Address.Classes2

Class B IP addresses have 16 bits in network ID and 16 bits in the host ID part. That gives us 2^14 networks (because first 2 bits are reserved) and 2^16 IP addresses. In class B there is no reservation for Loop-back and what is my IP, that's the reason we can utilize all the available networks. 
However, the number of hosts are again 2 less than the number of IP addresses and this is the case with Class C IP addresses as well. So we have (2^16) - 2 hosts in Class B. 

The next set of 2^30 IP addresses are again further divided into class C, D and E. The set of IP addresses which starts with 110 are called as Class C IP addresses. There are 2^21 networks and 2^8 IP addresses in class C IP addresses. And the number of hosts are 2 less than the number of IP addresses i.e 254.

  IP.Address.Classes

The rest of the IP addresses are divided into class D and E. The IP addresses which start with 1110 falls into class D set of IP's and the one starting with 1111 falls into Class E IP addresses. The class D and E IP addresses are not divided into Network ID and Host ID. Class D is used for multicasting purposes and Class E is used for Research and military purposes. 

Now given any random IP address it must be really difficult to tell to which class the IP address belongs. To answer that question look at the following figure.
  32 

The above figure gives the ranges of the IP address belonging to different classes. To make it more clear let's take an example.

Consider the following IP address "11000000.00000010.00000000.00000001" to find out to which class this address belongs just decode the first octet into decimal. 11000000 is equivalent to 192 in decimal and we already know 192 to 223 is class C so this IP address belongs to Class C IP addresses.

The following diagram summarizes the classfull IP addressing:
  20170523064042
The above diagram shows that 50% of the IP addresses are given to class A, 25% of the IP's are with class B, class C has 12.5% and class D and E have 6.25% each IP addresses.

Hope this was helpful. Leave your questions, answers & suggestions in the comment section below. And make sure to like us on Facebook, follow on Google+ and follow the blog.

Thank you!