Subnet Calculator Cidr

.subnet-calculator-wrapper { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; max-width: 800px; margin: 20px auto; padding: 25px; border: 1px solid #e1e1e1; border-radius: 8px; background-color: #f9f9f9; color: #333; line-height: 1.6; } .subnet-calculator-wrapper h2 { margin-top: 0; color: #2c3e50; text-align: center; } .calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 25px; } .input-group { display: flex; flex-direction: column; } .input-group label { font-weight: 600; margin-bottom: 8px; font-size: 14px; } .input-group input, .input-group select { padding: 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 16px; } .calc-btn-container { text-align: center; margin-bottom: 30px; } .calc-btn { background-color: #0073aa; color: #fff; padding: 12px 30px; border: none; border-radius: 4px; cursor: pointer; font-size: 18px; font-weight: bold; transition: background-color 0.3s; } .calc-btn:hover { background-color: #005177; } .results-container { background-color: #fff; padding: 20px; border-radius: 6px; border: 1px solid #ddd; display: none; } .results-container h3 { margin-top: 0; border-bottom: 2px solid #0073aa; padding-bottom: 10px; font-size: 20px; } .result-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #eee; } .result-row:last-child { border-bottom: none; } .result-label { font-weight: 600; color: #555; } .result-value { font-family: "Courier New", Courier, monospace; font-weight: bold; color: #000; } .error-msg { color: #d93025; background: #f8d7da; padding: 10px; border-radius: 4px; margin-bottom: 15px; display: none; text-align: center; } @media (max-width: 600px) { .calc-grid { grid-template-columns: 1fr; } }

CIDR Subnet Calculator

Please enter a valid IPv4 address.
/32 (1 Host) /31 (2 Hosts) /30 (4 Hosts) /29 (8 Hosts) /28 (16 Hosts) /27 (32 Hosts) /26 (64 Hosts) /25 (128 Hosts) /24 (256 Hosts) /23 (512 Hosts) /22 (1024 Hosts) /21 (2048 Hosts) /20 (4096 Hosts) /19 (8192 Hosts) /18 (16384 Hosts) /17 (32768 Hosts) /16 (65536 Hosts) /15 (131072 Hosts) /14 (262144 Hosts) /13 (524288 Hosts) /12 (1048576 Hosts) /11 (2097152 Hosts) /10 (4194304 Hosts) /9 (8388608 Hosts) /8 (16777216 Hosts) /7 (33554432 Hosts) /6 (67108864 Hosts) /5 (134217728 Hosts) /4 (268435456 Hosts) /3 (536870912 Hosts) /2 (1073741824 Hosts) /1 (2147483648 Hosts) /0 (4294967296 Hosts)

Subnet Information

Network Address:
Broadcast Address:
Subnet Mask:
Wildcard Mask:
First Usable Host:
Last Usable Host:
Total Number of Hosts:
Usable Number of Hosts:
CIDR Notation:

Understanding CIDR and Subnetting

CIDR, which stands for Classless Inter-Domain Routing, is a method for allocating IP addresses and IP routing. It was introduced by the Internet Engineering Task Force in 1993 to replace the previous addressing architecture of Classful network design (Class A, B, and C networks).

How the CIDR Subnet Calculator Works

A subnet calculator takes an IP address and a netmask (CIDR prefix) and calculates the resulting network properties. This is essential for network administrators to determine how many devices can reside on a specific network and what the network boundaries are.

  • Network Address: The first address in the range, identifying the network itself.
  • Broadcast Address: The last address in the range, used to communicate with all hosts on the network.
  • Usable Host Range: The IP addresses that can be assigned to devices like computers, printers, and routers.
  • Subnet Mask: The dotted-decimal representation of the CIDR prefix (e.g., /24 is 255.255.255.0).

Common CIDR Examples

Here are some of the most common CIDR prefixes used in local and wide area networks:

CIDR Subnet Mask Total Hosts
/30 255.255.255.252 4
/24 255.255.255.0 256
/16 255.255.0.0 65,536
/8 255.0.0.0 16,777,216

Usable vs Total Hosts

In most standard IPv4 networking, the first address (Network) and the last address (Broadcast) cannot be assigned to hosts. Therefore, the number of usable hosts is typically (2 ^ host_bits) - 2. For example, in a /24 network, there are 256 total addresses, but only 254 are usable for actual devices.

function calculateSubnet() { var ipStr = document.getElementById("ipAddress").value.trim(); var cidr = parseInt(document.getElementById("cidrMask").value); var errorDiv = document.getElementById("errorMessage"); var resultsDiv = document.getElementById("results"); errorDiv.style.display = "none"; resultsDiv.style.display = "none"; // Validate IP Address format var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/; var match = ipStr.match(ipPattern); if (!match) { errorDiv.textContent = "Error: Invalid IP Address format."; errorDiv.style.display = "block"; return; } var ipParts = []; var ipInt = 0; for (var i = 1; i <= 4; i++) { var part = parseInt(match[i]); if (part 255) { errorDiv.textContent = "Error: IP segments must be between 0 and 255."; errorDiv.style.display = "block"; return; } ipParts.push(part); ipInt = (ipInt <>> 0; // Calculate Mask var maskInt = 0; if (cidr > 0) { maskInt = (0xFFFFFFFF <>> 0; } var wildcardInt = (~maskInt) >>> 0; var networkInt = (ipInt & maskInt) >>> 0; var broadcastInt = (networkInt | wildcardInt) >>> 0; // Host calculations var totalHosts = Math.pow(2, (32 – cidr)); var usableHosts = (cidr <= 30) ? totalHosts – 2 : (cidr === 31 ? 2 : 1); var firstHostInt = (cidr <= 30) ? networkInt + 1 : networkInt; var lastHostInt = (cidr >> 24) & 0xFF) + "." + ((int >>> 16) & 0xFF) + "." + ((int >>> 8) & 0xFF) + "." + (int & 0xFF); } document.getElementById("resNetwork").textContent = intToIp(networkInt); document.getElementById("resBroadcast").textContent = intToIp(broadcastInt); document.getElementById("resMask").textContent = intToIp(maskInt); document.getElementById("resWildcard").textContent = intToIp(wildcardInt); document.getElementById("resFirst").textContent = intToIp(firstHostInt); document.getElementById("resLast").textContent = intToIp(lastHostInt); document.getElementById("resTotal").textContent = totalHosts.toLocaleString(); document.getElementById("resUsable").textContent = usableHosts < 0 ? 0 : usableHosts.toLocaleString(); document.getElementById("resCidr").textContent = ipStr + " /" + cidr; resultsDiv.style.display = "block"; }

Leave a Comment