When data packets are sent from a computer to the internet, it traverses from one network to another network or through multiple networks to reach the destination.
A network on the internet consists of so many hosts. One network can be different from another network in geographical size, transmission speed, transmission medium, number of hosts, throughput, reliability, and so on.
The one network connects with another network on the internet with the help of a gateway. The gateway serves the purpose of the exchange of data from one network to another network.
The source host can communicate with the destination host from one network to another network or multiple intermediate networks.
How is IP address defined?
You may have checked your IP address on your computer. If you have not checked your IP address, you can use this simple guide to check your IP address on the computer, phone, and router.
When you are connected to the internet, you need to understand what are public IP addresses.
The public IP address makes your computer unique on the internet. So, the public IP address differs in different networks.
For instance, if you are in your home network, then your public IP address would be different compare to the IP address when you are in a work office or coffee shop or hotel.
So, it is clear that in the public networks, your IP address will vary.
All these IP addresses have one thing common – they are divided into four sections and separated by dots.
The most common structure of IP address is IPv4, which we are going to discuss in this article.
Moreover, the IP address structure is categorized into two heads: IPv4 (Most used) and IPv6 (Advance version)
Basic Structure of IP address
What you see on your computer, it is in the format and language that you understand, such as words, numbers, and pictures.
The computer turns everything into a binary digit, which is 0 (zero) and 1 (one). It is also called a digital form or digital signal.
So, if the computer sees the number 255, then it will convert into a binary digit such as 11111111. Here, every binary digit is known as a bit, and when we combined 8-bits, then we call it as one byte.
To understand this, you can follow our comprehensive guide on bits and byte.
So, each IP address (IPv4) is made up of 32-bits. As we have discussed earlier that the IP address is divided into 4 sections, which means each section of the IP address consists of 8-bits, known as octets.
For instance, take the case of IP address 240.145.249.76. It is divided into four parts: part1.part2.part3.part4.
So, when we convert each part that is 8-bit segment or octet in a binary digit that it will look as below.
- 240 = 11110000 (octet)
- 145 = 10010001 (octet)
- 249 = 11111001 (octet)
- 76 = 01001100 (octet)
How IP address is divided?
On the internet, there could be multiple networks, and a network can have so many hosts.
A global two-dimensional 32-bit IP address is divided into two sections to uniquely define each host on the internet: Your network and your computer or host.
In other words, the first element of the address is network ID, in short, net ID, and another element is host ID, in short, host ID.
IP Address = (Net ID, Host ID)
Remember, the network ID and host ID are not usually divided equally. The network ID can be segregated in many ways: only the first part or first two parts or the first three parts, and the remaining part is for the host ID.
So, we will discuss how the network ID and host IP are divided into IP address classes.
Before that, we need to understand the Subnet Mask.
What is Subnet Mask?
As we have discussed above, an IP address consists of a network ID and a host ID. In other words, an IP address can be divided into two parts: the network portion and the host portion.
A Subnet Mask helps us to identify the network portion and host portion in an IP address.
In other words, Subnet Mask separates the network ID and host ID in an IP address.
The Subnet Mask also follows the same notations of the IP address and occupies 32-bit in length.
The example of Subnet Mask are:
- IP address: 184.108.40.206
- Subnet mask: 255.0.0.0
- IP address: 220.127.116.11
- Subnet mask: 255.255.0.0
How does Subnet Mask work?
If the octets of the IP address belongs to the network portion, then that octets of the Subnet mask are turned ON, and the remaining belong to the host portion, which is turned OFF.
If we look in binary notation, then 1 (one) represents a turned ON bit and 0 (zero) represents turned OFF bit. Likewise, in dotted-decimal notation, 1 to 255 represent turned ON bits, and 0 (zero) represent turned OFF bits.
In example 1, the first portion of Subnet Mask (255.0.0.0) is turned ON, and the remaining is turned OFF. So, in an IP address (18.104.22.168), the first part represents the network ID (255), and the remaining part represents the host ID (198.0.1).
In example 2, the first two portions of the Subnet Mask (255.255.0.0) is turned ON. So, in an IP address (22.214.171.124), the first two parts (172.198) represent the network ID, and the remaining parts (1.10) represent the host ID.
IP address classes
We understand how the network portion and host portion in an IP address is identified using Subnet Mask.
But, there is a total of 4.3 billion IP addresses. So, how the IP address is categorized so that we can quickly identify the type of networks and the number of hosts in a network.
All the IP addresses in the world are classified under IP address classes.
To make things easier and sequential, IP address classes classify IP addresses in Class A, B, C, D, and E.
To understand better, we need to understand some terms needed to define IP address classes.
- Network Address
- Loopback Address
- Broadcast Address
The network address in the IP address (IPv4) blocks is the first address used to identify the network.
In other words, the host part of the IP address always contains 0 (zero) bits in the Network address.
Let us take an example of IP address 126.96.36.199 with default Subnet Mask of 255.0.0.0, whose first octet is the network part, and the remaining three octets are the host part.
Here, the host part is 0 (zero), which means, the network address in the blocks of IP addresses from 188.8.131.52 to 184.108.40.206.
The loopback IP address is used by the operating system to create a virtual network interface, where the computer communicates with itself.
This process is used to troubleshoot and diagnostics the connection with the servers running on the local machine.
In other words, it will let the system send the message to itself to verify whether TCP/IP stack is installed correctly or not.
The IP address with first octet 127 (127.x.x.x) in decimal is the Loopback Address. The Loopback Address is also known as localhost.
The default loopback IP address is 127.0.0.1 (in IPv4). However, the range can be extended to 127.255.255.255.
And, the default loopback IPv6 address is 0000:0000:0000:0000:0000:0000:0000:0001/128 and in a more simplified way, it can be written as::1/128.
Another benefit of the loopback address is that it never changes, and the best way to identify a device in the network.
The Broadcast address work is used to communicate with all the devices in the local network. It is also used by the host to request an IP address from DHCP (Dynamic Host Configuration Protocol).
The Broadcast address is the last IP address in the blocks of IP addresses in a network. It is identified as one when all the host part of the IP address is set to 1-bit.
Suppose, the Subnet Mask is 255.255.255.0 and the IP address is 192.168.20.1.
It means that the last part of the address is available for the host, equal to 8-bits. The available IP address range in a network is from 192.168.20.0 to 192.168.20.255.
The last IP address here is 192.168.20.255, where all the bits are set to 1 (one) in the host part. This is the Broadcast address. Whereas, the first address is a network address (discussed earlier)
So, here the Host addresses are always in between the Network address and Broadcast address, which is between 192.168.20.0 and 192.168.20.255.
Let’s look into different classes of IP addresses.
Class A IP address
If the first part of the IP address is reserved for the network part and the remaining is for the host, it is a Class A IP address.
Class A networks are vast, in which 17 million hosts or computers are connected.
The Class A default Subnet Mask is 255.0.0.0.
The first octet of Class A IP address varies from 0 to 127. For examples: 220.127.116.11, 10.34.256.10, 18.104.22.168.
So, theoretically, the Class A IP address range from 0.0.0.0/8 to 127.255.255.255/8 (CIDR notation). It means that the first octet has a number between 0 and 127, and the /8 means that the first octet is used to divide the networks.
The last IP address range that is from 127.0.0.0 to 127.255.255.255 is reserved for the Loopback address.
The default Loopback address is 127.0.0.1.
The first (0.0.0.0/8) and last (22.214.171.124/8) IP address is always reserved for the Network address and Broadcast address.
The IP address 0.0.0.0 also the first IP address, and it represents all networks.
So, the available host address is in between 0.0.0.0 and 126.96.36.199.
Class B IP address
If the first two part of the IP address is reserved for the network part and the remaining for the host, it is called Class B IP address.
The first octet of Class B IP address varies from 128 to 191. For example: 188.8.131.52, 184.108.40.206, 220.127.116.11.
The Class B IP addresses networks are small than Class A IP addresses, which comprises a maximum of 65000 hosts.
The Class B default Subnet Mask is 255.255.0.0.
Class C IP address
If the first three-part of the IP address is reserved for network part and the remaining one part is for hosts, it is called Class C IP address.
The first octet of the Class C IP addresses ranges from 192 to 223. For example: 192.168.0.1, 18.104.22.168, 22.214.171.124.
The Class C network is the smallest one, which comprises of only 254 hosts or computers.
The Class C default Subnet Mask IP address is 255.255.255.0.
Class D IP address
The Class D IP address is reserved for multicast addresses. A multicast IP address is used for multiple recipients.
The first octet of the Class D IP addresses has an IP range from 224 to 239, from 126.96.36.199 to 188.8.131.52.
Class E IP address
The Class E IP addresses are reserved for future use only. These addresses are used for experimental purposes, such as in R&D or a research study.
The first octet of the Class E IP address has an IP range from 240 to 255, from 240.0.0.0 to 255.255.255.254.
The last IP address, 255.255.255.255 of IPv4, represents all hosts.
Subnetting is the process of dividing the more extensive network into a small network. It allows you to create multiple subnetworks within an existing single class A, B, or C network.
As we know, an IP address can be divided into two parts: the network portion and the host portion. Subnetting further divides a single network into multiple subnetworks by stealing some bits of the host part.
What are the benefits of subnetting?
There are a few reasons where subnetting helps.
- It will conserve unused IP addresses when we break down the extensive network into the smaller network.
- In an organization, Subnetting helps to improve network security by using firewalls or more, and it also requires smaller broadcast domains.
- A smaller network will have less traffic and alleviate network congestion because it allows a better flow of data packets to the target destination.
- Breaking the larger network into the smaller network will help in troubleshooting.
Understanding Subnetting with example
Let suppose we have a Class C network with available 256 addresses for the host. We know that the first and the last address is used for the network address and broadcast address.
So, the remaining addresses for the host are 254. Let divide these addresses into eight equal subnetworks. Now, each network will have 32 addresses, and when we remove reserved address for network and broadcast, then the remaining host addresses is 30 in a single subnetwork.
There is no doubt that after dividing the larger network into the smaller network, the available addresses for hosts is reduced to 240 instead of 254.
But, now you can manage the network in a better and more efficient way.
How to calculate subnets or hosts based on the Subnet Mask?
We know that when all 8 bits in one part of the IP address is set to 1, then we will get 255 decimal value.
Let illustrate the Subnet Mask 255.255.255.0 in binary digits
11111111 11111111 11111111 00000000
Now, let’s calculate binary to the decimal of the first part of the Subnet Mask.
11111111 (Binary) = 2^8 + 2^7 + 2^6 + 2^5 + 2^4 + 2^3 + 2^2 + 2^1 (Binary to decimal conversion from left to right) = 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255 (decimal value)
So, when we include zero, then the total possible value is 256 because the value range from 0 to 255.
As we have discussed earlier that we calculate network ID when we set the bit to 1 (one) and the available host ID when we set the value to 0 (Zero).
From the above example of Subnet Mask 255.255.255.0, the first three part of the address is set to 1 (one), which means 24-bits (8*3) is reserved for the network portion.
And the last part of the Subnet Mask is set to 0 (zero), which equal to 8-bits. It means 8-bits are available for the host addresses.
Similarly, let take another example of Subnet Mask like 255.255.255.192. Here, the last part represent 192 (128 + 64 + 0 + 0 + 0 + 0 + 0 + 0) decimal values, where 6-bits is available for host portion.
The remaining 26-bits ( 8 + 8 + 8 + 2) are available for network portion.
How to calculate host from Subnet Mask?
The quicker way to calculate the number of the host in a network is by using the formula 2^n-2, where n is the number of available bits for the host ID.
Also, you have to subtract the result with two because from the blocks of IP address in a network, the first address (when all the bits are set to zero) is reserved for the network address, and the last address (when all the bits are set to one) is reserved for broadcast address.
Let’s take the above example to calculate the number of hosts in a network.
Example 1: Subnet Mask 255.255.255.0
The number bits available for hosts is eight, and the number of hosts in a network is 2^8 – 2 = 254.
In another way, we can also calculate hosts when we know the number of allocated bits for network ID. Here, in this example, the number of bits for network ID is 24.
Now, the formula for the number of hosts is 2^32-24 – 2 = 254, where 32 is the total bits of the IPv4 address.
Example 2: Subnet Mask like 255.255.255.192
The above subnet Mask, when converted to binary will be 11111111 11111111 11111111 11000000.
Here, the 2 bits of host ID is used for subnetting.
The total number of bits for network ID is 26, and the remaining bits for host ID is 6.
The number of bits available for hosts is six, and the number of hosts in a network is 2^6 – 2 = 62.
Categorizing the IP addresses into Classes helps divide the network portion and host portion in an IP address. It also indicates the network size and the number of available hosts in a network.
IP address classes determine the use of IP address in a network. The Subnet Mask identifies the number of network past and hosts part.
The Subnet Mask also helps to further divide a network into multiple subnetworks, which is called as Subnetting.
Subnetting makes you manage smaller networks with more efficiency.
The concept of IP address Classes, the Subnet Mask, and Subnetting helps you manage a network in a better way.