CACS303 Computer Networking

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., /26 gives 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.7 is broadcast, 192.168.1.0 is 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:

08162431Class A (1-126)8 bitsHosts (0-127)24 bitsClass B (128-191)16 bitsHosts (0-65535)16 bitsClass C (192-223)24 bitsHosts (0-255)8 bits
Classful Addressing: Network vs. Host Bits (Default Subnet Masks)
08162431Octet 18 bitsOctet 28 bitsOctet 38 bitsOctet 48 bits
Binary-to-Decimal Conversion Example: 192.168.1.1 (11000000.10101000.00000001.00000001)
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 <|-- ClassE

Key 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.31
Subnet Assignment Workflow: NTC’s Branch Network

Subnetting Steps:

  1. Identify the network address and subnet mask:
    • Example: 192.168.10.0/28 (subnet mask: 255.255.255.240).
  2. Determine borrowed bits:
    • /28 means 28 network bits → 4 borrowed host bits.
  3. 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:

  1. Borrow 3 bits (since ).
  2. New subnet mask: /27 (24 + 3 = 27).
  3. Subnet IDs:
    • 192.168.20.0/27 (network), 192.168.20.32/27, ..., 192.168.20.192/27.
  4. Usable hosts per subnet: .
NTC AdminBranch1 (192.168.20.0/27)Branch2 (192.168.20.32/27)PC1 (192.168.20.5)PC2 (192.168.20.35)
Subnet Assignment Example: /27 Subnet with Usable Hosts (192.168.20.1–192.168.20.30 and 192.168.20.33–192.168.20.62)

3. CIDR Notation: The Modern Approach

Classless Inter-Domain Routing (CIDR) replaces classes with variable-length subnet masks (VLSM).

  • Example: 192.168.1.0/26 means:
    • Network prefix: 26 bits (192.168.1.0).
    • Subnet mask: 255.255.255.192.
    • Hosts per subnet: .
063.5127190.5254/24 (256 hosts)254/25 (128 hosts)126/26 (64 hosts)62/27 (32 hosts)30/28 (16 hosts)14
Usable Hosts per CIDR Block (2^(32-n) - 2)
04194303.5838860712582910.516777214/816777214/1665534/24254/2730
Usable Hosts per CIDR Block (2^(32-n) - 2)

Advantages:

  • Eliminates classful waste (e.g., /29 for 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:

  1. Network address: All host bits = 0 (e.g., 192.168.1.0/29).
  2. Broadcast address: All host bits = 1 (e.g., 192.168.1.7/29).
  3. Usable hosts: All others (e.g., 192.168.1.1 to 192.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.65 to 192.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., /29 for small offices, /24 for districts).
  • Example: A /24 network (10.0.0.0/24) is subnetted into /27 subnets 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 in 192.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: /28 subnets for each server group (e.g., 203.123.45.0/28 for checkout servers).

6. Common Pitfalls and Exam Traps

  1. Forgetting to subtract 2 for network/broadcast:
    • Wrong: hosts.
    • Correct: usable hosts.
  2. Miscounting borrowed bits:
    • /25 borrows 3 bits → 8 subnets, not 4.
  3. Confusing subnet mask formats:
    • 255.255.255.240 = /28 (not /24).
  4. Private vs. public IPs:
    • 10.0.0.1 is private; 8.8.8.8 is public (Google DNS).

Exam Tip

  1. Memorize private ranges: 10.x.x.x, 172.16–31.x.x, 192.168.x.x.
  2. Practice subnetting:
    • Given 192.168.1.0/26, calculate:
      • Subnet mask: 255.255.255.192.
      • Subnets: 4 (0, 64, 128, 192).
      • Hosts/subnet: 62.
  3. Use the formula:
    • Subnets: .
    • Hosts: .
  4. Draw diagrams: Always sketch subnet ranges (e.g., 0, 64, 128, 192 for /26).
  5. 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/20 into 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., /29 for small offices) to efficiently allocate public IPs to thousands of users without wasting addresses. For example, a /24 block is divided into /27 subnets 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 in 192.168.10.0/24, while web servers use 192.168.20.0/24.
  • Daraz’s Load Balancers: Distributes traffic across servers using CIDR-routed subnets (e.g., /26 blocks) 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…