IPv4 Subnet Calculator
Calculate IPv4 subnets, CIDR notation, and network ranges
IPv4 Subnet Calculator
Calculate IPv4 subnets, CIDR notation, and network ranges
About IPv4 Subnet Calculator
Calculate IPv4 subnets, CIDR notation, network addresses, broadcast addresses, and available host ranges. This comprehensive subnet calculator helps network administrators plan IP address allocations and understand network segmentation.
- Calculate subnet masks and CIDR notation
- Determine network and broadcast addresses
- Find available host ranges
- Support for variable length subnet masking (VLSM)
- Network planning and documentation tools
How to Use IPv4 Subnet Calculator
- Enter IP Address - Input any valid IPv4 address (e.g., 192.168.1.1)
- Specify Subnet - Enter subnet mask or CIDR prefix (e.g., /24 or 255.255.255.0)
- Calculate - Get detailed subnet information including network range
- View Results - See network address, broadcast address, and host range
Advertisement
Frequently Asked Questions
What is subnet masking?
Subnet masking is a technique that divides a network into smaller subnetworks. It uses a subnet mask to determine which portion of an IP address identifies the network and which identifies the host.
What is CIDR notation?
CIDR (Classless Inter-Domain Routing) notation uses a slash followed by a number to indicate the network prefix length. For example, /24 means the first 24 bits are the network portion.
How do I calculate the number of hosts?
The number of available hosts is 2^(host bits) - 2. The -2 accounts for the network address (first) and broadcast address (last), which cannot be assigned to hosts.
What are network and broadcast addresses?
The network address identifies the subnet itself (all host bits are 0), while the broadcast address is used to send messages to all hosts in the subnet (all host bits are 1).
What is Variable Length Subnet Masking (VLSM)?
VLSM allows using different subnet mask lengths within the same network, enabling more efficient IP address allocation by creating subnets of various sizes based on requirements.
Common Use Cases
- Network planning and design
- IP address allocation schemes
- Router and switch configuration
- VLSM implementation
- Network troubleshooting
- Security zone segmentation
- DHCP scope planning
- Documentation and inventory
Sponsored Content
Technical Details
IPv4 Address Structure:
- 32-bit Address: Divided into network and host portions
- Dotted Decimal: Four octets separated by periods
- Subnet Mask: Binary pattern defining network/host boundary
- CIDR Prefix: Number of network bits (/8 to /30 for subnets)
- Host Calculation: 2^(32 - prefix length) - 2 usable addresses
Common Subnet Reference
| CIDR | Subnet Mask | Hosts | Subnets |
|---|---|---|---|
| /8 | 255.0.0.0 | 16,777,214 | 256 |
| /16 | 255.255.0.0 | 65,534 | 65,536 |
| /24 | 255.255.255.0 | 254 | 16,777,216 |
| /25 | 255.255.255.128 | 126 | 33,554,432 |
| /26 | 255.255.255.192 | 62 | 67,108,864 |
| /27 | 255.255.255.224 | 30 | 134,217,728 |
| /28 | 255.255.255.240 | 14 | 268,435,456 |
| /30 | 255.255.255.252 | 2 | 1,073,741,824 |
Programming Examples
Python:
import ipaddress
def calculate_subnet(ip_with_prefix):
network = ipaddress.IPv4Network(ip_with_prefix, strict=False)
return {
'network_address': str(network.network_address),
'broadcast_address': str(network.broadcast_address),
'subnet_mask': str(network.netmask),
'prefix_length': network.prefixlen,
'num_hosts': network.num_addresses - 2,
'host_range': f"{network.network_address + 1} - {network.broadcast_address - 1}"
}
# Example usage
result = calculate_subnet("192.168.1.100/24")
print(f"Network: {result['network_address']}")
print(f"Broadcast: {result['broadcast_address']}")
print(f"Hosts: {result['num_hosts']}")
JavaScript:
function calculateSubnet(ip, prefixLength) {
const ipNum = ipToNumber(ip);
const mask = (0xFFFFFFFF << (32 - prefixLength)) >>> 0;
const networkAddr = ipNum & mask;
const broadcastAddr = networkAddr | (0xFFFFFFFF >>> prefixLength);
const numHosts = Math.pow(2, 32 - prefixLength) - 2;
return {
networkAddress: numberToIp(networkAddr),
broadcastAddress: numberToIp(broadcastAddr),
subnetMask: numberToIp(mask),
numHosts: numHosts,
firstHost: numberToIp(networkAddr + 1),
lastHost: numberToIp(broadcastAddr - 1)
};
}
function ipToNumber(ip) {
return ip.split('.').reduce((acc, octet) => (acc << 8) + parseInt(octet), 0) >>> 0;
}
function numberToIp(num) {
return [(num >>> 24) & 255, (num >>> 16) & 255, (num >>> 8) & 255, num & 255].join('.');
}
Advertisement
