Domain 1Network FundamentalsCORE

IPv4 Subnetting and VLSM

Mathematical concepts of IPv4 subnetting, Variable Length Subnet Masking (VLSM), CIDR notation, and calculating subnets and host ranges.

Domain: Domain 1: Network Fundamentals•Updated: 2026-08-26
#Subnetting#VLSM#CIDR#Subnet Mask#Host Calculation

IPv4 Subnetting and CIDR

Classful vs. Classless Addressing

  • Concept: Originally, IPv4 addresses were divided into strict “Classes” (Classful). This led to massive IP address waste. CIDR (Classless Inter-Domain Routing) was introduced by the IETF in 1993 to replace classful addressing, allowing flexible network sizes.
  • Details: IP addresses are assigned by IANA (Internet Assigned Numbers Authority).

IPv4 Address Classes (Classful)

Class First Octet Range First Octet Binary Default Mask Total Networks Hosts per Network
A 0 - 127 0xxxxxxx /8 (255.0.0.0) 128 16,777,216
B 128 - 191 10xxxxxx /16 (255.255.0.0) 16,384 65,536
C 192 - 223 110xxxxx /24 (255.255.255.0) 2,097,152 256
D 224 - 239 1110xxxx N/A N/A (Multicast) N/A
E 240 - 255 1111xxxx N/A N/A (Experimental) N/A

Things to note:

  • Only Classes A, B, and C are assigned to devices.
  • Classful addressing wastes IPs (e.g., assigning a /24 Class C network to a point-to-point router link wastes 252 addresses).

Subnetting Formulas and Rules

  • Concept: Subnetting borrows bits from the host portion of an IP address to create smaller networks (subnets).
  • Formulas:
    • Usable Hosts per Subnet: $2^h - 2$ (where $h$ = number of host bits). We subtract 2 for the Network Address and Broadcast Address.
    • Number of Subnets: $2^s$ (where $s$ = number of borrowed bits).
  • Special Prefix Lengths:
    • /31 (255.255.255.254): Standard formula yields 0 usable hosts. However, for point-to-point links, you can break the rules and use both addresses (no network/broadcast needed).
    • /32 (255.255.255.255): Yields -1 usable hosts. Used exclusively to represent a single specific host (e.g., in static routes or loopback interfaces).

The Subnetting Process (FLSM)

  • Concept: FLSM (Fixed-Length Subnet Masks) means all subnets created from a major network are the exact same size.
  • The “Magic Number” (Block Size) Trick: To find subsequent subnets quickly, identify the decimal value of the last bit in the network portion (the borrowed bit). Add this value to the previous subnet’s network address to find the next one.
flowchart TD
    A[Identify Requirements] --> B{Need specific # of subnets?}
    B -- Yes --> C[Borrow 's' bits: 2^s >= required subnets]
    B -- No --> D{Need specific # of hosts?}
    D -- Yes --> E[Leave 'h' host bits: 2^h - 2 >= required hosts]
    C --> F[Calculate New Prefix Length]
    E --> F
    F --> G[Calculate Block Size / Magic Number]
    G --> H[List Subnets by adding Block Size]

Subnet Mask Cheat Sheet (Class C Example)

CIDR Subnet Mask Host Bits Usable Hosts Block Size
/24 255.255.255.0 8 254 256
/25 255.255.255.128 7 126 128
/26 255.255.255.192 6 62 64
/27 255.255.255.224 5 30 32
/28 255.255.255.240 4 14 16
/29 255.255.255.248 3 6 8
/30 255.255.255.252 2 2 4

Things to note: For Class B and Class A networks, the process is exactly the same, but you borrow bits across multiple octets (e.g., /17, /11).

Identifying Subnets and Ranges

To find the network, broadcast, and usable range for any given IP/prefix:

  1. Network Address: Convert IP to binary. Set all host bits to 0. Convert back to decimal.
  2. Broadcast Address: Convert IP to binary. Set all host bits to 1. Convert back to decimal.
  3. First Usable: Network Address + 1.
  4. Last Usable: Broadcast Address - 1.

Variable-Length Subnet Masks (VLSM)

  • Concept: VLSM allows you to create subnets of different sizes within the same major network to minimize wasted IP space.
  • Rules for VLSM:
    1. Always assign the largest subnet first (at the lowest IP address).
    2. Assign the next largest subnet immediately after the previous one’s broadcast address.
    3. Repeat until all requirements are met, ending with the smallest (point-to-point).

VLSM Example Walkthrough

Requirement: Subnet 192.168.1.0/24 for: Tokyo LAN A (110 hosts), Toronto LAN B (45), Toronto LAN A (29), Tokyo LAN B (8), and a P2P link (2 hosts).

Order Subnet Name Hosts Needed Prefix Network Address Broadcast Address Usable Range
1 Tokyo LAN A 110 /25 192.168.1.0 192.168.1.127 .1 - .126
2 Toronto LAN B 45 /26 192.168.1.128 192.168.1.191 .129 - .190
3 Toronto LAN A 29 /27 192.168.1.192 192.168.1.223 .193 - .222
4 Tokyo LAN B 8 /28 192.168.1.224 192.168.1.239 .225 - .238
5 P2P Link 2 /30* 192.168.1.240 192.168.1.243 .241 - .242

*Note: While /31 is technically valid for P2P, the CCNA exam traditionally expects /30 for a 2-host requirement unless explicitly stated otherwise.

Key Practice Examples (Zero Loss)

  • Class C Subnetting: 192.168.1.0/24 divided into 4 subnets of 45 hosts.
    • Requires 47 addresses per subnet (45 + network + broadcast).
    • Use /26 (62 usable hosts). Subnets: .0, .64, .128, .192.
  • Class C Subnetting: 192.168.255.0/24 into 5 equal subnets.
    • Borrow 3 bits ($2^3 = 8$ subnets). Use /27. Block size is 32.
  • Identify Subnet: Host 192.168.5.57/27.
    • /27 means block size is 32. Multiples of 32: 0, 32, 64.
    • Host belongs to 192.168.5.32/27.
  • Identify Subnet: Host 192.168.29.219/29.
    • /29 means block size is 8. Multiples of 8: …208, 216, 224.
    • Host belongs to 192.168.29.216/29.
  • Class B Subnetting: 172.16.0.0/16 into 80 subnets.
    • Borrow 7 bits ($2^7 = 128$). Use /23 (255.255.254.0).
  • Class B Subnetting: 172.22.0.0/16 into 500 subnets.
    • Borrow 9 bits ($2^9 = 512$). Use /25.
  • Class B Subnetting: 172.18.0.0/16 into 250 subnets with 250 hosts each.
    • Need 8 subnet bits (256 subnets) and 8 host bits (254 hosts). Use /24.
  • Identify Subnet: Host 172.25.217.192/21.
    • /21 means 3rd octet block size is 8 (256 - 248 = 8). Multiples: 0, 8, 16, 24… 216, 224.
    • Host belongs to 172.25.216.0/21.
  • Class A Subnetting: 10.0.0.0/8 into 2000 subnets.
    • Borrow 11 bits ($2^{11} = 2048$). Use /19. Leaves 13 host bits (8,190 hosts/subnet).
  • Identify Class A Range: 10.217.182.223/11.
    • /11 means 3 bits borrowed in 2nd octet (block size 32). Multiples: 192, 224.
    • Network: 10.192.0.0 | Broadcast: 10.223.255.255 | First Usable: 10.192.0.1 | Last Usable: 10.223.255.254.

Cisco IOS Commands & Formulas Reference

Subnetting Math Formulas

# Calculate Usable Hosts
Usable_Hosts = (2 ^ host_bits) - 2

# Calculate Number of Subnets
Total_Subnets = 2 ^ borrowed_bits

# Calculate Block Size (Magic Number)
Block_Size = 256 - (Value of the last octet in the subnet mask)

Applying Subnets in Cisco IOS

! Entering interface configuration mode
Router(config)# interface GigabitEthernet0/0

! Assigning an IP address and subnet mask (Dotted Decimal format required in IOS)
! Example: 192.168.1.1 with a /26 mask (255.255.255.192)
Router(config-if)# ip address 192.168.1.1 255.255.255.192

! Activating the interface
Router(config-if)# no shutdown

! Verifying the IP and subnet configuration
Router# show ip interface brief
Router# show ip route

Things to note:

  • Cisco IOS does not accept CIDR slash notation (e.g., /26) when configuring interface IP addresses. You must use the dotted-decimal subnet mask (e.g., 255.255.255.192).
  • CIDR notation is only used in documentation, routing tables (show ip route), and some specific routing protocol configurations (like EIGRP/OSPF summarization).