How to identify an IP class from a given IP address?

In today’s blog, we will discuss IP with respect to IPv4 addressing. What is IPv4? It is the fourth version of the internet protocol. Internet Protocol (IP) is the main set of rules and standards for communication. Internet Protocol (IP) is part of an internet protocol suite, which also includes the transmission control protocol (TCP). These two are combined and termed TCP/IP. The internet protocol suite governs rules for packetizing, addressing, transmitting, routing, and receiving data over networks.

IP address

Let’s dig deep into the various types of IPv4 classes and their identification.

An IP address has two parts – Host ID and Network ID. The Host ID identifies the computer/device while the Network ID identifies the network it belongs to. IPv4 works at layer – 3 i.e Network layer in the OSI model. The IPv4 address is a 32-bit address split into 4 octets (1 octet = 8 bits). These octets help us with an addressing method to accommodate small to large-sized networks. Accordingly, these are divided into 5 IP address ranges namely,

  1. Class A
  2. Class B
  3. Class C
  4. Class D
  5. Class E

IPv4 is 32 bits long, and we can form 232 maximum addresses with IPv4 addresses. The maximum number of addresses is 4,29,49,67,296 i.e 232 addresses. Every IPv4 address has four octets each of which can contain one to three digits ranging from 0 to 255 separated by a single dot(.). Here, each octet is the decimal representation (base-10) for an 8-digit binary number (base-2) as follows.

Let’s explore the IPv4 classes. The bits in the first octet of an IP address decide the class of an IP address. The network ID identifies which network you are on and the number of networks in any class is given by the following formula:

Number of Networks = 2^(networkbits)

The host ID identifies your device on the network and the number of hosts in any class is given by the following formula.

Number of Hosts = 2^(hostbits-2)

In this equation, 2 IP addresses are subtracted for the following reasons

  1. The host ID in which all the bits are set to 0 is not assigned to any device as it represents the network ID.
  2. The host ID in which all the bits are set to 1 is reserved for Direct Broadcast Address (for sending the data from one network to all the other hosts in another network)

Class A

The Class A IP addresses use the first octet for the network ID and the last three octets for the host ID.

Important points to remember for Class A

The network ID has 8 bits.

The host ID has 24 bits.

The first bit of the first octet is always set to ‘0’.

The default subnet mask for Class A IP address is 255.0.0.0. Subnet masks are used to inform hosts on the network which part is the network address and which part is the host address of an IP address.

Now, how does the subnet mask work this out? Let’s see.

Suppose you have an IP address as

10.20.10.7 = 00001010.00010100.00001010.00000111

and the mask as,

255.0.0.0 = 11111111.00000000.00000000.00000000

The IP address bits that have corresponding mask bits as 1 represent the network ID and the IP address bits that have corresponding mask bits as set to 0 represent the host ID.

By comparing the corresponding bits of address bits and mask bits we get the following,

Network ID = 00001010 = 10

Host ID = 00010100.00001010.00000111 = 20.10.7

Thus the number of networks and hosts in Class A can be calculated as below.

Network ID =2⁷-2 = 126 

(Here, as the first bit of the first octet is always set to ‘0’, we take the remaining 7 bits for calculation. Also, the 2 addresses are subtracted because 0.0.0.0 and 127.x.x.x are special addresses.

Host ID = 2²⁴-2 = 16,777,214

The IP addresses belonging to Class A range from 1.n.n.n to 126.n.n.n.(where n ranges from 0 to 255)

In short, it means anyone using a Class A IP address can have a maximum of 126 networks and 16,777,214 hosts/devices connected.

Class B

The Class B IP addresses use the first two octets for the network ID and the last two octets for the host ID.

Important points to remember for Class B

The network ID has 16 bits.

The host ID has 16 bits.

The first two bits of the first octet are always set to ‘10’.

The subnet mask for class B is 255.255.0.0.

So, class B can accommodate the following maximum number of networks and hosts

Network IDs = 2¹⁴ = 16384 network ID

Host IDs = (2¹⁶ – 2) = 65534 host address

The IP addresses belonging to Class B range from 128.0.n.n to 191.255.n.n.(where n ranges from 0 to 255)

Class C

The Class C IP addresses use the first three octets for the network ID and the last octet for the host ID.

Important points to remember for Class C

The network ID has 24 bits.

The host ID has 8 bits.

The first three bits of the first octet are always set to ‘110’.

The subnet mask for class C is 255.255.255.0.

So, class C can accommodate the following maximum number of networks and hosts

Network IDs = 2²¹= 20,97,152.

Host IDs = (2⁸ – 2)= 254

The IP address belonging to Class C ranges from 192.0.0.n to 223.255.255.n.(where n ranges from 0 to 255)

Class D

The Class D IP addresses use the first four bits of the first octet for the network ID and the remaining bits for the host ID.

The IP address belonging to Class D ranges from 224.0.0.0 to 239.255.255.255.

Class D is reserved for multicasting and this class doesn’t have any subnet mask.

Class E

The IP addresses of Class E have the first four bits of the first octet set to 1111. The remaining bits are all host bits.

The IP addresses belonging to Class E range from 240.0.0.0 to 255.255.255.254.

This class is reserved for future use, research, and development purposes and does not have any subnet mask.

So, with this understanding, you are all set to identify the class of any given IP address. Just convert the decimal IP address to its binary equivalent. You can also learn the IP ranges of each IP class.

That’s all for this article. Hope it was useful and helped you with network calculations.

Stay tuned for more such learning blogs!

Check this post to learn about AWS Cloud – Internships, jobs, salary, job roles, top companies, and more. and Step-by-step guide to Multi-part upload in AWS S3 using AWS CLI, AWS certifications

Leave a Comment

Your email address will not be published. Required fields are marked *