IP Address Classes and Prefix Lengths

In IPv4, addresses are categorized into classes, but only Class A, B, and C addresses can be assigned to devices as IP addresses:

  • Class A: Prefix Length /8
  • Class B: Prefix Length /16
  • Class C: Prefix Length /24

IP Address Allocation and Wastefulness

The Internet Assigned Numbers Authority (IANA) assigns IPv4 addresses/networks to companies based on their size. However, the “classful” system led to significant waste of IP addresses. For example, a company needing 5,000 addresses would be assigned a Class B IP address, which has over 65,000 addresses—resulting in more than 60,000 unused addresses.

Introduction of CIDR

To address this inefficiency, the Internet Engineering Task Force (IETF) introduced CIDR (Classless Inter-Domain Routing) in 1993. CIDR removes the rigid size constraints of Class A, B, and C networks, allowing them to be divided into smaller, more efficient networks called “subnets.”


Calculating Usable IP Addresses

To determine how many usable IP addresses are in a given network:

Where:

  • n = Number of host bits

Example: CIDR Practice with /25

  • Network: 203.0.113.0/25

  • Binary Representation:

    1100 1011 . 0000 0000 . 0111 0001 . 0 | 000 0000
  • Subnet Mask:

    1111 1111 . 1111 1111 . 1111 1111 . 1 | 000 0000

    This equals 255.255.255.128.

  • Usable Hosts:

    2^(7 bits) - 2 = 126 hosts

Example: CIDR Practice with /28

  • Network: 203.0.113.0/28

  • Binary Representation:

    1100 1011 . 0000 0000 . 0111 0001 . 0000 | 0000
  • Subnet Mask:

    1111 1111 . 1111 1111 . 1111 1111 . 1111 | 0000

    This equals 255.255.255.240.

  • Usable Hosts:

    2^(4 bits) - 2 = 14 hosts

Subnetting Cheatsheet

Group Size1286432168421
Subnet Mask128192224240248252254255
CIDR/25/26/27/28/29/30/31/32
3rd Octet/17/18/19/20/21/22/23/24
2nd Octet/9/10/11/12/13/14/15/16
1st Octet/1/2/3/4/5/6/7/8

Subnetting Process Overview

  1. Identify CIDR/Subnet Mask: Locate it on the cheat sheet.
  2. Find Group Size: Increase by group size until passing the target IP.
  3. Calculate:
    • Network ID: Number before the target IP.
    • Next Network: Number after the target IP.
    • Broadcast Address: IP address before the next network.
    • First Host: IP address after the network ID.
    • Last Host: IP address before the broadcast IP.
    • Total Addresses: Group size (minus 2 for usable addresses).

Example: Solving CIDR for 3rd Octet IPs

  • Address: 10.4.77.188/19
  • Subnet Mask: 255.255.224.0
  • Group Size: 256 - 224 = 32
  • Range: 10.4.64.0 to 10.4.95.255
  • Usable Addresses: 8192

Alternative Subnetting Method (Without Cheat Sheet)

  1. Identify the “Magic Octet”: Where the IP/Prefix lies.
  2. Count Network Bits: Determine the address group size.
  3. Calculate Subnet Mask: Based on the magic octet.
  4. Determine Base Network and Broadcast:
    • If remainder in division, use integer times group size.
    • No remainder, base address is that octet value.
  5. Calculate Subnets and Usable Hosts.

Example 1:

  • Address: 154.219.154.180/20
  • Magic Octet: 3rd
  • Subnet Mask: 255.255.240.0
  • Network: 154.219.144.0
  • Broadcast: 154.219.159.255
  • Subnets: 16
  • Total Hosts: 4094

Example 2:

  • Address: 84.75.21.6/10
  • Magic Octet: 2nd
  • Subnet Mask: 255.192.0.0
  • Network: 84.64.0.0
  • Broadcast: 84.127.255.255
  • Subnets: 4
  • Total Hosts: 4,194,302