Skip to main content
Other

IP Subnet Calculator

Calculate IPv4 subnetting ranges, CIDR blocks, wildcard masks, usable IP ranges, and design optimized networks using the VLSM planner.

MD Abu Hanif Mia

Engineered & Verified by MD Abu Hanif Mia • Nexus Systems Engineering Team (NIST Constants & ISO 80000-2 Mathematical Standards)

Institutional Formula & Benchmark Verification • Last Verified: 2026-11-19

Formula at a Glance

IPv4 CIDR Subnet & Usable Host Formula

Verified Formula
Ntotal=232−p,Nhosts=232−p−2  (p≤30)N_{\text{total}} = 2^{32 - p}, \quad N_{\text{hosts}} = 2^{32 - p} - 2 \; (p \le 30)

Key Formula Variables:

pCIDR Prefix Length: Number of leading network bits (e.g. /24 = 255.255.255.0)
32 - pHost Bits: Remaining bits available for host addressing inside the subnet
-2Reserved Addresses: Excludes the Network ID address and Broadcast address
Calculation Methodology: 1. Subtract CIDR prefix p from 32 to get host bits. 2. Compute 2^(32-p) for total IPs. 3. Subtract 2 (network & broadcast) for usable host capacity (point-to-point /31 uses RFC 3021).
Try a 1-Click Scenario:
Continue Your Calculation Workflow

What to Calculate After IP Subnet Calculator

The Math Behind It

Calculations for this tool are based on the standard IPv4 CIDR Subnet & Usable Host Formula:

Ntotal=232−p,Nhosts=232−p−2  (p≤30)N_{\text{total}} = 2^{32 - p}, \quad N_{\text{hosts}} = 2^{32 - p} - 2 \; (p \le 30)
  • p = CIDR Prefix Length (Number of leading network bits (e.g. /24 = 255.255.255.0))
  • 32 - p = Host Bits (Remaining bits available for host addressing inside the subnet)
  • -2 = Reserved Addresses (Excludes the Network ID address and Broadcast address)

1. Subtract CIDR prefix p from 32 to get host bits. 2. Compute 2^(32-p) for total IPs. 3. Subtract 2 (network & broadcast) for usable host capacity (point-to-point /31 uses RFC 3021).

Quick Reference Matrix

IPv4 CIDR Subnet Mask & Usable Host Capacity Cheat Sheet

Interactive Presets

Quick networking reference converting CIDR prefixes (/30 through /16) into dotted-decimal subnet masks and usable host counts.

IPv4 CIDR Subnet Mask & Usable Host Capacity Cheat Sheet
CIDR PrefixSubnet MaskTotal IPv4 IPsUsable Hosts (2^(32-p)-2)Action
/30255.255.255.25242
/28255.255.255.2401614
/26255.255.255.1926462
/24255.255.255.0256254
/22255.255.252.01,0241,022
/16255.255.0.065,53665,534

Click any row to test these numbers in the interactive calculator above.

In the architecture of modern digital systems, internet communication is governed by the Internet Protocol (IP). For devices to communicate across a global scale or within localized local area networks (LANs), data packets must be routed to their destinations accurately.

As networks grow in complexity and scale, assigning a single massive block of IP addresses to a organization becomes inefficient. IP Subnetting is the primary engineering technique used to divide a single physical network into multiple smaller, logically isolated subnetworks.

This guide provides a comprehensive examination of IP subnetting, CIDR notation, binary arithmetic behind netmasks, network classes, and Variable Length Subnet Masking (VLSM) calculations.


1. The Anatomy of an IPv4 Address

An Internet Protocol version 4 (IPv4) address is a 32-bit binary number containing a sequence of 32 ones and zeros. For human readability, this 32-bit block is represented in dotted-decimal notation, consisting of four decimal numbers (each ranging from 0 to 255) separated by dots.

Each of these four sections is called an octet because it represents 8 bits (28=2562^8 = 256 possible values):

IP Address (Dotted-Decimal): 192.168.1.10\text{IP Address (Dotted-Decimal): } 192.168.1.10
IP Address (Binary): 11000000.10101000.00000001.00001010\text{IP Address (Binary): } 11000000.10101000.00000001.00001010

Every IP address is divided into two distinct components:

  1. Network Portion: Identifies the specific network to which the device belongs.
  2. Host Portion: Identifies the specific device (computer, printer, router interface) within that network.

The boundary between the network portion and host portion is defined by the Subnet Mask.


2. Subnet Masks and CIDR Notation

A Subnet Mask is a 32-bit helper mask where all network bits are set to 1 and all host bits are set to 0. By performing a bitwise logical AND operation between the IP address and the subnet mask, a router isolates the network address.

For example, using a standard Class C mask:

IP Address:   192.168.1.10   ->  11000000.10101000.00000001.00001010
Subnet Mask:  255.255.255.0  ->  11111111.11111111.11111111.00000000
------------------------------------------------------------------------
Network IP:   192.168.1.0    ->  11000000.10101000.00000001.00000000

Classless Inter-Domain Routing (CIDR)

Historically, IP addresses were bound to rigid subnet masks based on class structures. In 1993, CIDR (Classless Inter-Domain Routing) was introduced to replace classful addressing.

CIDR uses a slash / followed by the number of active network bits (ones) in the subnet mask. This is known as the Prefix Length:

  • 255.255.255.0 contains 24 ones, so it is written as /24.
  • 255.255.0.0 contains 16 ones, so it is written as /16.
  • 255.255.255.240 contains 28 ones, so it is written as /28.

3. Mathematical Derivations in Subnetting

Calculating subnet boundaries requires binary arithmetic. For any given prefix length NN:

1. Total IP Allocations

The total number of IP addresses contained in the block ($IP_{total}$) is:

IPtotal=232−NIP_{total} = 2^{32 - N}

2. Usable Host Capacity

In any subnet, two addresses are reserved for network infrastructure:

  • Network Address: The first address where all host bits are 0. Used to identify the subnet block in routing tables.
  • Broadcast Address: The last address where all host bits are 1. Used to send packets to all hosts on the subnet.

Thus, the number of assignable host addresses (HusableH_{usable}) is:

Husable=232−N−2H_{usable} = 2^{32 - N} - 2

Note: For point-to-point router links (/31 and /32), modern standards (RFC 3021) allow the omission of network/broadcast addresses, yielding 2 and 1 hosts respectively.

3. Wildcard Mask

A wildcard mask is the inverse of the subnet mask, calculated as:

Wildcard Mask=255.255.255.255−Subnet Mask\text{Wildcard Mask} = 255.255.255.255 - \text{Subnet Mask}

4. Classful Networking Structure

Before CIDR, the IPv4 space was partitioned into five classes based on the first octet values:

ClassRange (First Octet)Default MaskPurposeMax Hosts per Net
Class A$1 - 126$$255.0.0.0$ (/8)Large organizations$16,777,214$
Class B$128 - 191$$255.255.0.0$ (/16)Medium enterprises$65,534$
Class C$192 - 223$$255.255.255.0$ (/24)Small networks$254$
Class D$224 - 239$N/AMulticast groupsN/A
Class E$240 - 255$N/AScientific researchN/A

Note: The first octet value 127 is excluded from Class A as it is reserved for local loopback testing (e.g., 127.0.0.1).


5. Public vs. Private IP Addresses

To conserve the limited IPv4 address pool, the Internet Engineering Task Force (IETF) reserved specific blocks of addresses for internal, private network deployments (RFC 1918). These addresses are ignored by public internet routers.

1. RFC 1918 Private Ranges

  • 10.0.0.0 to 10.255.255.255 (/8 prefix)
  • 172.16.0.0 to 172.31.255.255 (/12 prefix)
  • 192.168.0.0 to 192.168.255.255 (/16 prefix)

2. APIPA (Automatic Private IP Addressing)

  • 169.254.0.0 to 169.254.255.255 (/16 prefix)
  • Used by operating systems to automatically self-configure a network connection when DHCP is unavailable.

6. Variable Length Subnet Masking (VLSM)

Variable Length Subnet Masking (VLSM) is an advanced routing technique where subnets within the same overall address block can have different sizes. This allows network administrators to allocate subnets tailored to the specific host needs of each department, minimizing address waste.

The VLSM Design Methodology:

  1. List Host Requirements: Write down the size requirements for all segments, including point-to-point router links (which require 2 hosts).
  2. Sort by Size: Sort the segments in descending order (largest segment to smallest segment). This is critical because placing smaller subnets first can fragment the address space.
  3. Allocate Blocks: For each segment:
    • Find the smallest block size (2k2^k) that can accommodate the required hosts plus the 2 reserved addresses.
    • Find the corresponding CIDR prefix ($32 - k$).
    • Assign the starting address, calculate the network, broadcast, and range.
    • Start the next segment immediately at the next available IP boundary.

7. Real-World Cloud VPC Design Example

Modern cloud architectures, such as Amazon Web Services (AWS) or Google Cloud Platform (GCP), rely on CIDR mapping to isolate environments.

Let's design a Virtual Private Cloud (VPC) network based on a 10.0.0.0/16 base range with the following segment needs:

  • Production App Subnet: 500 hosts
  • Staging App Subnet: 120 hosts
  • Database Subnet: 50 hosts
  • Public DMZ Subnet: 20 hosts

Applying the VLSM protocol:

  1. Production App (500 hosts): Needs block size of 512 (292^9). Suffix is $/23$.
    • Subnet Range: 10.0.0.0/23 (10.0.0.0 - 10.0.1.255)
  2. Staging App (120 hosts): Needs block size of 128 (272^7). Suffix is $/25$.
    • Subnet Range: 10.0.2.0/25 (10.0.2.0 - 10.0.2.127)
  3. Database (50 hosts): Needs block size of 64 (262^6). Suffix is $/26$.
    • Subnet Range: 10.0.2.128/26 (10.0.2.128 - 10.0.2.191)
  4. Public DMZ (20 hosts): Needs block size of 32 (252^5). Suffix is $/27$.
    • Subnet Range: 10.0.2.192/27 (10.0.2.192 - 10.0.2.223)

By utilizing VLSM, we efficiently packed all four networks within the base block while saving thousands of unused IP addresses for future scaling.

Frequently Asked Questions

What is the mathematical formula used by the IP Subnet Calculator?
The IP Subnet Calculator uses the IPv4 CIDR Subnet & Usable Host Formula: Total Addresses = 2^(32 - prefix) | Usable Hosts = 2^(32 - prefix) - 2. Where: p = CIDR Prefix Length (Number of leading network bits (e.g. /24 = 255.255.255.0)); 32 - p = Host Bits (Remaining bits available for host addressing inside the subnet); -2 = Reserved Addresses (Excludes the Network ID address and Broadcast address). 1. Subtract CIDR prefix p from 32 to get host bits. 2. Compute 2^(32-p) for total IPs. 3. Subtract 2 (network & broadcast) for usable host capacity (point-to-point /31 uses RFC 3021).
What is an IP subnet?
A subnet (short for subnetwork) is a logical subdivision of an IP network. Dividing a large network into smaller, distinct subnets improves routing efficiency, enhances security, and reduces broadcast traffic by isolating local network communications.
What does CIDR stand for?
CIDR stands for Classless Inter-Domain Routing. It is a method for allocating IP addresses and routing IP packets that replaced the older classful network architecture. CIDR uses prefix notation (e.g., /24) to denote the size of the network mask.
How do you calculate the number of usable hosts in a subnet?
The number of usable hosts is calculated using the formula 2^(32 - N) - 2, where N is the CIDR prefix length (subnet mask bits). We subtract 2 because the first address is reserved for the network address and the last address is reserved for the broadcast address.
What is the difference between public and private IP addresses?
Public IP addresses are globally unique and routable on the public internet. Private IP addresses (defined in RFC 1918) are reserved for local area networks (LANs) and are not routable on the internet, requiring Network Address Translation (NAT) to access external web resources.
What is the purpose of a broadcast address?
A broadcast address is a special network address used to transmit packets to all active devices on a specific subnet simultaneously. In IPv4, the broadcast address is the absolute last address in the subnet's range.
What is a wildcard mask?
A wildcard mask is the bitwise inverse of a subnet mask (calculated as ~subnet_mask). It is commonly used in Cisco routers, access control lists (ACLs), and routing protocols (like OSPF) to specify which bits of an IP address should be matched.
What is VLSM (Variable Length Subnet Masking)?
VLSM allows network designers to partition an IP address space into multiple subnets of varying sizes based on the host requirements of each segment. This avoids the waste of IP addresses that occurs with Fixed Length Subnet Masking (FLSM).
What is the APIPA address range?
APIPA (Automatic Private IP Addressing) uses the IP address block 169.254.0.0/16. Operating systems automatically assign an address from this range to a network interface when a DHCP server is unavailable and no static IP is configured.
Why is the loopback address 127.0.0.1 used?
The IP range 127.0.0.0/8 is reserved for loopback operations. The address 127.0.0.1 (often referred to as 'localhost') allows a computer to send network traffic to itself, which is critical for local testing, diagnostics, and running local services.
How does IPv6 subnetting differ from IPv4 subnetting?
IPv6 uses 128-bit addresses (compared to IPv4's 32-bit addresses), meaning it has an virtually inexhaustible address pool. IPv6 subnets are usually standardized around a /64 prefix length for local segments, and they do not use traditional broadcast addresses, relying instead on multicast.

Community Discussions & Real Scenarios

Ask specific questions, compare edge cases, and get advice from people calculating the same scenario.