Classless Addressing in IP Addressing - GeeksforGeeks
Classless Addressing in IP Addressing - GeeksforGeeks
Mask is a 32-bit binary number that gives the network address in the
address block when AND operation is bitwise applied on the mask and
any IP address of the block.
Class A - 255.0.0.0
Class B - 255.255.0.0
Class C - 255.255.255.0
Question: 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.
▲ inside a network. Subnets make
A subnet or subnetwork is a network
networks more efficient. Through subnetting,
Open In App 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 net 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,
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.
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
C++ C Python3 C#
#include <bits/stdc++.h>
int first_octet=stoi(ip.substr(0,ip.find('.')));
if(first_octet>=0 and first_octet<=127){
// Means the IP Address in Class A
return ip+"/8";
}
if(first_octet>=128 and first_octet<=191){
// Means the IP Address is in Class B
return ip+"/16";
}
if(first_octet>=192 and first_octet<=223){
// Means the IP Address is in Class C
return ip+"/24";
}
return "Reserved IP Address. Invalid.";
}
//Driver Code
int main() {
// Will store the ip address as an input in ip variable
string ip;
cout<<"Enter the IP Address: ";
cin>>ip;
cout<<ip_classless(ip)<<endl;
Explanation:
Solution:
kartik Follow
Open In App
66
Similar Reads
Network Topology
OSI Model
Protocols
TCP/IP Model
IP Addressing
What is IPv4?
IP stands for Internet Protocol version v4 stands for Version Four (IPv4), is the most widely used
system for identifying devices on a network. It uses a set of four numbers, separated by periods (like…
)
5 min read
Introduction To Subnetting
Subnetting is the process of dividing a large network into smaller networks called "subnets." Subnets
provide each group of devices with their own space to communicate, which ultimately helps the…
8 min read
Registered Address:
K 061, Tower K, Gulshan Vivante
Apartment, Sector 137, Noida,
Gautam Buddh Nagar, Uttar Pradesh,
201305
Advertise with us
Open In App
Company Languages
About Us Python
Legal Java
Privacy Policy C++
In Media PHP
Contact Us GoLang
Advertise with us SQL
GFG Corporate Solution R Language
Placement Training Program Android Tutorial
Tutorials Archive
Open In App