Stackvora.tech

Subnetting in 10 Minutes — CIDR, VLSM and Quick Math

Understanding IP subnetting is fundamental for any network professional, allowing for efficient IP address allocation, reduced broadcast domains, and…

Understanding IP subnetting is fundamental for any network professional, allowing for efficient IP address allocation, reduced broadcast domains, and improved network security. This guide covers Classless Inter-Domain Routing (CIDR) notation, Variable Length Subnet Masking (VLSM), and practical methods for rapid subnet calculation, moving beyond traditional classful boundaries.

We'll focus on IPv4, providing the core concepts and quick-math techniques essential for designing and troubleshooting modern networks.

CIDR: The Foundation of Modern Subnetting

Classless Inter-Domain Routing (CIDR), introduced in RFC 1518 and formalized in RFC 4632, replaced the rigid class A, B, and C addressing scheme with a more flexible system. Instead of fixed network boundaries, CIDR uses a network prefix length (often called the CIDR suffix or "slash notation") to define the network portion of an IP address.

For example, 192.168.1.0/24 indicates that the first 24 bits are the network address, and the remaining 8 bits are for host addresses. This flexibility allows for arbitrary network sizes, enabling more efficient use of the IPv4 address space.

Key CIDR Concepts

  • Network Address: The first IP address in a subnet, where all host bits are zero.
  • Broadcast Address: The last IP address in a subnet, where all host bits are one. Messages sent to this address reach all devices within that subnet.
  • Usable Host Range: All IP addresses between the network and broadcast address, excluding those two.
  • Subnet Mask: A 32-bit number that identifies the network portion of an IP address. In binary, all network bits are 1s, and all host bits are 0s. The CIDR prefix length is simply the count of the 1s in the subnet mask.

The Two Tables You Must Memorize

These two simple tables are the cornerstone of quick subnet calculations. Master them, and subnetting becomes intuitive.

Powers of Two (Host Bits to Hosts)

This table relates the number of host bits (n) to the total number of addresses (2^n) and usable hosts (2^n - 2).

Host Bits (n) | Total Addresses (2^n) | Usable Hosts (2^n - 2)
--------------|-----------------------|----------------------
1             | 2                     | 0 (not practical)
2             | 4                     | 2
3             | 8                     | 6
4             | 16                    | 14
5             | 32                    | 30
6             | 64                    | 62
7             | 128                   | 126
8             | 256                   | 254

To find the CIDR prefix from the number of host bits, subtract the host bits from 32. For example, 8 host bits means /24 (32-8=24).

Subnet Mask (CIDR Prefix to Decimal Mask)

This table directly maps the CIDR prefix length to the decimal value of the last non-255 octet in the subnet mask. Remember that /0 through /8 affect the first octet, /9 through /16 the second, /17 through /24 the third, and /25 through /32 the fourth. Most practical subnetting starts at /24 or smaller blocks.

CIDR Prefix | Last Octet Mask | Block Size
------------|-----------------|-----------
/24         | 0               | 256
/25         | 128             | 128
/26         | 192             | 64
/27         | 224             | 32
/28         | 240             | 16
/29         | 248             | 8
/30         | 252             | 4
/31         | 254             | 2 (point-to-point links, see RFC 3021)
/32         | 255             | 1 (single host route)

The "Block Size" here refers to the increment of network addresses for that particular mask. For a /26, subnets will increment by 64 (0, 64, 128, 192).

Subnetting a Network: A Step-by-Step Example

Let's work through a common scenario: you have a larger network block and need to divide it into smaller subnets to accommodate different departments or functions, each with specific host requirements.

Example: Subnetting 192.168.10.0/24 for 4 subnets

You are given the network 192.168.10.0/24 and need to create 4 subnets, each supporting approximately 50 hosts.

  1. Determine Host Requirements: Each subnet needs ~50 hosts. Look at the "Usable Hosts" column in the Powers of Two table. The smallest block size that can accommodate 50 usable hosts is 62 hosts, which corresponds to 6 host bits (2^6 = 64 total addresses).
  2. Calculate New CIDR Prefix: With 6 host bits, the new CIDR prefix is 32 - 6 = /26.
  3. Find the New Subnet Mask: From the Subnet Mask table, a /26 mask is 255.255.255.192. The block size (or magic number) is 64.
  4. List the Subnets: Start with the original network address and increment by the block size (64) in the last octet until you've exhausted the original /24 block (which ends at 255 in the last octet).
Original Network: 192.168.10.0/24 (Total addresses: 256)
Required hosts per subnet: ~50
→ Need 6 host bits (2^6 = 64 total addresses; 62 usable)
→ New prefix: /26 (32 - 6 = 26)
→ Subnet Mask: 255.255.255.192
→ Block Size (increment): 64

Subnets:
1.  Network Address:   192.168.10.0/26
    Host Range:        192.168.10.1 - 192.168.10.62
    Broadcast Address: 192.168.10.63

2.  Network Address:   192.168.10.64/26
    Host Range:        192.168.10.65 - 192.168.10.126
    Broadcast Address: 192.168.10.127

3.  Network Address:   192.168.10.128/26
    Host Range:        192.168.10.129 - 192.168.10.190
    Broadcast Address: 192.168.10.191

4.  Network Address:   192.168.10.192/26
    Host Range:        192.168.10.193 - 192.168.10.254
    Broadcast Address: 192.168.10.255

Each of these four subnets can indeed accommodate 62 usable hosts, satisfying the requirement.

VLSM: Variable Length Subnet Masking

Variable Length Subnet Masking (VLSM) is an extension of CIDR that allows you to use different subnet masks within the same major network block. This is crucial for optimizing IP address utilization and minimizing waste, especially in networks with varying host requirements (e.g., a large LAN segment vs. a point-to-point WAN link).

VLSM Design Principle: Largest First

When applying VLSM, always allocate the largest required subnets first. This approach simplifies the process and ensures that larger blocks don't consume address space that could otherwise be broken down into smaller, more specific subnets.

VLSM Worked Example

You have the parent network 10.0.0.0/16. You need to create the following subnets:

  • LAN A: 1000 hosts
  • LAN B: 500 hosts
  • LAN C: 200 hosts
  • WAN links: Two point-to-point links (2 hosts each)
  1. Determine CIDR Prefixes for Each Requirement:
    • 1000 hosts: Need 2^10 = 1024 total addresses (10 host bits). This is a /22 (32-10=22). Usable: 1022.
    • 500 hosts: Need 2^9 = 512 total addresses (9 host bits). This is a /23 (32-9=23). Usable: 510.
    • 200 hosts: Need 2^8 = 256 total addresses (8 host bits). This is a /24 (32-8=24). Usable: 254.
    • 2 hosts (point-to-point): Need 2^2 = 4 total addresses (2 host bits). This is a /30 (32-2=30). Usable: 2.
  2. Sort Requirements (Largest First):
    1. LAN A: 1000 hosts (/22)
    2. LAN B: 500 hosts (/23)
    3. LAN C: 200 hosts (/24)
    4. WAN Link 1: 2 hosts (/30)
    5. WAN Link 2: 2 hosts (/30)
  3. Allocate Subnets from 10.0.0.0/16:
    • LAN A (1000 hosts):
      • Network: 10.0.0.0/22
      • Subnet Mask: 255.255.252.0
      • Host Range: 10.0.0.1 - 10.0.3.254
      • Broadcast: 10.0.3.255
      • Next available block starts at 10.0.4.0 (increment by 4 in the 3rd octet for a /22)
    • LAN B (500 hosts):
      • Network: 10.0.4.0/23
      • Subnet Mask: 255.255.254.0
      • Host Range: 10.0.4.1 - 10.0.5.254
      • Broadcast: 10.0.5.255
      • Next available block starts at 10.0.6.0 (increment by 2 in the 3rd octet for a /23)
    • LAN C (200 hosts):
      • Network: 10.0.6.0/24
      • Subnet Mask: 255.255.255.0
      • Host Range: 10.0.6.1 - 10.0.6.254
      • Broadcast: 10.0.6.255
      • Next available block starts at 10.0.7.0 (increment by 1 in the 3rd octet for a /24)
    • WAN Link 1 (2 hosts):
      • Network: 10.0.7.0/30
      • Subnet Mask: 255.255.255.252
      • Host Range: 10.0.7.1 - 10.0.7.2
      • Broadcast: 10.0.7.3
      • Next available block starts at 10.0.7.4 (increment by 4 in the 4th octet for a /30)
    • WAN Link 2 (2 hosts):
      • Network: 10.0.7.4/30
      • Subnet Mask: 255.255.255.252
      • Host Range: 10.0.7.5 - 10.0.7.6
      • Broadcast: 10.0.7.7
      • Next available block starts at 10.0.7.8

This VLSM approach significantly reduces wasted IP addresses compared to using a single, larger mask (e.g., /22 for all subnets), which would have resulted in 768 wasted addresses just for the two smaller LANs and WAN links.

Troubleshooting and Common Pitfalls

Incorrect subnetting is a frequent source of network connectivity issues. Here are common problems and how to approach them:

  • Incorrect Subnet Mask: A device configured with the wrong subnet mask might believe hosts on its own subnet are on a remote subnet, sending traffic to its default gateway unnecessarily, or vice-versa. Always double-check the mask against the CIDR prefix.
  • Overlapping Subnets: This occurs when two or more subnets are assigned IP address ranges that include the same IP addresses. Routers cannot correctly forward traffic in such a scenario. VLSM allocation (largest first) helps prevent this. Use tools like ipcalc or online subnet calculators to verify.
  • Incorrect Gateway Configuration: The default gateway for a host must be an IP address within the host's own subnet. A common mistake is assigning the gateway an IP from a different subnet.
  • Broadcast/Network Address Assigned to Host: Attempting to assign the network address (all host bits 0) or broadcast address (all host bits 1) to a host device. These addresses are reserved and cannot be used by end devices. Most modern operating systems will reject such configurations.
  • Mismatch Between CIDR Prefix and Subnet Mask: Although they represent the same information, ensuring consistency in documentation and configuration is vital. For example, /24 means 255.255.255.0. Mixing these up can lead to miscalculations.
  • Forgetting -2 for Usable Hosts: Remember that the network and broadcast addresses are unusable for host devices. If you need 30 hosts, you can't use a /27 (32 total addresses), as that only leaves 30 usable hosts. If a device fails, it could be due to this edge case, so always factor in a buffer.

Back to the knowledge base · Ask the AI assistant