X Xerobit

Subnetting Guide — How to Calculate Subnet Masks and IP Ranges

Subnetting divides a network into smaller subnetworks. Here's how CIDR notation, subnet masks, and IP address ranges work — with calculation examples and a cheat sheet.

Mian Ali Khalid · · 8 min read
Use the tool
Subnet / CIDR Calculator
Calculate IPv4 subnets — network, broadcast, usable range, wildcard mask. Input CIDR (/24) or dotted mask (255.255.255.0). Binary visualization.
Open Subnet / CIDR Calculator →

Subnetting divides a large IP address block into smaller networks. You subnet when you need to organize a network, limit broadcast traffic, control routing, or allocate address ranges to teams, VLANs, or cloud VPCs.

Use the Subnet Calculator to calculate subnet masks, network addresses, broadcast addresses, and usable IP ranges from any CIDR notation.

IP addresses and binary

IPv4 addresses are 32 bits, written as four decimal octets: 192.168.1.1.

192       .168       .1         .1
11000000  .10101000  .00000001  .00000001

Every IPv4 address is a 32-bit binary number. The binary representation is what subnet masks operate on.

Subnet masks

A subnet mask defines which part of an IP address is the network portion and which is the host portion.

Subnet mask 255.255.255.0:

255.255.255.0
11111111.11111111.11111111.00000000
← Network (24 bits) → ← Host (8 bits) →

All the 1 bits in the mask identify the network portion. All the 0 bits identify the host portion.

With a 255.255.255.0 mask:

  • The network address is the IP address with all host bits set to 0
  • The broadcast address is the IP address with all host bits set to 1
  • Usable hosts are everything in between

Example: 192.168.1.0/24

IP address:   192.168.1.0   = 11000000.10101000.00000001.00000000
Subnet mask:  255.255.255.0 = 11111111.11111111.11111111.00000000
Network:      192.168.1.0   (host bits = 00000000)
Broadcast:    192.168.1.255 (host bits = 11111111)
Usable hosts: 192.168.1.1 to 192.168.1.254
Host count:   254 (2^8 - 2 = 254)

Subtract 2 because the network address and broadcast address are not usable.

CIDR notation

CIDR (Classless Inter-Domain Routing) notation appends a prefix length to the IP address: 192.168.1.0/24.

The /24 means “24 bits are the network portion” — equivalent to mask 255.255.255.0.

CIDRSubnet maskUsable hostsBlock size
/8255.0.0.016,777,214Class A
/16255.255.0.065,534Class B
/24255.255.255.0254Class C
/25255.255.255.128126Half of /24
/26255.255.255.19262Quarter of /24
/27255.255.255.22430
/28255.255.255.24014
/29255.255.255.2486
/30255.255.255.2522Point-to-point links
/31255.255.255.2542 (special)RFC 3021 point-to-point
/32255.255.255.2551Single host

Formula:

Usable hosts = 2^(32 - prefix) - 2

For /24: 2^(32-24) - 2 = 2^8 - 2 = 254 For /27: 2^(32-27) - 2 = 2^5 - 2 = 30

Subnetting a /24 network

You have 10.0.1.0/24 (254 usable hosts) and need to divide it into 4 equal subnets.

Step 1: Determine bits needed to create 4 subnets. 2^n ≥ 4n = 2 (borrow 2 bits from the host portion)

Step 2: New prefix length = 24 + 2 = /26

Step 3: Calculate the 4 subnets. Each /26 has a block size of 256/4 = 64:

SubnetNetworkFirst usableLast usableBroadcast
110.0.1.0/2610.0.1.110.0.1.6210.0.1.63
210.0.1.64/2610.0.1.6510.0.1.12610.0.1.127
310.0.1.128/2610.0.1.12910.0.1.19010.0.1.191
410.0.1.192/2610.0.1.19310.0.1.25410.0.1.255

Each /26 has 62 usable hosts.

Subnetting for specific host requirements

Scenario: You need a subnet with at least 50 hosts.

2^n - 2 ≥ 502^6 - 2 = 62 → n = 6 host bits → prefix = 32 - 6 = /26

Scenario: You need a subnet with at least 100 hosts.

2^n - 2 ≥ 1002^7 - 2 = 126 → n = 7 → prefix = /25

Scenario: Point-to-point link (exactly 2 hosts, one router interface on each end):

Use /30 for standard: 2 usable hosts. Or /31 (RFC 3021): treats both addresses as usable on point-to-point links — saves 2 addresses vs /30.

The subnet cheat sheet

Blocks that multiples of: 128 64 32 16 8 4 2 1

For any subnet, the block sizes follow powers of 2:

PrefixSubnet maskBlock sizeUsable hostsNetworks in /24
/25255.255.255.1281281262
/26255.255.255.19264624
/27255.255.255.22432308
/28255.255.255.240161416
/29255.255.255.2488632
/30255.255.255.2524264

Quick formula: The last octet of the broadcast address = network address’s last octet + block size - 1.

For 10.0.0.64/26 (block size 64): broadcast = 64 + 64 - 1 = 10.0.0.127

Cloud networking and VPCs

In AWS, Azure, and GCP, you create Virtual Private Clouds (VPCs) with CIDR blocks and divide them into subnets. Standard patterns:

AWS VPC example

VPC:          10.0.0.0/16    (65,534 usable IPs)
├── Public:   10.0.1.0/24    (254 IPs — internet-facing)
├── Private:  10.0.2.0/24    (254 IPs — app servers)
└── Database: 10.0.3.0/24    (254 IPs — RDS instances)

AWS reserves 5 IP addresses per subnet (not just 2): the network address, VPC router (.1), DNS (.2), reserved for future use (.3), and broadcast (.255). So a /24 has 251 usable IPs in AWS, not 254.

Multi-AZ pattern (3 availability zones)

VPC: 10.0.0.0/16
├── AZ-a public:  10.0.1.0/24
├── AZ-b public:  10.0.2.0/24
├── AZ-c public:  10.0.3.0/24
├── AZ-a private: 10.0.11.0/24
├── AZ-b private: 10.0.12.0/24
└── AZ-c private: 10.0.13.0/24

Matching subnet sizes across AZs makes scaling consistent. The /11 in the third octet for private subnets is a convention to visually separate public (single-digit) from private (double-digit) subnets.

IPv6 subnetting

IPv6 addresses are 128 bits, written as 8 groups of 4 hex digits: 2001:db8::/32.

A typical IPv6 allocation from an ISP is a /48. You can subnet it into /64 networks — each /64 has 2^64 ≈ 18 quintillion addresses. Standard practice: use /64 for every subnet (even if you only have 3 devices).

IPv6 prefixSubnets from /48Use
/481Typical ISP allocation
/56256 /56s from /48Smaller site allocation
/6465,536 /64s from /48Standard subnet size

Using the Subnet Calculator

The Subnet Calculator takes any IP address + prefix length and returns:

  • Network address
  • Broadcast address
  • Subnet mask (dotted decimal)
  • First and last usable host addresses
  • Total number of hosts
  • CIDR notation

It also supports VLSM (Variable Length Subnet Masking) — dividing a block into subnets of different sizes based on specific host requirements.


Related posts

Related tool

Subnet / CIDR Calculator

Calculate IPv4 subnets — network, broadcast, usable range, wildcard mask. Input CIDR (/24) or dotted mask (255.255.255.0). Binary visualization.

Written by Mian Ali Khalid. Part of the Dev Productivity pillar.