IP Subnetting is the practice of dividing a single physical network into two or more logical sub-networks (subnets). This process is vital for managing IP addresses efficiently and improving network performance and security. By breaking a large network into smaller segments, you reduce broadcast traffic and can apply specific security policies to different departments or areas of your organization.
How to Calculate a Subnet
To calculate a subnet, you must perform a bitwise AND operation between the IP address and the Subnet Mask. This determines the Network Address. The Broadcast Address is calculated by setting all host bits in the network to 1. The range between the Network address and Broadcast address (excluding those two) provides the Usable Host Addresses.
CIDR Notation Explained
CIDR (Classless Inter-Domain Routing) notation simplifies the representation of subnet masks. For example, instead of writing 255.255.255.0, we use /24. The number 24 represents the number of leading '1' bits in the subnet mask. Our calculator supports masks from /8 (Class A) all the way down to /32 (Single Host).
Example Calculation
If you have an IP address of 192.168.1.10 with a /24 mask:
Subnet Mask: 255.255.255.0
Network Address: 192.168.1.0
Broadcast Address: 192.168.1.255
Usable Range: 192.168.1.1 to 192.168.1.254
Total Hosts: 254
function numToDot(n) {
return [
(n >>> 24) & 0xFF,
(n >>> 16) & 0xFF,
(n >>> 8) & 0xFF,
n & 0xFF
].join('.');
}
function dotToNum(dot) {
var parts = dot.split('.');
if (parts.length !== 4) return null;
var res = 0;
for (var i = 0; i < 4; i++) {
var p = parseInt(parts[i]);
if (isNaN(p) || p 255) return null;
res = (res <>> 0;
}
function numToBin(n) {
var bin = (n >>> 0).toString(2);
while (bin.length < 32) bin = '0' + bin;
return bin.match(/.{1,8}/g).join('.');
}
function calculateSubnet() {
var ipStr = document.getElementById('ipAddress').value.trim();
var cidr = parseInt(document.getElementById('cidrMask').value);
var errorDiv = document.getElementById('errorMessage');
var resultsDiv = document.getElementById('results');
var ipNum = dotToNum(ipStr);
if (ipNum === null) {
errorDiv.style.display = 'block';
resultsDiv.style.display = 'none';
return;
}
errorDiv.style.display = 'none';
resultsDiv.style.display = 'block';
var maskNum = (0xFFFFFFFF <>> 0;
if (cidr === 0) maskNum = 0; // handle /0 if needed, though dropdown starts at /8
var wildcardNum = (~maskNum) >>> 0;
var networkNum = (ipNum & maskNum) >>> 0;
var broadcastNum = (networkNum | wildcardNum) >>> 0;
var hostCount = 0;
var rangeStr = "";
if (cidr === 32) {
hostCount = 1;
rangeStr = numToDot(networkNum);
} else if (cidr === 31) {
hostCount = 2;
rangeStr = numToDot(networkNum) + " – " + numToDot(broadcastNum);
} else {
hostCount = Math.pow(2, (32 – cidr)) – 2;
rangeStr = numToDot(networkNum + 1) + " – " + numToDot(broadcastNum – 1);
}
document.getElementById('resNetwork').innerText = numToDot(networkNum);
document.getElementById('resBroadcast').innerText = numToDot(broadcastNum);
document.getElementById('resRange').innerText = rangeStr;
document.getElementById('resHosts').innerText = hostCount.toLocaleString();
document.getElementById('resMask').innerText = numToDot(maskNum);
document.getElementById('resWildcard').innerText = numToDot(wildcardNum);
document.getElementById('resBinary').innerText = numToBin(ipNum);
document.getElementById('resCIDR').innerText = "/" + cidr;
}