Subnetting Calculator

.subnet-calc-container { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; max-width: 800px; margin: 20px auto; padding: 25px; border: 1px solid #e0e0e0; border-radius: 12px; background-color: #ffffff; box-shadow: 0 4px 6px rgba(0,0,0,0.05); } .subnet-calc-container h2 { color: #2c3e50; text-align: center; margin-bottom: 25px; font-size: 28px; } .input-row { display: flex; gap: 15px; margin-bottom: 20px; flex-wrap: wrap; } .input-group { flex: 1; min-width: 200px; } .input-group label { display: block; margin-bottom: 8px; font-weight: 600; color: #34495e; font-size: 14px; } .input-group input, .input-group select { width: 100%; padding: 12px; border: 1px solid #ccd1d9; border-radius: 6px; box-sizing: border-box; font-size: 16px; } .calc-btn { width: 100%; background-color: #3498db; color: white; padding: 15px; border: none; border-radius: 6px; font-size: 18px; font-weight: bold; cursor: pointer; transition: background 0.3s; margin-top: 10px; } .calc-btn:hover { background-color: #2980b9; } .results-section { margin-top: 30px; display: none; background: #f8f9fa; border-radius: 8px; padding: 20px; border: 1px solid #e9ecef; } .results-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; } .result-item { padding: 10px; border-bottom: 1px solid #dee2e6; } .result-label { font-weight: bold; color: #495057; display: block; font-size: 13px; text-transform: uppercase; } .result-value { font-family: monospace; color: #2c3e50; font-size: 16px; word-break: break-all; } .article-content { margin-top: 40px; line-height: 1.6; color: #333; } .article-content h3 { color: #2c3e50; margin-top: 25px; } .example-box { background: #fff3cd; padding: 15px; border-left: 5px solid #ffecb5; margin: 20px 0; }

IPv4 Subnet Calculator

/32 (Host) /31 /30 /29 /28 /27 /26 /25 /24 (Class C) /23 /22 /21 /20 /19 /18 /17 /16 (Class B) /15 /14 /13 /12 /11 /10 /9 /8 (Class A) /7 /6 /5 /4 /3 /2 /1
Network Address
Subnet Mask
Broadcast Address
Usable Host Range
Total Hosts
Usable Hosts
Wildcard Mask
CIDR Notation

Understanding Subnetting and IP Addressing

Subnetting is the practice of dividing a physical network into smaller, logical sub-networks. This process is essential for managing network traffic, enhancing security, and optimizing the utilization of limited IPv4 address space. By using a subnetting calculator, network engineers can quickly determine the boundaries of a network without performing complex binary arithmetic manually.

Key Subnetting Terms

  • IP Address: A 32-bit numerical label assigned to each device participating in a computer network that uses the Internet Protocol.
  • Subnet Mask: A 32-bit number that masks an IP address and divides the IP address into network address and host address parts.
  • CIDR (Classless Inter-Domain Routing): A method for allocating IP addresses and IP routing that replaces the older system based on classes (Class A, B, and C). It uses a "/" notation followed by the number of bits in the mask.
  • Network Address: The first address in a subnet, used to identify the network itself. It cannot be assigned to a host.
  • Broadcast Address: The last address in a subnet, used to communicate with all hosts on that subnet simultaneously.
Example Calculation:
If you have an IP of 192.168.1.10 with a /24 prefix:
– The Subnet Mask is 255.255.255.0.
– The Network ID is 192.168.1.0.
– The Broadcast is 192.168.1.255.
– You have 254 usable host addresses (192.168.1.1 to 192.168.1.254).

Why use a Subnet Calculator?

Manual subnetting involves converting decimal octets into 8-bit binary strings, applying logical AND operations with the mask, and converting back. This is prone to human error, especially when working with non-standard prefixes like /27 or /19. Our calculator automates this logic, providing instant results for network planning and troubleshooting.

function calculateSubnet() { var ipStr = document.getElementById('ip_address').value.trim(); var cidr = parseInt(document.getElementById('cidr_prefix').value); // Validate IP format var ipParts = ipStr.split('.'); if (ipParts.length !== 4) { alert("Please enter a valid IPv4 address (e.g., 192.168.1.1)"); return; } var ipBinary = 0; for (var i = 0; i < 4; i++) { var part = parseInt(ipParts[i]); if (isNaN(part) || part 255) { alert("Each IP octet must be between 0 and 255."); return; } ipBinary = (ipBinary <>> 0; // Calculate Mask var mask = 0; if (cidr > 0) { mask = (0xFFFFFFFF <>> 0; } var wildcard = (~mask) >>> 0; var network = (ipBinary & mask) >>> 0; var broadcast = (network | wildcard) >>> 0; // Total and Usable 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; // Convert back to dot-decimal function btoip(bin) { return [ (bin >>> 24) & 0xFF, (bin >>> 16) & 0xFF, (bin >>> 8) & 0xFF, bin & 0xFF ].join('.'); } var firstHost = (cidr <= 30) ? btoip(network + 1) : "N/A"; var lastHost = (cidr <= 30) ? btoip(broadcast – 1) : "N/A"; // Update UI document.getElementById('res_net_addr').innerText = btoip(network); document.getElementById('res_mask').innerText = btoip(mask); document.getElementById('res_broad_addr').innerText = btoip(broadcast); document.getElementById('res_wildcard').innerText = btoip(wildcard); document.getElementById('res_total_hosts').innerText = totalHosts.toLocaleString(); document.getElementById('res_usable_hosts').innerText = usableHosts.toLocaleString(); document.getElementById('res_cidr_note').innerText = ipStr + " /" + cidr; if (cidr <= 30) { document.getElementById('res_range').innerText = firstHost + " – " + lastHost; } else if (cidr === 31) { document.getElementById('res_range').innerText = btoip(network) + " – " + btoip(broadcast); } else { document.getElementById('res_range').innerText = btoip(network) + " (Single Host)"; } document.getElementById('results').style.display = 'block'; }

Leave a Comment