Network Tools

Subnet Calculator

Calculate CIDR subnet details like network, broadcast and host count.

/
Quick Select:
🧮

Enter IP address and CIDR to calculate subnet info

What is Subnet Calculator?

Subnet calculator computes network information from an IP address and subnet mask, including network address, broadcast address, and host range.

Calculated Information

  • Network address
  • Broadcast address
  • First and last usable host
  • Number of hosts
  • CIDR notation

Use Cases

  • Network planning
  • IP address allocation
  • Network troubleshooting

Takes one IPv4 address and a prefix length between 0 and 32, then derives the network address, broadcast address, dotted mask, wildcard mask and usable host range from 32-bit bitwise arithmetic in the browser. Use it to place a host inside the right /26 block, size a VLAN, or check the numbers quoted in a ticket.

Mask, wildcard, and where the two boundaries land

An IPv4 address is one 32-bit integer, so the whole calculation is three bitwise steps with no lookup table. The mask is built as 0xFFFFFFFF << (32 - cidr) and the wildcard is its complement, which is why /26 pairs 255.255.255.192 with 0.0.0.63 rather than 0.0.0.64. The network address is ip & mask, the broadcast is network | wildcard, and the binary panel prints address, mask and network in dot-separated octets so the cut point is visible: 192.168.1.100 is 11000000.10101000.00000001.01100100, the mask keeps the first 26 bits, the low 6 bits go to zero, and the network becomes 192.168.1.64. The host range is then network plus one through broadcast minus one.

/31 and /32 drop the minus-two rule

From /1 to /30 the usable count is 2^(32 - cidr) minus 2, because the all-zero host part names the subnet and the all-ones host part is the directed broadcast. Both of those drop away at the small end. At /31 the tool reports 2 usable hosts and lets the network address double as the first host while the broadcast serves as the last; that is the RFC 3021 reading of a point-to-point link, where each end needs an address and no broadcast is ever sent. At /32 the total of 1 stays 1, so the address is its own network, its own broadcast, its first host and its last: the host route a firewall rule or a monitoring probe expects for a single permitted IP. A /30 still reports the ordinary 4 addresses and 2 usable.

What this calculator will not answer

It maps exactly one prefix, so neighbouring planning jobs stay out of scope. There is no VLSM: entering 10.0.0.0/16 does not propose the /20s inside it, and the ten preset buttons only set the prefix, never the address, so they cannot walk you to the next block. Start-and-end addresses belong to the range-to-CIDR tool instead. Address classification is a fixed octet table: 10/8, 172.16/12, 192.168/16, 127/8, 169.254/16, 224 to 239 multicast, 240 and above reserved, everything else public. Hence 100.64.0.0/10 carrier-grade NAT and 192.0.2.0/24 documentation space both read as public, and 127.0.0.1 reads as class unknown because the class A branch stops at 126. IPv6 input never reaches the arithmetic.

Worked example

Placing 192.168.1.100 in its /26 block

Input
192.168.1.100 with prefix 26
Output
network 192.168.1.64 · broadcast 192.168.1.127 · mask 255.255.255.192 · wildcard 0.0.0.63 · hosts 192.168.1.65–192.168.1.126 · 64 addresses, 62 usable

The fourth octet 100 is 01100100; a /26 mask zeroes the low six bits, so the block starts at .64 and ends at .127. Both boundary addresses are excluded from the 64-address total, which is why 62 is the number to quote for a VLAN of that size.

Limits and pitfalls

  • A prefix of 0 passes the 0–32 check but computes badly: JavaScript masks the shift count, so << 32 behaves like << 0, the mask prints 255.255.255.255 and the host range reads 192.168.1.101 – 192.168.1.99 with the first value above the last.
  • Octets may not carry leading zeros, because each part is compared as text after parsing, so 192.168.001.1 is rejected while some system tools accept it and read it as octal.
  • One prefix per run: no VLSM splitting, no start-and-end range input, and no IPv6, since the four-part octet check never accepts a colon-form address.
  • The address-type label comes from a hard-coded octet table, so 100.64.0.0/10 (RFC 6598), 192.0.2.0/24 (TEST-NET-1) and 198.18.0.0/15 all show as public and should not be treated as a final private-versus-public verdict.
  • Calculation runs on every keystroke, so a half-typed address such as 10.1 flashes the invalid-format banner, and the copy button only appears once a result exists.

Related tools

When it goes wrong

I typed 26.5 into the CIDR box and the network address jumped to .96, but the usable-host count reads 43.255.

CauseThe field is bound with v-model.number, so parseFloat hands 26.5 straight through the 0–32 range check. The mask is built as 0xFFFFFFFF << (32 - cidr), and JavaScript converts a shift count to uint32 before shifting, so 5.5 becomes 5 and the mask shown is the /27 one. The host counts are computed separately with Math.pow(2, 32 - cidr), which returns 45.25 for that exponent, and 43.255 is what happens after subtracting two.

FixEnter whole prefixes only — the number input declares step 1 but never blocks a decimal from reaching the model. If the block you meant was /27, retype 27 and the mask, network and host figures agree again.

I deleted the address in the input box and the mask, host range and binary panel stayed on screen.

CauseThe watcher on the two fields is wrapped in if (ipInput.value), so an empty address skips calculateSubnet() altogether and subnetInfo keeps holding the previous result object. Nothing in the template re-derives the panel, and the error branch is skipped too, so stale numbers render with no warning.

FixPress the Clear button: it empties the address, puts the prefix back to 24 and nulls the result in one go. Editing only the prefix will not refresh the panel either, for the same guard.

A mistyped 33 in the prefix made the entire result block disappear, Copy Result button included.

CauseThe range test runs before any arithmetic and sets subnetInfo to null while raising “CIDR must be between 0 and 32”. The min and max attributes are constraint hints for form validation only — they do not stop a typed number from reaching the model, so 33 is calculated as far as the check.

FixCorrect the number to 0–32; the result cards and the Copy Result button both return on that keystroke, since both sit behind v-if="subnetInfo".

The copied host count shows up as 16,777,214 and a script that parses it breaks; the field names are in the page language, not the one my parser expects.

CauseCopy Result assembles plain text at click time from the active locale: every label comes from tools.subnet.copyLabel*, and the usable-host number goes through toLocaleString(), so anything from a thousand upward carries a grouping separator. The first line also echoes the address field verbatim rather than the trimmed string that was actually parsed.

FixRead the dotted values from the result cards and recompute the count as 2^(32-cidr) - 2 (1 for /32, 2 for /31), or strip separators and match the labels of whichever language you ran the copy in.

An address pasted from a spec sheet is rejected with “Invalid IPv4 address format” even though it looks the same as one I typed by hand.

CauseEach octet must satisfy String(parseInt(part, 10)) === part. Full-width digits from a CJK input method, a leading plus sign, or a stray comma or space left inside the string all fail that equality, and only the outer ends of the whole field are trimmed. The banner names no octet, so the string looks correct on screen.

FixSwitch the input method to half-width and retype it, or paste through a plain-text editor first. Split the address on dots yourself and compare each part to its integer form to find the octet that fails.

Prefix quick table, as this calculator reports it

PrefixDotted maskWildcardAddresses in blockUsable hosts
/8255.0.0.00.255.255.25516,777,21616,777,214
/12255.240.0.00.15.255.2551,048,5761,048,574
/16255.255.0.00.0.255.25565,53665,534
/20255.255.240.00.0.15.2554,0964,094
/22255.255.252.00.0.3.2551,0241,022
/24255.255.255.00.0.0.255256254
/25255.255.255.1280.0.0.127128126
/26255.255.255.1920.0.0.636462
/27255.255.255.2240.0.0.313230
/28255.255.255.2400.0.0.151614
/29255.255.255.2480.0.0.786
/30255.255.255.2520.0.0.342
/31255.255.255.2540.0.0.122
/32255.255.255.2550.0.0.011

Usable hosts follow the cidr >= 31 branch: /31 reports 2 and /32 reports 1 instead of dropping the two boundary addresses, so read /31 as a point-to-point link and /32 as a single host route. The quick-select buttons ship /8, /16, /24 through /30 and /32 only — there is no /31 button, so that prefix has to be typed.

Frequently Asked Questions

What do /24 and /16 mean?
They count consecutive 1-bits in the subnet mask: /24 = 255.255.255.0 — 24 network bits, 8 host bits, 2⁸−2 = 254 usable hosts; /16 gives 65,534. Smaller prefix, bigger network.
Why is the usable host count always minus two?
Every subnet reserves two addresses: all-zero host bits is the network address itself, all-ones is broadcast. A /30 has just 2 usable — exactly why it serves point-to-point links. Exclude both from allocation planning.
How do I tell if two IPs share a subnet?
AND each IP with the mask; identical results mean same subnet. The intuition: 10.0.1.5 and 10.0.2.5 differ under /24 but match under /16 — when "ping fails without a gateway", compute this first.

Content reviewed: