Network Mask Calculator

.nmc-container { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; color: #333; max-width: 800px; margin: 20px auto; padding: 25px; border: 1px solid #e1e4e8; border-radius: 12px; background-color: #ffffff; box-shadow: 0 4px 6px rgba(0,0,0,0.05); } .nmc-header { text-align: center; margin-bottom: 30px; } .nmc-header h2 { color: #2c3e50; font-size: 28px; margin-bottom: 10px; } .nmc-row { display: flex; gap: 20px; margin-bottom: 20px; flex-wrap: wrap; } .nmc-field { flex: 1; min-width: 200px; } .nmc-label { display: block; font-weight: 600; margin-bottom: 8px; color: #4a5568; } .nmc-input { width: 100%; padding: 12px; border: 2px solid #cbd5e0; border-radius: 6px; box-sizing: border-box; font-size: 16px; transition: border-color 0.2s; } .nmc-input:focus { outline: none; border-color: #4299e1; } .nmc-button { width: 100%; background-color: #3182ce; color: white; border: none; padding: 15px; border-radius: 6px; font-size: 18px; font-weight: 600; cursor: pointer; transition: background-color 0.2s; margin-bottom: 30px; } .nmc-button:hover { background-color: #2b6cb0; } .nmc-results { background-color: #f7fafc; padding: 20px; border-radius: 8px; display: none; border: 1px solid #edf2f7; } .nmc-result-item { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid #e2e8f0; } .nmc-result-item:last-child { border-bottom: none; } .nmc-res-label { font-weight: 600; color: #4a5568; } .nmc-res-value { font-family: monospace; color: #2d3748; font-size: 16px; } .nmc-article { margin-top: 40px; line-height: 1.6; color: #4a5568; } .nmc-article h3 { color: #2d3748; margin-top: 25px; } .nmc-article p { margin-bottom: 15px; } .nmc-article ul { margin-bottom: 15px; padding-left: 20px; } .nmc-error { color: #e53e3e; background: #fff5f5; padding: 10px; border-radius: 4px; margin-bottom: 20px; display: none; border: 1px solid #feb2b2; }

Network Mask & Subnet Calculator

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'; }

Leave a Comment