VLSM (Variable Length Subnet Masking) Calculator
Efficiently allocate IP address space by dividing a network into subnets of varying sizes based on your host requirements. Enter a base network and the number of hosts needed for each subnet.
Formula
Required Prefix Length:
prefix = 32 - ⌈log₂(hosts_required + 2)⌉
subnet_size = 2^(32 - prefix)
usable_hosts = subnet_size - 2
network_address = base_ip & subnet_mask
broadcast_address = network_address + subnet_size - 1
first_host = network_address + 1
last_host = broadcast_address - 1
subnet_mask = 0xFFFFFFFF << (32 - prefix)
wildcard_mask = ~subnet_mask
The +2 accounts for the network address and broadcast address which cannot be assigned to hosts. Subnets are sorted largest-to-smallest and allocated sequentially to minimize wasted address space.
Assumptions & References
- VLSM allocates subnets in descending order of host requirements (largest first) to minimize fragmentation and wasted address space.
- Each subnet requires at least 2 extra addresses: one for the network address and one for the broadcast address.
- Subnet sizes are always powers of 2 (e.g., /30 = 4 addresses, /29 = 8, /28 = 16, etc.).
- The minimum usable subnet is /30 (2 usable hosts). /31 and /32 are excluded as they are special-purpose (RFC 3021 and loopback).
- Each subnet is boundary-aligned: the network address must be a multiple of the subnet size.
- The base network address must be a valid network address for the given prefix (host bits must be zero).
- Supports IPv4 only. IPv6 uses a different subnetting model.
- RFC 950 – Internet Standard Subnetting Procedure.
- RFC 1009 – Requirements for Internet Gateways (VLSM support).
- RFC 1519 – Classless Inter-Domain Routing (CIDR).