IP Address

When you are using your browser on your laptop and you want to browse www.google.com (assuming you are connected to Internet), the picture looks like:

  • You are within the network of your Internet Provider.
  • Your laptop is one of the node in the network. There are many other computers in this network, and each computer is a node in this network.
  • Your browser is one of the process running in a host (i.e. your laptop).

In order to get response from Google:

  • You should be able to connect Google's network from your network.
  • You should be able to connect to a host in Google's network.
  • You should be able to connect to a specific process (which keeps listening to a port, typically 80) on that specific host.

The above 3 things should happen only upon typing www.google.com in your browser.

When you type www.google.com in your browser, your machine talks to a service which converts "www.google.com" into some numbers, called as IP address, to identify the Google's network and host within that network. The process is identified by port number.

IP address is made up of 2 parts:

  1. Network ID
  2. Host ID

Network ID identifies the network, and Host ID identifies the host within that network. And port number helps to reach the process within that host. Most of the port numbers are predefined for standard protocols. If the protocol is not standard, then the port number is explicitly mentioned.

DNS - Domain Name Service

DNS is the service which converts the domain name (google.com) to its IP address. Whether you're accessing a Web site or sending e-mail, your computer uses a DNS server to look up the domain name you're trying to access. It is a massive database which maps domain names to their respective IPs.

How does your computer know what DNS server to use?

Typically, when you connect to your home network, your Internet service provider (ISP) sends some important network configuration information to your computer or mobile device. That configuration includes one or more DNS servers that the device should use when translating DNS names to IP address. Your ISP is responsible for configuring a DNS server for you to use.

DNS Overhead: Before contacting google.com, we had to contact DNS server to get its IP address. Once we have the IP address, we can reach the target website. This entire process is actually an overhead as our target was to reach google.com, but we had to make a trip to DNS server before going to google.com. This is called as DNS overhead.

You can always bypass a DNS lookup by entering IP address directly in your browser. However, you're probably more likely to remember "google.com" rather than its IP address. In addition, a Web site's IP address can change over time, and some sites even associate multiple IP addresses with a single domain name.

In order to avoid DNS overhead, we make a trip to DNS server first time, and then the machine caches the IP address. It has TTL associated with it. If TTL expires, then the machine will contact the DNS again.

Dynamic and Static IP Addresses

Where does your computer's IP address come from? If we're talking about your desktop or laptop computer, it probably comes from a Dynamic Host Configuration Protocol (DHCP) server on your network. The job of a DHCP server is to make sure your computer has the IP address and other network configuration it needs whenever you're online. Because this is "dynamic," the IP address for your computer will probably change from time to time, such as when you shut down your computer for a few days. As the user, you'll probably never notice all this taking place.

Web servers and other computers that need a consistent point of contact use static IP addresses. This means that the same IP address is always assigned to that system's network interface when it's online. To make sure that interface always gets the same IP address, ISP associates the address with the Media Access Control (MAC) address for that network interface. Every network interface, both wired and wireless, has a unique MAC address embedded in it by the manufacturer.

Powers of 2 Table

Number of Bits Possible Values Comments Number of Bits Possible Values Comments
0 2^0 = 1 Either 0 or 1 21 2^21
1 2^1 = 2 22 2^22
2 2^2 = 4 1 Nibble 23 2^23
3 2^3 = 8 1 Byte 24 2^24
4 2^4 = 16 25 2^25
5 2^5 = 32 26 2^26
6 2^6 = 64 27 2^27
7 2^7 = 128 28 2^28
8 2^8 = 256 29 2^29
9 2^9 = 512 30 2^30 1 Gigabyte
10 2^10 = 1024 1 Kilobyte 31 2^31
11 2^11 = 2048 32 2^32
12 2^12 = 4096 33 2^33
13 2^13 34 2^34
14 2^14 35 2^35
15 2^15 36 2^36
16 2^16 37 2^37
17 2^17 38 2^38
18 2^18 39 2^39
19 2^19 40 2^40 1 Terabyte
20 2^20 1 Megabyte 41 2^41

Looking at the above table, if there are n bits in a number space, total numbers present in that space is 2^n.

If there are 2 bits, then total possible numbers = 2^2 = 4 (00, 01, 10, 11)

If there are 3 bits, then total possible numbers = 2^3 = 8 (000, 001, 010, 011, 100, 101, 110, 111)

Note: 1 Byte = 8 Bits

So, 1 Kilobyte = 1000 Bytes = 1000 * 8 Bits = 8000 Bits

Number of Bits and Address Space Division

Column 1 Column 2 Column 3 Column 4 Column 5 Column 6
0 0 0 0 0 0
1 0 1 0 0 1
1 0 0 1 0
1 1 0 1 1
1 0 0
1 0 1
1 1 0
1 1 1

Column 1 shows address space when number of bits = 1 i.e. 2 possible values in address space.

If we choose 1 bit, we can divide the entire number space in 2^1 parts. 0 and 1, in this case.

Column 2 and 3 show address space when number of bits = 2 i.e. 4 possible values in address space.

If we choose 1 bit (left most bit), we can divide the entire number space in 2^1 = 2 parts.

1st Part = 00, 01 2nd Part = 10, 11

If we choose 2 bits, we can divide the entire number space in 2^2 = 4 parts.

1st Part = 00 2nd Part = 01 3rd Part = 10 4th Part = 11

Column 4, 5 and 6 show address space when n = 3, i.e. 8 possible values in address space

If we choose 1 bit (left most bit), we can divide the entire number space in 2^1 = 2 parts.

1st Part = 000, 001, 010, 011 2nd Part = 100, 101, 110, 111

If we choose 2 bits, we can divide the entire number space in 2^2 = 4 parts.

1st Part = 001, 001 2nd Part = 010, 011 3rd Part = 100, 101 4th Part = 110, 111

In a nutshell,

If there are n bits, then there are 2^n possible numbers in number space.

If we choose first k bits, then we divide the entire number space in 2^k parts.

Now, 2^k parts contain 2^n numbers.

So, total numbers in 1 part = (2^n) / (2^k) = 2^(n-k)

E.g. 3 bits contain 2^3 = 8 numbers in address space.

If we choose first bit, then total numbers present in 1 part is: 2^(3-1) = 2^2 = 4 (000, 001, 010, 011) & (100, 101, 110, 111)

If we choose first 2 bits, then total numbers present in 1 part is: 2^(3-2) = 2^1 = 2 i.e. (000, 001), (010, 011), (100, 101) and (110, 111)

Coming to computer networks:

n bits = IP Address

k bits = Network ID Part

n-k bits = Host ID Part

So, If I choose k bits, I will get 2^k networks, and each network will contain 2^(n-k) hosts. This is also called as size of 1 network.

In computer networks, IP address is 32 bits. So, total possible IP addresses are 2^32 = 4,294,967,296 ~ 4.2 billion

In earlier days, they divided these 32 bits into static parts - 8 bits of network ID and 24 bits of host IDs.

8 Bits (Network ID) 24 Bits (Host ID)

Total Possible Networks: 2^8 = 256

Total hosts in 1 network: 2^24 = 16,777,216 ~ 16 Million Hosts in 1 network.

However, this setup had some problems:

  1. 256 Networks is a very small number of networks to have in today's world. This number was good in 80s and 90s, when there were only 100s of network, but not anymore.
  2. If anybody buys 1 network, it would come with 16 million hosts, which are way greater than required in a single network typically. No network other than NASA and Pentagon has requirements of this many IPs in a single network.

In a nutshell, this design was not scalable. So, the world moved to "classfull" manner for IP addressing.

Classfull IP Addressing

Classfull IP addresses are summarized in below table:

Class A Networks

Size of class A network is 2^31. So, total addresses in this class = 2^31 = 2,147,483,648 i.e. Approximately 2 billions

Class A network contains 8 bits for Network ID and 24 bits for Host ID.

Out of the first 8 bits for Network ID, 1st bit is fixed and it is always 0. So, there are 7 bits remaining for network configuration.

Number of networks that can be configured in Class A = 2^7 = 128. However, only 126 networks can be used practically.

Number of hosts that can be configured in 1 network of Class A = 2^24 = 16,777,216 i.e. Approximately more than 16 millions.

Since the first and last IP address is reserved for network address and broadcast address respectively, number of hosts that can be configured in 1 network of class A = (2^24) - 2.

Network ID (0 x x x x x x x) Host ID Host ID Host ID

First Network ID = 0 0 0 0 0 0 0 0 = 0

Last for Network ID = 0 1 1 1 1 1 1 1 = 127

First Host ID in each network = 0 0 0 0 0 0 0 0 . 0 0 0 0 0 0 0 0 . 0 0 0 0 0 0 0 0 = 0.0.0

Last Host ID in each network = 1 1 1 1 1 1 1 1 . 1 1 1 1 1 1 1 1 . 1 1 1 1 1 1 1 1 = 255.255.255

Class B Networks

Size of class B network is 2^30. So, total addresses in this class = 2^30 = 1,073,741,824 i.e. Approximately 1 billion

Class B network contains 16 bits for Network ID and 16 bits for Host ID.

Out of the first 16 bits for Network ID, first 2 bits are fixed and it is always 1 0. So, there are 14 bits remaining for network configuration.

Number of networks that can be configured in Class B = 2^14 = 16, 384 = 16k.

Number of hosts that can be configured in 1 network of Class B = 2^16 = 65, 536 i.e. Approximately more than 65k.

Since the first and last IP address is reserved for network address and broadcast address respectively, number of hosts that can be configured in 1 network of class B = (2^16) - 2.

Network ID (1 0 x x x x x x) Network ID (x x x x x x x x) Host ID Host ID

First Network ID = 1 0 0 0 0 0 0 0 . 0 0 0 0 0 0 0 0 = 128.0

Last for Network ID = 1 0 1 1 1 1 1 1 . 1 1 1 1 1 1 1 1 = 191.255

First Host ID in each network = 0 0 0 0 0 0 0 0 . 0 0 0 0 0 0 0 0 = 0.0

Last Host ID in each network = 1 1 1 1 1 1 1 1 . 1 1 1 1 1 1 1 1 = 255.255

Class C Networks

Size of class C network is 2^29. So, total addresses in this class = 2^29 = 536,870,912 i.e. Approximately half a billion

Class C network contains 24 bits for Network ID and 8 bits for Host ID.

Out of the first 24 bits for Network ID, first 2 bits are fixed and it is always 1 1 0. So, there are 21 bits remaining for network configuration.

Number of networks that can be configured in Class C = 2^21 = 2,097,152 = 2 lacs.

Number of hosts that can be configured in 1 network of Class C = 2^8 = 256

Since the first and last IP address is reserved for network address and broadcast address respectively, number of hosts that can be configured in 1 network of class C = (2^8) - 2 = 254

Network ID (1 1 0 x x x x x) Network ID (x x x x x x x x) Network ID (x x x x x x x x) Host ID

First Network ID = 1 1 0 0 0 0 0 0 . 0 0 0 0 0 0 0 0 . 0 0 0 0 0 0 0 = 192.0.0

Last for Network ID = 1 1 0 1 1 1 1 1 . 1 1 1 1 1 1 1 1 . 1 1 1 1 1 1 1 1 = 223.255.255

First Host ID in each network = 0 0 0 0 0 0 0 0 = 0

Last Host ID in each network = 1 1 1 1 1 1 1 1 = 255

Class D Networks

Size of class D network is 2^28. So, total addresses in this class = 2^28 = 268,435,456

Host ID and network ID classification is not defined for class D networks.

First IP address in Class D network = 1 1 1 0 0 0 0 0 . 0 0 0 0 0 0 0 0 . 0 0 0 0 0 0 0 0 . 0 0 0 0 0 0 0 0 = 224.0.0.0

Last IP address in Class D network = 1 1 1 0 1 1 1 1 . 1 1 1 1 1 1 1 1 . 1 1 1 1 1 1 1 1 . 1 1 1 1 1 1 1 1 = 239.255.255.255

Class E Networks

Size of class E network is 2^28. So, total addresses in this class = 2^28 = 268,435,456

Host ID and network ID classification is not defined for class E networks.

First IP address in Class D network = 1 1 1 1 0 0 0 0 . 0 0 0 0 0 0 0 0 . 0 0 0 0 0 0 0 0 . 0 0 0 0 0 0 0 0 = 240.0.0.0

Last IP address in Class D network = 1 1 1 1 1 1 1 1 . 1 1 1 1 1 1 1 1 . 1 1 1 1 1 1 1 1 . 1 1 1 1 1 1 1 1 = 255.255.255.255

Summary

Bit-wise representation

In the following table:

  • n - indicates a bit used for the network ID.
  • H - indicates a bit used for the host ID.
  • X - indicates a bit without a specified purpose.
Class A
  0.  0.  0.  0 = 00000000.00000000.00000000.00000000
127.255.255.255 = 01111111.11111111.11111111.11111111
                  0nnnnnnn.HHHHHHHH.HHHHHHHH.HHHHHHHH

Class B
128.  0.  0.  0 = 10000000.00000000.00000000.00000000
191.255.255.255 = 10111111.11111111.11111111.11111111
                  10nnnnnn.nnnnnnnn.HHHHHHHH.HHHHHHHH

Class C
192.  0.  0.  0 = 11000000.00000000.00000000.00000000
223.255.255.255 = 11011111.11111111.11111111.11111111
                  110nnnnn.nnnnnnnn.nnnnnnnn.HHHHHHHH

Class D
224.  0.  0.  0 = 11100000.00000000.00000000.00000000
239.255.255.255 = 11101111.11111111.11111111.11111111
                  1110XXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX

Class E
240.  0.  0.  0 = 11110000.00000000.00000000.00000000
255.255.255.255 = 11111111.11111111.11111111.11111111
                  1111XXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX

results matching ""

    No results matching ""