An IP Netmask calculator is an essential tool for network administrators and IT professionals. It allows you to determine the boundaries of a network, the number of available host addresses, and identify the network and broadcast addresses for any given IPv4 address and CIDR prefix.
What is a Subnet Mask?
A subnet mask is a 32-bit number that masks an IP address and divides the IP address into network address and host address. It is used by the TCP/IP protocol to determine whether a host is on the local subnet or on a remote network.
CIDR Notation Explained
CIDR (Classless Inter-Domain Routing) notation is a compact way to represent an IP address and its associated routing prefix. For example, 192.168.1.0/24 represents the IP address and its subnet mask 255.255.255.0. The "/24" indicates that the first 24 bits of the address are the network portion.
Example Calculation
If you have an IP address 10.0.0.50 with a /26 mask (255.255.255.192):
Network Address: 10.0.0.0 (The start of the block)
Broadcast Address: 10.0.0.63 (The end of the block)
Usable Hosts: 10.0.0.1 to 10.0.0.62
Total Hosts: 64 (2^6)
Usable Hosts: 62 (Total – Network – Broadcast)
Why use this tool?
Manual binary math for subnetting is prone to errors. This calculator provides instant results for planning network topology, configuring routers, or troubleshooting connectivity issues. It supports all standard IPv4 CIDR ranges from /1 to /32.
function ipToInt(ip) {
var parts = ip.split('.');
if (parts.length !== 4) return null;
var res = 0;
for (var i = 0; i < 4; i++) {
var part = parseInt(parts[i]);
if (isNaN(part) || part 255) return null;
res = (res <>> 0;
}
function intToIp(int) {
return ((int >>> 24) & 0xFF) + '.' +
((int >>> 16) & 0xFF) + '.' +
((int >>> 8) & 0xFF) + '.' +
(int & 0xFF);
}
function getMaskFromCidr(cidr) {
return (0xFFFFFFFF <>> 0;
}
function calculateSubnet() {
var ipInput = document.getElementById("ipAddress").value.trim();
var cidr = parseInt(document.getElementById("netmask").value);
var errorDiv = document.getElementById("error-msg");
var resultDiv = document.getElementById("results");
errorDiv.style.display = "none";
resultDiv.style.display = "none";
var ip = ipToInt(ipInput);
if (ip === null) {
errorDiv.innerText = "Please enter a valid IPv4 address (e.g., 192.168.1.1).";
errorDiv.style.display = "block";
return;
}
var mask = getMaskFromCidr(cidr);
var network = (ip & mask) >>> 0;
var wildcard = (~mask) >>> 0;
var broadcast = (network | wildcard) >>> 0;
var totalHosts = Math.pow(2, 32 – cidr);
var usableHosts = cidr <= 30 ? totalHosts – 2 : (cidr === 31 ? 2 : 1);
var firstHost = (cidr <= 30) ? network + 1 : network;
var lastHost = (cidr <= 30) ? broadcast – 1 : broadcast;
// Fill results
document.getElementById("resNetwork").innerText = intToIp(network) + " /" + cidr;
document.getElementById("resBroadcast").innerText = intToIp(broadcast);
if (cidr <= 30) {
document.getElementById("resRange").innerText = intToIp(firstHost) + " – " + intToIp(lastHost);
} else if (cidr === 31) {
document.getElementById("resRange").innerText = intToIp(network) + " – " + intToIp(broadcast);
} else {
document.getElementById("resRange").innerText = intToIp(network) + " (Host Only)";
}
document.getElementById("resTotalHosts").innerText = totalHosts.toLocaleString();
document.getElementById("resUsableHosts").innerText = usableHosts >> 0).toString(2).padStart(32, '0');
var formattedBinary = binaryStr.match(/.{1,8}/g).join('.');
document.getElementById("resBinaryMask").innerText = formattedBinary;
resultDiv.style.display = "block";
}