Netmask Calculator

Advanced Netmask & Subnet Calculator

/32 (255.255.255.255 – Host) /31 (255.255.255.254 – Point-to-Point) /30 (255.255.255.252) /29 (255.255.255.248) /28 (255.255.255.240) /27 (255.255.255.224) /26 (255.255.255.192) /25 (255.255.255.128) /24 (255.255.255.0 – Class C) /23 (255.255.254.0) /22 (255.255.252.0) /21 (255.255.248.0) /20 (255.255.240.0) /19 (255.255.224.0) /18 (255.255.192.0) /17 (255.255.128.0) /16 (255.255.0.0 – Class B) /15 (255.254.0.0) /14 (255.252.0.0) /13 (255.248.0.0) /12 (255.240.0.0) /11 (255.224.0.0) /10 (255.192.0.0) /9 (255.128.0.0) /8 (255.0.0.0 – Class A) /7 (254.0.0.0) /6 (252.0.0.0) /5 (248.0.0.0) /4 (240.0.0.0) /3 (224.0.0.0) /2 (192.0.0.0) /1 (128.0.0.0) /0 (0.0.0.0)

Subnet Information

Network Address:
Broadcast Address:
Subnet Mask:
Wildcard Mask:
Usable IP Range:
Total Number of Hosts:
Usable Number of Hosts:
Please enter a valid IPv4 address (e.g., 192.168.1.1).
function calculateSubnet() { var ipStr = document.getElementById('ipAddress').value.trim(); var cidr = parseInt(document.getElementById('cidr').value); var resultsDiv = document.getElementById('subnetResults'); var errorDiv = document.getElementById('netError'); // Simple IP Regex Validation var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/; var match = ipStr.match(ipPattern); if (!match) { resultsDiv.style.display = 'none'; errorDiv.style.display = 'block'; return; } var octets = match.slice(1).map(Number); for (var i = 0; i < 4; i++) { if (octets[i] 255) { resultsDiv.style.display = 'none'; errorDiv.style.display = 'block'; return; } } errorDiv.style.display = 'none'; // Convert IP to 32-bit unsigned integer var ipLong = ((octets[0] <>> 0) + (octets[1] << 16) + (octets[2] < 0) { maskLong = (0xFFFFFFFF <>> 0; } // Network and Broadcast var networkLong = (ipLong & maskLong) >>> 0; var wildcardLong = (~maskLong) >>> 0; var broadcastLong = (networkLong | wildcardLong) >>> 0; // Helper to format long to IP string function longToIp(long) { return [ (long >>> 24) & 255, (long >>> 16) & 255, (long >>> 8) & 255, long & 255 ].join('.'); } // Calculations for Hosts var totalHosts = Math.pow(2, (32 – cidr)); var usableHosts = (cidr >= 31) ? 0 : totalHosts – 2; if (cidr === 32) usableHosts = 1; if (cidr === 31) usableHosts = 2; // Modern RFC 3021 usage var usableRange = "N/A"; if (cidr <= 30) { usableRange = longToIp(networkLong + 1) + " – " + longToIp(broadcastLong – 1); } else if (cidr === 31) { usableRange = longToIp(networkLong) + " – " + longToIp(broadcastLong); } else if (cidr === 32) { usableRange = longToIp(networkLong); } // Display Results document.getElementById('resNetwork').innerText = longToIp(networkLong) + " /" + cidr; document.getElementById('resBroadcast').innerText = longToIp(broadcastLong); document.getElementById('resMask').innerText = longToIp(maskLong); document.getElementById('resWildcard').innerText = longToIp(wildcardLong); document.getElementById('resRange').innerText = usableRange; document.getElementById('resTotalHosts').innerText = totalHosts.toLocaleString(); document.getElementById('resUsableHosts').innerText = usableHosts.toLocaleString(); resultsDiv.style.display = 'block'; }

Understanding IPv4 Subnetting and Netmasks

A Netmask Calculator is an essential tool for network administrators, IT students, and engineers. It simplifies the process of dividing a network into smaller, manageable sub-networks (subnets). By entering an IP address and a CIDR prefix, you can instantly determine critical network parameters like the broadcast address and usable IP range.

What is a Subnet Mask?

A subnet mask is a 32-bit number used to distinguish between the network portion and the host portion of an IP address. In binary, the mask consists of a sequence of 1s followed by 0s. The 1s represent the network, while the 0s represent the individual devices (hosts) on that network.

Common CIDR Notations and Their Masks

CIDR (Classless Inter-Domain Routing) notation is a shorthand way to represent a subnet mask. Instead of writing out 255.255.255.0, we write /24.

CIDR Subnet Mask Usable Hosts
/24 255.255.255.0 254
/26 255.255.255.192 62
/30 255.255.255.252 2

How the Calculation Works

To calculate a subnet manually, follow these steps:

  1. Convert to Binary: Convert the IP address and the Subnet Mask into binary format.
  2. AND Operation: Perform a bitwise AND operation between the IP and the Mask to find the Network Address.
  3. Wildcard Mask: Invert the Subnet Mask (change 1s to 0s and 0s to 1s).
  4. OR Operation: Perform a bitwise OR operation between the Network Address and the Wildcard Mask to find the Broadcast Address.
  5. Host Range: The usable IPs are all addresses between the Network Address and the Broadcast Address.

Example Calculation

If you have the IP address 192.168.1.10 with a /24 mask:

  • Subnet Mask: 255.255.255.0
  • Network ID: 192.168.1.0
  • Broadcast ID: 192.168.1.255
  • First Usable: 192.168.1.1
  • Last Usable: 192.168.1.254

Why Use a Subnet Calculator?

Manual subnetting is prone to human error, especially when dealing with non-standard masks (like /27 or /19). This calculator ensures 100% accuracy for route planning, firewall configuration, and VLAN management. It quickly provides the wildcard mask, which is frequently needed for Cisco ACL (Access Control List) configurations.

Leave a Comment