Computer NetworkingUnit 69 min read
IPv4 Addressing & Subnetting: Classes, CIDR, Subnet Masks & Calculations
Unit 6 of Computer Networking covers IPv4 address structure, classful addressing (A/B/C/D/E), CIDR notation, subnet masks, subnetting techniques, and real-world applications like NTC’s network segmentation and eSewa’s IP allocation. Learn to calculate subnets, usable hosts, and broadcast addresses with step-by-step exa
TAKEAWAYS:
- IPv4 addresses are 32-bit hierarchical identifiers divided into classes (A–E), each with predefined default subnet masks and address ranges (e.g., Class A: 1.0.0.0–126.255.255.255).
- Subnetting splits a network into smaller subnets using borrowed host bits, requiring calculations for subnet mask, number of subnets, and usable hosts per subnet.
- CIDR notation (e.g.,
/24) replaces classful addressing by specifying the prefix length, enabling flexible subnetting (e.g.,/26gives 64 hosts per subnet). - Private vs. public IPs: Private ranges (e.g.,
10.0.0.0/8,192.168.0.0/16) are used internally (e.g., home routers), while public IPs (assigned by IANA) route globally. - Broadcast and network addresses are reserved in each subnet (e.g., in
192.168.1.0/29,192.168.1.7is broadcast,192.168.1.0is network). - Real-world tie-ins: NTC uses subnetting to manage ISP networks, eSewa’s servers rely on private IPs for internal traffic, and Daraz’s load balancers distribute traffic via CIDR-routed subnets.
1. IPv4 Address Basics: Structure and Classes
IPv4 addresses are 32-bit binary numbers represented in dotted-decimal notation (e.g., 192.168.1.1). They are divided into classes (A–E), each with a default subnet mask and purpose:
classDiagram
class IPv4Address {
+32-bit binary
+Dotted-decimal (e.g., 192.168.1.1)
+Classes: A, B, C, D, E
+Default subnet masks
}
class ClassA {
+Range: 1.0.0.0–126.255.255.255
+Subnet mask: 255.0.0.0 (/8)
+First octet: Network ID
}
class ClassB {
+Range: 128.0.0.0–191.255.255.255
+Subnet mask: 255.255.0.0 (/16)
+First two octets: Network ID
}
class ClassC {
+Range: 192.0.0.0–223.255.255.255
+Subnet mask: 255.255.255.0 (/24)
+First three octets: Network ID
}
class ClassD {
+Range: 224.0.0.0–239.255.255.255
+Multicast (e.g., video streaming)
}
class ClassE {
+Range: 240.0.0.0–255.255.255.255
+Reserved for research
}
IPv4Address <|-- ClassA
IPv4Address <|-- ClassB
IPv4Address <|-- ClassC
IPv4Address <|-- ClassD
IPv4Address <|-- ClassEKey Observations:
- Class A: Large networks (e.g., government agencies). Wastes addresses for small networks.
- Class B: Medium networks (e.g., universities). Still inefficient for small subnets.
- Class C: Small networks (e.g., home routers). Exhausted due to limited hosts (254).
- Private IPs (non-routable on the internet):
10.0.0.0/8(Class A)172.16.0.0/12(Class B)192.168.0.0/16(Class C)- Used in eSewa’s internal servers and home Wi-Fi routers.
2. Subnetting: Why and How
Problem: Classful addressing wastes IPs (e.g., a Class B network gives 65,534 hosts to a small office). Solution: Subnetting borrows bits from the host portion to create smaller subnets.
sequenceDiagram
participant Admin as NTC Admin
participant Router as Router
participant PC1 as Branch1 PC (192.168.20.5)
participant PC2 as Branch2 PC (192.168.20.35)
Admin->>Router: Assign /27 subnet (192.168.20.0/27)
Router-->>PC1: Allocate 192.168.20.5 (usable host)
Router-->>PC2: Allocate 192.168.20.35 (usable host)
PC1->>PC2: Ping (192.168.20.35)
note right: Subnet mask: 255.255.255.224
note right: Broadcast: 192.168.20.31Subnet Assignment Workflow: NTC’s Branch NetworkSubnetting Steps:
- Identify the network address and subnet mask:
- Example:
192.168.10.0/28(subnet mask:255.255.255.240).
- Example:
- Determine borrowed bits:
/28means 28 network bits → 4 borrowed host bits.
- Calculate:
- Number of subnets: .
- Hosts per subnet: (subtract network and broadcast addresses).
- Subnet increment: (for the last octet).
Worked Example: NTC’s ISP Network
NTC assigns 192.168.20.0/24 to a district. To create 5 subnets for 5 branches:
- Borrow 3 bits (since ).
- New subnet mask:
/27(24 + 3 = 27). - Subnet IDs:
192.168.20.0/27(network),192.168.20.32/27, ...,192.168.20.192/27.
- Usable hosts per subnet: .
3. CIDR Notation: The Modern Approach
Classless Inter-Domain Routing (CIDR) replaces classes with variable-length subnet masks (VLSM).
- Example:
192.168.1.0/26means:- Network prefix: 26 bits (
192.168.1.0). - Subnet mask:
255.255.255.192. - Hosts per subnet: .
- Network prefix: 26 bits (
Advantages:
- Eliminates classful waste (e.g.,
/29for a small subnet). - Used by NEPSE’s trading terminals to allocate minimal IPs to each workstation.
Comparison Table:
| Feature | Classful Addressing | CIDR |
|---|---|---|
| Flexibility | Rigid (fixed class sizes) | Variable (VLSM) |
| Efficiency | Wastes IPs | Optimal allocation |
| Example | 172.16.0.0/16 |
172.16.0.0/24 (subnet) |
4. Special Addresses in Subnets
Every subnet has three reserved addresses:
- Network address: All host bits =
0(e.g.,192.168.1.0/29). - Broadcast address: All host bits =
1(e.g.,192.168.1.7/29). - Usable hosts: All others (e.g.,
192.168.1.1to192.168.1.6).
Example for 192.168.1.64/26:
- Network:
192.168.1.64 - Broadcast:
192.168.1.127 - Usable hosts:
192.168.1.65to192.168.1.126(62 hosts).
5. Real-World Applications
1. NTC’s Internet Service Provider (ISP) Networks
- Problem: NTC needs to assign IPs to thousands of users without wasting addresses.
- Solution: Uses CIDR subnetting (e.g.,
/29for small offices,/24for districts). - Example: A
/24network (10.0.0.0/24) is subnetted into/27subnets for 8 branches.
2. eSewa’s Internal Server Farm
- Problem: eSewa’s backend servers must communicate privately without exposing IPs.
- Solution: Uses private IP ranges (
192.168.x.x/16) and NAT to translate to public IPs. - Example: Database servers in
192.168.10.0/24, web servers in192.168.20.0/24.
3. Daraz’s Load Balancer Traffic Routing
- Problem: Daraz’s website must distribute traffic across multiple servers.
- Solution: Uses CIDR-routed subnets to direct requests to specific server pools.
- Example:
/28subnets for each server group (e.g.,203.123.45.0/28for checkout servers).
6. Common Pitfalls and Exam Traps
- Forgetting to subtract 2 for network/broadcast:
- Wrong: hosts.
- Correct: usable hosts.
- Miscounting borrowed bits:
/25borrows 3 bits → 8 subnets, not 4.
- Confusing subnet mask formats:
255.255.255.240=/28(not/24).
- Private vs. public IPs:
10.0.0.1is private;8.8.8.8is public (Google DNS).
Exam Tip
- Memorize private ranges:
10.x.x.x,172.16–31.x.x,192.168.x.x. - Practice subnetting:
- Given
192.168.1.0/26, calculate:- Subnet mask:
255.255.255.192. - Subnets: 4 (
0,64,128,192). - Hosts/subnet: 62.
- Subnet mask:
- Given
- Use the formula:
- Subnets: .
- Hosts: .
- Draw diagrams: Always sketch subnet ranges (e.g.,
0,64,128,192for/26). - Watch for CIDR tricks:
/30= 2 hosts (point-to-point links)./31= experimental (RFC 3021).
Final Note: Subnetting is 80% calculation, 20% theory. Master the formulas, and you’ll ace the exam! For practice, try:
- Subnet
172.16.0.0/20into 8 equal subnets. - Find the broadcast address of
10.5.6.128/25.
In the real world
- NTC’s ISP Networks: Uses CIDR subnetting (e.g.,
/29for small offices) to efficiently allocate public IPs to thousands of users without wasting addresses. For example, a/24block is divided into/27subnets for 8 branches, each with 30 usable hosts. - eSewa’s Internal Servers: Employs private IP ranges (
192.168.x.x/16) and NAT to hide backend servers from public exposure. Database servers reside in192.168.10.0/24, while web servers use192.168.20.0/24. - Daraz’s Load Balancers: Distributes traffic across servers using CIDR-routed subnets (e.g.,
/26blocks) to ensure optimal resource allocation and minimize latency for users across Nepal.
Based on the TU BCA syllabus for Computer Networking (CACS303), unit 6.
Discussion
Loading…