How to Calculate Subnet Masks

March 22, 2026 · 10 min read

Subnetting is one of those networking topics that seems intimidating until you understand the binary math behind it. Whether you're studying for the CCNA, configuring a VPC in AWS, or just trying to figure out why two devices can't talk to each other — understanding subnet masks is essential.

This guide teaches you to calculate subnet masks by hand, explains CIDR notation, and gives you the formulas to quickly determine network addresses, broadcast addresses, and host ranges.

What Is a Subnet Mask?

A subnet mask tells a device which part of an IP address identifies the network and which part identifies the host. It's a 32-bit number, just like an IPv4 address, written in the same dotted-decimal format.

IP Address: 192.168.1.100 Subnet Mask: 255.255.255.0 ─────────── ─ Network Host

The subnet mask works like a stencil: where the mask has 1 bits, the IP address bits belong to the network portion. Where the mask has 0 bits, the IP address bits belong to the host portion.

CIDR Notation

Instead of writing out the full subnet mask, CIDR (Classless Inter-Domain Routing) notation uses a slash followed by the number of network bits:

CIDR Subnet Mask Binary Usable Hosts
/8 255.0.0.0 11111111.00000000.00000000.00000000 16,777,214
/16 255.255.0.0 11111111.11111111.00000000.00000000 65,534
/24 255.255.255.0 11111111.11111111.11111111.00000000 254
/25 255.255.255.128 11111111.11111111.11111111.10000000 126
/26 255.255.255.192 11111111.11111111.11111111.11000000 62
/27 255.255.255.224 11111111.11111111.11111111.11100000 30
/28 255.255.255.240 11111111.11111111.11111111.11110000 14
/30 255.255.255.252 11111111.11111111.11111111.11111100 2
/32 255.255.255.255 11111111.11111111.11111111.11111111 1

The Key Formulas

Three formulas let you calculate everything you need:

Total addresses = 2^(32 - CIDR prefix) Usable hosts = 2^(32 - CIDR prefix) - 2 Number of subnets = 2^(CIDR prefix - original prefix)

The - 2 in the usable hosts formula accounts for the network address (all host bits = 0) and broadcast address (all host bits = 1), which can't be assigned to devices.

Step-by-Step: Calculate Network and Broadcast Addresses

Let's work through 192.168.1.100/26:

Step 1: Convert to Binary

IP: 192.168.1.100 11000000.10101000.00000001.01100100 Mask: /26 = 255.255.255.192 11111111.11111111.11111111.11000000 ────── Host bits (6 bits)

Step 2: Find the Network Address (AND operation)

Perform a bitwise AND between the IP and the mask. This zeros out the host bits:

IP: 11000000.10101000.00000001.01100100 Mask: 11111111.11111111.11111111.11000000 ─────────────────────────────────── Network: 11000000.10101000.00000001.01000000 = 192.168.1.64

Step 3: Find the Broadcast Address

Set all host bits to 1:

Network: 11000000.10101000.00000001.01000000 Set host bits to 1: 11000000.10101000.00000001.01111111 = 192.168.1.127

Step 4: Determine the Host Range

Network address: 192.168.1.64 (not assignable) First usable host: 192.168.1.65 Last usable host: 192.168.1.126 Broadcast address: 192.168.1.127 (not assignable) Usable hosts: 2^6 - 2 = 62

The Quick Method (No Binary Needed)

For common subnets, you can skip binary entirely using the block size method:

  1. Find the block size: 256 - subnet mask octet value
  2. The network address is the nearest multiple of the block size below the IP
  3. The broadcast address is network address + block size - 1

For 192.168.1.100/26:

Block size = 256 - 192 = 64 Multiples of 64: 0, 64, 128, 192... 100 falls between 64 and 128 Network: 192.168.1.64 Broadcast: 192.168.1.64 + 64 - 1 = 192.168.1.127 Host range: .65 to .126

Common Subnetting Scenarios

Splitting a /24 into smaller subnets

You have 10.0.0.0/24 and need 4 equal subnets:

Need 4 subnets → borrow 2 bits (2^2 = 4) New prefix: /24 + 2 = /26 Each subnet: 64 addresses (62 usable hosts) Subnet 1: 10.0.0.0/26 → hosts .1 to .62 Subnet 2: 10.0.0.64/26 → hosts .65 to .126 Subnet 3: 10.0.0.128/26 → hosts .129 to .190 Subnet 4: 10.0.0.192/26 → hosts .193 to .254

Cloud VPC subnetting (AWS/GCP/Azure)

Cloud providers typically recommend:

# Typical AWS VPC layout VPC: 10.0.0.0/16 (65,534 IPs) ├── Public-AZ1: 10.0.1.0/24 (254 IPs) ├── Public-AZ2: 10.0.2.0/24 (254 IPs) ├── Private-AZ1: 10.0.10.0/24 (254 IPs) ├── Private-AZ2: 10.0.11.0/24 (254 IPs) ├── DB-AZ1: 10.0.20.0/24 (254 IPs) └── DB-AZ2: 10.0.21.0/24 (254 IPs)

Subnet Mask Cheat Sheet

CIDR Mask Block Size Hosts Use Case
/30 255.255.255.252 4 2 Point-to-point links
/28 255.255.255.240 16 14 Small office, AWS minimum
/27 255.255.255.224 32 30 Department LAN
/26 255.255.255.192 64 62 Medium office
/25 255.255.255.128 128 126 Large department
/24 255.255.255.0 256 254 Standard LAN, cloud subnet
/16 255.255.0.0 65,536 65,534 Cloud VPC, campus network

Subnetting with Python

Python's ipaddress module makes subnetting trivial:

import ipaddress # Parse a network network = ipaddress.ip_network('192.168.1.0/26', strict=False) print(f"Network: {network.network_address}") # 192.168.1.0 print(f"Broadcast: {network.broadcast_address}") # 192.168.1.63 print(f"Mask: {network.netmask}") # 255.255.255.192 print(f"Hosts: {network.num_addresses - 2}") # 62 print(f"First host: {list(network.hosts())[0]}") # 192.168.1.1 print(f"Last host: {list(network.hosts())[-1]}") # 192.168.1.62 # Check if an IP is in a subnet ip = ipaddress.ip_address('192.168.1.50') print(f"{ip} in {network}? {ip in network}") # True # Split into smaller subnets for subnet in network.subnets(prefixlen_diff=2): print(f" {subnet} → {subnet.num_addresses - 2} hosts")

JavaScript Subnetting

function subnetInfo(ip, cidr) { const ipNum = ip.split('.').reduce((acc, oct) => (acc << 8) + parseInt(oct), 0) >>> 0; const mask = (~0 << (32 - cidr)) >>> 0; const network = (ipNum & mask) >>> 0; const broadcast = (network | ~mask) >>> 0; const toIP = n => [(n>>>24)&255, (n>>>16)&255, (n>>>8)&255, n&255].join('.'); return { network: toIP(network), broadcast: toIP(broadcast), firstHost: toIP(network + 1), lastHost: toIP(broadcast - 1), mask: toIP(mask), hosts: Math.pow(2, 32 - cidr) - 2 }; } console.log(subnetInfo('192.168.1.100', 26)); // { network: '192.168.1.64', broadcast: '192.168.1.127', // firstHost: '192.168.1.65', lastHost: '192.168.1.126', // mask: '255.255.255.192', hosts: 62 }
Bottom line: Subnetting boils down to one concept: how many bits belong to the network vs. the host. Use the block-size shortcut for quick mental math, the binary method for exam-style precision, or Python/JavaScript for automation. For instant results, use the calculator below.
Calculate subnets instantly
Enter any IP and CIDR prefix — get network address, broadcast, host range, and more.
Open Subnet Calculator

Related Reading

Get New Tools in Your Inbox

We ship new free tools weekly. No spam, unsubscribe anytime.