Mastering Subnetting
Hello, I'm Sheheryar Altaf, a BSCS student at COMSATS University Islamabad. Passionate about computer science, I'm dedicated to mastering Object-Oriented Programming (OOP), Data Structures and Algorithms (DSA), and databases.
I have practical experience in projects like the Voting Management System database, where I've applied these skills hands-on.
I'm eager to tackle new challenges and continuously expand my knowledge and skills in computer science. Here's to excelling in my studies and embracing endless possibilities!
Subnetting and Subnet Masks Explained
Concepts:
Network: Think of it as the entire city.
Subnet: These are like individual neighborhoods within the city.
Purpose of Subnetting:
Subnetting divides a larger network (the city) into smaller, manageable sections (subnets or neighborhoods). This organization helps improve performance and security.
Subnet Mask:
Acts as a zoning plan to identify which portion of an IP address is for the network and which is for hosts.
Example: The subnet mask
255.255.255.0can be visualized in binary as11111111.11111111.11111111.00000000. The1sindicate the network part, and the0sindicate the host part.
Key Components:
Network Address: Identifies the subnet (like the name of a party location).
- All host bits are set to 0.
Broadcast Address: Used to communicate with all devices in the subnet (like a loudspeaker announcing to everyone).
- All host bits are set to 1.
CIDR Notation:
/27 means 27 bits are used for the network part, leaving 5 bits for hosts.
Total Addresses: (2^5 = 32)
Usable Addresses: (32 - 2 = 30) (subtracting the network and broadcast addresses)
Total Number of Addresses:
- Total addresses in a subnet can be calculated using the formula: (2^{\text{number of host bits}})
Total Number of Addresses refers to the total number of IP addresses within a given subnet. This includes:
Usable Addresses: Addresses that can be assigned to devices (hosts) on the network.
Network Address: The address that identifies the subnet itself.
Broadcast Address: The address used to communicate with all devices in the subnet.
Classes of IP Addresses:
Class A:
First Octet: 0 to 127
Default Subnet Mask: 255.0.0.0
Can accommodate about 16 million hosts.
Class B:
First Octet: 128 to 191
Default Subnet Mask: 255.255.0.0
Can support about 65,000 hosts.
Class C:
First Octet: 192 to 223
Default Subnet Mask: 255.255.255.0
Suitable for small organizations, supports 256 hosts.
Class D (Multicast):
- First Octet: 224 to 239
Class E (Experimental):
- First Octet: 240 to 255
Custom Subnet Masks:
The subnet mask 255.255.255.224 is not a default Class C mask; it’s a customized mask for creating smaller subnets.
Example of CIDR Notation:
192.168.1.0/24:
- This means the first 24 bits are for the network (subnet mask: 255.255.255.0).
Subnetting Summary Example:
Original Network:
IP Address:
172.16.0.0Default Subnet Mask:
255.255.0.0(/16)
Objective: Create subnets with at least 500 usable hosts.
Steps:
Determine Required Subnet Size:
To fit 500 hosts, need at least 512 addresses (including network and broadcast).
Use 9 bits for hosts: (2^9 = 512) addresses, giving 510 usable.
Calculate New Subnet Mask:
Default mask is /16. New mask requires 23 bits for the network.
New Subnet Mask:
255.255.254.0(/23).
Number of Subnets:
With a /23 subnet mask, you use 7 additional bits for subnetting:
(2^{(23 - 16)} = 2^7 = 128) subnets
Usable Hosts per Subnet:
Each /23 supports 9 bits for hosts:
(2^9 - 2 = 510) usable hosts
Summary:
Original IP Address:
172.16.0.0New Subnet Mask:
255.255.254.0(/23)Number of Subnets: 128
Usable Hosts per Subnet: 510
Additional Points:
IPv6: Uses 128 bits, structured as eight groups of hexadecimal digits.
Network vs. Host Address:
Network Address: Identifies the subnet.
Host Address: Identifies individual devices on that subnet.
Subnet Mask Purpose: Reveals which part of the IP is for the network and which part is for hosts, usually requiring conversion to binary.
Why Not Just One Network?
Having a single network would lead to broadcast chaos, making it difficult to pinpoint issues. Subnetting minimizes broadcasts and enhances network efficiency.
Solution: Routers
Routers prevent broadcasts from overwhelming the network by directing traffic intelligently between networks.
This separation allows for more efficient communication.
Number of Hosts Calculation
To find the number of hosts in a subnet:
- Formula: (2^{(\text{total bits} - \text{network bits})} - 2) (subtracting 2 accounts for the network and broadcast addresses).
Subnetting
Subnetting allows you to create smaller networks within a larger one.
By borrowing bits from the host portion (changing 0s to 1s), you can create more subnets but reduce the number of available hosts in each subnet.
Important Points
You can borrow host bits until you have at least 2 hosts remaining.
If you borrow too many bits, you might end up with zero usable hosts in that subnet.
Network Address: Determined using the AND operation between the IP address and subnet mask.
Broadcast Address: Found by inverting the subnet mask and using the OR operation with the network address.
Network Address:
First address in the subnet.
Represents the subnet itself and is not assigned to any device.
Broadcast Address:
Last address in the subnet.
Used for sending messages to all devices in the subnet and is also not assigned to any device.

