Calculate network details, usable host ranges, and broadcast addresses for any IPv4 address.
Subnet Mask:
Network Address:
Broadcast Address:
Usable Host Range:
Total Usable Hosts:
Wildcard Mask:
CIDR Notation:
What is a Network Mask?
A Network Mask (or subnet mask) is a 32-bit number used in IPv4 networking to divide an IP address into two parts: the network address and the host address. It acts as a filter that tells routers and devices which portion of the IP address belongs to the local network and which portion identifies specific devices (hosts) on that network.
How CIDR Notation Works
CIDR (Classless Inter-Domain Routing) notation is a shorthand way to represent a subnet mask. Instead of writing four octets like 255.255.255.0, we write a forward slash followed by the number of "1" bits in the binary mask. For example:
/24 is equivalent to 255.255.255.0 (24 ones)
/16 is equivalent to 255.255.0.0 (16 ones)
/8 is equivalent to 255.0.0.0 (8 ones)
Calculating Usable Hosts
To find the number of usable hosts on a network, we use the formula 2(32 – n) – 2, where 'n' is the CIDR prefix. We subtract 2 because the first address is the Network Address and the last address is the Broadcast Address, neither of which can be assigned to a specific device.
Network Calculation Example
Suppose you have the IP 10.0.0.5 with a /28 mask:
Subnet Mask: 255.255.255.240
Network Address: 10.0.0.0
Broadcast: 10.0.0.15
Usable Hosts: 10.0.0.1 through 10.0.0.14 (14 total)
function ipToInt(ip) {
var parts = ip.split('.');
if (parts.length !== 4) return null;
var res = 0;
for (var i = 0; i < 4; i++) {
var octet = parseInt(parts[i]);
if (isNaN(octet) || octet 255) return null;
res = (res <>> 0;
}
function intToIp(int) {
return ((int >>> 24) & 0xFF) + '.' +
((int >>> 16) & 0xFF) + '.' +
((int >>> 8) & 0xFF) + '.' +
(int & 0xFF);
}
function calculateSubnet() {
var ipInput = document.getElementById('ipAddr').value.trim();
var cidrInput = parseInt(document.getElementById('cidrVal').value);
var errorDiv = document.getElementById('nmcError');
var resultsDiv = document.getElementById('nmcResults');
errorDiv.style.display = 'none';
resultsDiv.style.display = 'none';
var ipInt = ipToInt(ipInput);
if (ipInt === null) {
errorDiv.innerHTML = "Error: Please enter a valid IPv4 address (e.g., 192.168.1.1).";
errorDiv.style.display = 'block';
return;
}
if (isNaN(cidrInput) || cidrInput 32) {
errorDiv.innerHTML = "Error: CIDR prefix must be a number between 0 and 32.";
errorDiv.style.display = 'block';
return;
}
// Calculate Mask
var mask = 0;
if (cidrInput > 0) {
mask = (0xFFFFFFFF <>> 0;
}
var wildcard = (~mask) >>> 0;
var network = (ipInt & mask) >>> 0;
var broadcast = (network | wildcard) >>> 0;
var usableHosts = 0;
var rangeText = "N/A";
if (cidrInput === 32) {
usableHosts = 1;
rangeText = intToIp(network);
} else if (cidrInput === 31) {
usableHosts = 2;
rangeText = intToIp(network) + " – " + intToIp(broadcast);
} else {
usableHosts = Math.pow(2, 32 – cidrInput) – 2;
var firstHost = (network + 1) >>> 0;
var lastHost = (broadcast – 1) >>> 0;
rangeText = intToIp(firstHost) + " – " + intToIp(lastHost);
}
document.getElementById('resMask').innerText = intToIp(mask);
document.getElementById('resNet').innerText = intToIp(network);
document.getElementById('resBroadcast').innerText = intToIp(broadcast);
document.getElementById('resRange').innerText = rangeText;
document.getElementById('resHosts').innerText = usableHosts.toLocaleString();
document.getElementById('resWildcard').innerText = intToIp(wildcard);
document.getElementById('resCidr').innerText = ipInput + " /" + cidrInput;
resultsDiv.style.display = 'block';
}