Subnetting is the practice of dividing a single physical network into multiple logical sub-networks (subnets). This process is critical for efficient IP address management, improving network performance, and enhancing security by isolating traffic between different departments or sections of an organization.
How the Subnet Calculator Works
This tool takes a standard IPv4 address and a CIDR (Classless Inter-Domain Routing) prefix to determine the boundaries of your network. Here is how the math works behind the scenes:
Network Address: Calculated by performing a bitwise AND operation between the IP address and the subnet mask. It represents the "start" of the network.
Broadcast Address: Calculated by taking the network address and setting all the host bits to 1. This address is used to send data to all devices in the subnet.
Usable Hosts: In most networks, the first address (Network) and the last address (Broadcast) cannot be assigned to devices. Therefore, the formula for usable hosts is 2(32 – CIDR) – 2.
Common Subnetting Example
Imagine you have the IP address 192.168.1.10 with a /24 mask. Here is what the breakdown looks like:
Metric
Value
IP Address
192.168.1.10
Subnet Mask
255.255.255.0
Network ID
192.168.1.0
Broadcast ID
192.168.1.255
Usable Hosts
254
Why Use Subnetting?
Large networks suffer from "broadcast storms" where too much administrative traffic slows down actual data transfer. By breaking a large Class B or Class A network into smaller segments, you limit the scope of broadcast traffic. It also allows network administrators to apply firewall rules between subnets, ensuring that a compromise in one segment doesn't automatically grant access to the entire infrastructure.
function calculateNetwork() {
var oct1 = parseInt(document.getElementById('oct1').value);
var oct2 = parseInt(document.getElementById('oct2').value);
var oct3 = parseInt(document.getElementById('oct3').value);
var oct4 = parseInt(document.getElementById('oct4').value);
var cidr = parseInt(document.getElementById('cidrInput').value);
// Validation
if (isNaN(oct1) || isNaN(oct2) || isNaN(oct3) || isNaN(oct4) ||
oct1 255 || oct2 255 ||
oct3 255 || oct4 255) {
alert("Please enter valid IP octets (0-255).");
return;
}
// Convert IP to 32-bit integer
var ipInt = ((oct1 <>> 0) | (oct2 << 16) | (oct3 < 0) {
maskInt = (0xffffffff <>> 0;
}
// Network Address
var netInt = (ipInt & maskInt) >>> 0;
// Wildcard Mask
var wildInt = (~maskInt) >>> 0;
// Broadcast Address
var broadInt = (netInt | wildInt) >>> 0;
// Convert Integer to IP Strings
var intToIp = function(i) {
return ((i >>> 24) & 0xFF) + "." + ((i >> 16) & 0xFF) + "." + ((i >> 8) & 0xFF) + "." + (i & 0xFF);
};
var networkAddr = intToIp(netInt);
var broadcastAddr = intToIp(broadInt);
var subnetMask = intToIp(maskInt);
var wildcardMask = intToIp(wildInt);
// Host Calculations
var totalHosts = Math.pow(2, (32 – cidr));
var usableHosts = (cidr >= 31) ? 0 : totalHosts – 2;
if (cidr === 31) usableHosts = 2; // Special case for /31 point-to-point
if (cidr === 32) usableHosts = 1; // Single host
var hostRange = "N/A";
if (cidr < 31) {
var firstHost = intToIp(netInt + 1);
var lastHost = intToIp(broadInt – 1);
hostRange = firstHost + " – " + lastHost;
} else if (cidr === 31) {
hostRange = intToIp(netInt) + " – " + intToIp(broadInt);
} else if (cidr === 32) {
hostRange = intToIp(netInt);
}
// Update UI
document.getElementById('resNetwork').innerText = networkAddr;
document.getElementById('resBroadcast').innerText = broadcastAddr;
document.getElementById('resRange').innerText = hostRange;
document.getElementById('resHosts').innerText = usableHosts.toLocaleString();
document.getElementById('resMask').innerText = subnetMask;
document.getElementById('resWildcard').innerText = wildcardMask;
document.getElementById('resCIDR').innerText = "/" + cidr;
document.getElementById('subnetResults').style.display = 'block';
}