IPv4 VLSM subnet calculator

Split an IPv4 network into variable-sized subnets based on required host counts.

Enter the starting IPv4 network, its CIDR prefix, and the number of hosts needed in each subnet, for example 50, 20, 10. Results are sorted by descending subnet size. Each block reserves a network and broadcast address; /31 point-to-point links are not used.

Blocks are displayed from largest to smallest; equal-sized blocks retain input order. Remaining addresses do not account for other routing constraints.

Method and assumptions

Method version 1.0.0 · Updated

Plan subnets (VLSM)

Formula: Each block is the smallest power of two that fits the requested hosts plus two reserved addresses; aligned blocks are allocated largest first.

Enter the starting IPv4 network, its CIDR prefix, and the number of hosts needed in each subnet, for example 50, 20, 10. Results are sorted by descending subnet size. Each block reserves a network and broadcast address; /31 point-to-point links are not used.

address
IPv4 address
prefix
CIDR prefix length
hostRequirements
Hosts required per subnet (comma-separated)

IPv4 CIDR /0 through /32 and 1 to 64 host requirements. Each subnet reserves two addresses (network and broadcast) and uses an aligned power-of-two block; /31 is not used.

Calculate with code

These short examples use the same inputs and core calculation as this tool. Adapt validation and formatting to your application.

JavaScript
const hosts = [50, 20, 10];
const prefixFor = h => 32 - Math.ceil(Math.log2(h + 2));
console.log(hosts.map(prefixFor)); // /26, /27, /28 (allocate largest first)
TypeScript
const hosts: number[] = [50, 20, 10];
const prefixFor = (h: number): number => 32 - Math.ceil(Math.log2(h + 2));
console.log(hosts.map(prefixFor)); // /26, /27, /28
Python
import ipaddress
for hosts in (50, 20, 10):
    prefix = 32 - (hosts + 2 - 1).bit_length()
    print(prefix)  # /26, /27, /28; allocate largest first
Java
int[] hosts = {50,20,10};
for (int h : hosts) System.out.println(32 - (int)Math.ceil(Math.log(h+2)/Math.log(2))); // prefixes /26, /27, /28
C#
int[] hosts = [50,20,10];
foreach (var h in hosts) Console.WriteLine(32 - (int)Math.Ceiling(Math.Log2(h+2))); // /26, /27, /28

Learn about IP protocols