0% found this document useful (0 votes)
18 views9 pages

Classless Addressing in IP Addressing - GeeksforGeeks

The document explains classless addressing in IP addressing, detailing how network addresses and masks are used to identify networks and hosts. It covers subnetting, which divides large address blocks into smaller sub-blocks for efficient network management, and provides examples of calculations related to subnets and hosts. Additionally, it includes a C++ program that converts classful IP addresses to classless CIDR notation.

Uploaded by

kemerwaonani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views9 pages

Classless Addressing in IP Addressing - GeeksforGeeks

The document explains classless addressing in IP addressing, detailing how network addresses and masks are used to identify networks and hosts. It covers subnetting, which divides large address blocks into smaller sub-blocks for efficient network management, and provides examples of calculations related to subnets and hosts. Additionally, it includes a C++ program that converts classful IP addresses to classless CIDR notation.

Uploaded by

kemerwaonani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Classless Addressing in IP Addressing

Last Updated : 20 Sep, 2023

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.

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.

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

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.

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)
Open In App
6. Last Host ID : Subnet address + Number of Hosts

C++ C Python3 C#

#include <bits/stdc++.h>

using namespace std;

string ip_classless(string ip){


// Extract the first octet as a string and then convert it to an
int using stoi function

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;

// This Code is contributed by Himesh Singh Chauhan


return 0;
}

Explanation:

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. The resulting CIDR notation is returned by the function
ip_classless.
Open In App
Enter an IP address in classful notation: 192.168.0.0
Classless address: 192.168.0.0/24

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, no. of subnets = 2(25-16) = 29 = 512.

No. of hosts per subnet = 2(32-25) - 2 = 27 - 2 = 128 - 2 = 126

For the first subnet block(means 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 and broadcast address = 172.16.0.127

GATE Previous Year Questions


GATE | GATE CS 2003 | Question 82

GATE | GATE CS 2006 | Question 45

GATE | GATE CS 2007 | Question 67

GATE | GATE CS 2008 | Question 57

GATE | GATE CS 2010 | Question 47

GATE | GATE CS 2012 | Question 21

GATE | GATE CS 2015 Set 3 | Question 48

Advertise with us Next Article


Classful vs Classless Addressing

kartik Follow
Open In App
66

Similar Reads

Computer Network Tutorial


A Computer Network is a system where two or more devices are linked together to share data,
resources and information. These networks can range from simple setups, like connecting two device…
7 min read

Basics of Computer Network

Network Hardware and Software

Network Topology

OSI Model

Protocols

TCP/IP Model

Medium Access Control

SLIDING WINDOW PROTOCOLS

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

What is IPv6? Open In App


The most common version of the Internet Protocol currently is IPv6. The well-known IPv6 protocol is
being used and deployed more often, especially in mobile phone markets. IP address determines wh…
5 min read

Introduction of Classful IP Addressing


An IP address is an address that has information about how to reach a specific host, especially
outside the LAN. An IP address is a 32-bit unique address having an address space of 232.Classful I…
11 min read

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. Mask is a 32-bit binary…
7 min read

Classful vs Classless Addressing


Classful and Classless addressing are methods used in networking to manage IP addresses. Classful
addressing divides IP addresses into fixed classes (A, B, C, D, E), each with predefined ranges. In…
( )
6 min read

Classless Inter Domain Routing (CIDR)


Classless Inter-Domain Routing (CIDR) is a method of IP address allocation and IP routing that allows
for more efficient use of IP addresses. CIDR is based on the idea that IP addresses can be allocated…
6 min read

Supernetting in Network Layer


Supernetting is the opposite of Subnetting. In subnetting, a single big network is divided into multiple
smaller subnetworks. In Supernetting, multiple networks are combined into a bigger network termed …
4 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

Difference between Subnetting and Supernetting


Subnetting is the procedure to divide the network into sub-networks or small networks, these smaller
networks are known as subnets. The subnet is also defined as an internal address made up of a…
4 min read

Article Tags : Computer Networks


Open In App
Network Layer
Corporate & Communications
Address:
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar
Pradesh (201305)

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

DSA Data Science & ML


Data Structures Data Science With Python
Algorithms Data Science For Beginner
DSA for Beginners Machine Learning
Basic DSA Problems ML Maths
DSA Roadmap Data Visualisation
Top 100 DSA Interview Problems Pandas
DSA Roadmap by Sandeep Jain NumPy
All Cheat Sheets NLP
Deep Learning

Web Technologies Python Tutorial


HTML Python Programming Examples
CSS Python Projects
JavaScript Python Tkinter
TypeScript Python Web Scraping
ReactJS OpenCV Tutorial
NextJS Python Interview Question
Bootstrap Django
Web Design

Computer Science DevOps


Operating Systems Git
Computer Network Linux
Database Management System AWS
Software Engineering Docker
Digital Logic Design Kubernetes
Engineering Maths Azure
Software Development GCP
Software Testing DevOps Roadmap

System Design Inteview Preparation


High Level Design Competitive Programming
Low Level Design Open In App Top DS or Algo for CP
UML Diagrams Company-Wise Recruitment Process
Interview Guide Company-Wise Preparation
Design Patterns Aptitude Preparation
OOAD Puzzles
System Design Bootcamp
Interview Questions

School Subjects GeeksforGeeks Videos


Mathematics DSA
Physics Python
Chemistry Java
Biology C++
Social Science Web Development
English Grammar Data Science
Commerce CS Subjects
World GK

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved

Aptitude Engineering Mathematics Discrete Mathematics Operating System DBMS Compu

Open In App

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy