logoCndocs

Classless Addressing in IP Addressing

The Network address identifies a network on the internet. Using this, we can find a range of addresses in the network and total possible number of hosts in the network.

A mask is a 32-bit binary number that gives the network address in the address block when an AND operation is bitwise applied on the mask and any IP address of the block.

The default masks in different classes are:

  • Class A – 255.0.0.0
  • Class B – 255.255.0.0
  • Class C – 255.255.255.0

Example: Given IP address 132.6.17.85 and default class B mask, find the beginning address (network address).

Solution: The default mask is 255.255.0.0, which means that only the first 2 bytes are preserved and the other 2 bytes are set to 0. Therefore, the network address is 132.6.0.0.

Subnetting

Dividing a large block of addresses into several contiguous sub-blocks and assigning these sub-blocks to different smaller networks is called subnetting. It is a practice that is widely used when classless addressing is done.

A subnet or subnetwork is a network inside a network. Subnets make networks more efficient. Through subnetting, network traffic can travel a shorter distance without passing through unnecessary routers to reach its destination.

Classless Addressing

To reduce the wastage of IP addresses in a block, we use sub-netting. What we do is that we use host ID bits as network ID bits of a classful IP address. We give the IP address and define the number of bits for mask along with it (usually followed by a '/' symbol), like, 192.168.1.1/28.

Here, the subnet mask is found by putting the given number of bits out of 32 as 1, like, in the given address, we need to put 28 out of 32 bits as 1 and the rest as 0, and so, the subnet mask would be 255.255.255.240.

A classless addressing system or classless interdomain routing (CIDR or supernetting) is the way to combine two or more class C networks to create a /23 or a /22 supernet. A classless addressing system or classless interdomain routing (CIDR) is an improved IP addressing system. In a classless addressing system, the block of IP address is assigned dynamically based on specific rules.

Some Values Calculated in Subnetting:

  1. Number of subnets: 2^(Given bits for mask – No. of bits in default mask)
  2. Subnet address: AND result of subnet mask and the given IP address
  3. Broadcast address: By putting the host bits as 1 and retaining the network bits as in the IP address
  4. Number of hosts per subnet: 2^(32 – Given bits for mask) – 2
  5. First Host ID: Subnet address + 1 (adding one to the binary representation of the subnet address)
  6. Last Host ID: Subnet address + Number of Hosts

Example of Classless Addressing

Let's look at a simple example of how to convert an IP address from classful to classless notation:

def ip_classless(ipaddress):
    '''
    Will return the Classless IP Address
    '''
    # Gets the First Octet through String Slicing 
    firstOctet = int(ipaddress[:ipaddress.index('.')])
    
    if(0 <= firstOctet <= 127):
      # Means this is Class A IP Address
        return ipaddress + '/8'
    elif(128 <= firstOctet <= 191):
      # Means this is a Class B IP Address
        return ipaddress + '/16'
    elif(192 <= firstOctet <= 223):
      # Means this is a Class C IP Address
        return ipaddress + '/24'
    else:
        return "This is a reserved IP Address, INVALID!!"
 
# Example usage
ip = "192.168.0.0"
print(ip_classless(ip))  # Output: 192.168.0.0/24

This program takes an IP address in classful notation as input (e.g., 192.168.0.0) and converts it to classless addressing (CIDR notation) by checking the Class of the IP address and setting the mask (number after '/') on that basis.

Practical Example

Question: Given IP Address – 172.16.0.0/25, find the number of subnets and the number of hosts per subnet. Also, for the first subnet block, find the subnet address, first host ID, last host ID, and broadcast address.

Solution:

  • This is a class B address. So, number of subnets = 2^(25-16) = 2^9 = 512.
  • Number of hosts per subnet = 2^(32-25) – 2 = 2^7 – 2 = 128 – 2 = 126
  • For the first subnet block (Subnet Number=1), we have:
    • Subnet address = 172.16.0.0
    • First host ID = 172.16.0.1
    • Last host ID = 172.16.0.126
    • Broadcast address = 172.16.0.127

Advantages of Classless Addressing

  1. Efficient Use of IP Space: Classless addressing allows for more efficient use of the available IP address space by allocating only the necessary number of addresses to each network.

  2. Flexible Subnetting: It provides flexibility in subnetting, allowing network administrators to create subnets of various sizes based on their specific needs.

  3. Reduced Routing Table Size: CIDR helps in reducing the size of routing tables by allowing route aggregation, which combines multiple routes into a single entry.

  4. Better Address Allocation: It enables more precise allocation of IP addresses, reducing wastage that was common in classful addressing.

  5. Support for VLSM: Classless addressing supports Variable Length Subnet Masking (VLSM), which allows different subnets to have different subnet masks.

Conclusion

Classless addressing, also known as Classless Inter-Domain Routing (CIDR), was introduced to overcome the limitations of classful addressing. It provides a more flexible and efficient way to allocate IP addresses and create subnets. By using a variable-length subnet mask, CIDR allows network administrators to allocate IP addresses in blocks of any size, rather than being restricted to the fixed sizes of Class A, B, and C networks.

This approach has significantly extended the usable life of IPv4 addressing by making more efficient use of the available address space. It also provides the foundation for modern routing protocols and network design practices.

Test Your Knowledge

Take a quiz to reinforce what you've learned

Exam Preparation

Access short and long answer questions for written exams

Share this page

On this page

Edit on Github