# Subnet & CIDR Calculator

- **URL:** https://codeasystem.com/calculators/developer/subnet-cidr-calculator/
- **Category:** developer
- **Description:** Turn an IPv4 address and CIDR prefix into network address, broadcast, usable host range, host count and wildcard mask.
- **Primary output:** Network address: 192.168.1.128/26

## Inputs
- IPv4 address (name: `ip`, type: text, example: 192.168.1.130)
- CIDR prefix (name: `prefix`, type: number, example: 26)

## Outputs
- Network address: 192.168.1.128/26
- Subnet mask: 255.255.255.192
- Wildcard mask: 0.0.0.63
- Broadcast address: 192.168.1.191
- First usable host: 192.168.1.129
- Last usable host: 192.168.1.190
- Usable host addresses: 62
- Total addresses in block: 64

## Formula / methodology
```
mask = prefix ? (0xFFFFFFFF << (32−p)) : 0
network = ip AND mask   broadcast = network OR NOT mask
hosts = 2^(32−p) − 2   (/31 → 2 per RFC 3021, /32 → 1)
```

The prefix length p becomes a bitmask whose first p bits are ones. ANDing it with your address yields the network address; ORing with the inverted mask yields the broadcast address.

For prefixes up to /30 the lowest and highest addresses are reserved for network and broadcast identities, leaving 2^(32−p) − 2 usable hosts. Point-to-point /31 links keep both addresses per RFC 3021, and a /32 is a single-host route.

The wildcard mask used by ACLs and routing configs is simply the bitwise inverse of the subnet mask.

## Assumptions & limitations
- Strict IPv4 dotted-decimal only; no IPv6.
- Prefix must be a whole number 0–32.
- Host counts follow the RFC 950 convention with RFC 3021 /31 handling.

## How to use
1. **Paste any address in the block**; It does not have to be the network address itself; any member lands on the same block.
2. **Set the prefix length**; Use the slash notation from your plan or config, e.g. 24 for a classic class-C-sized block.
3. **Copy the results**; Network, broadcast, host range, wildcard mask and host count are ready for router, firewall or DHCP configuration.

## Example
The address 192.168.1.130 inside a /26 sits on network 192.168.1.128 with broadcast 192.168.1.191, usable hosts .129–.190 (62 total), mask 255.255.255.192 and wildcard 0.0.0.63.

Result for these inputs:

```
Network address: 192.168.1.128/26
```

## About this calculator
### Why bit math beats mental arithmetic

Subnetting questions reduce to bitwise AND/OR on 32-bit integers. Doing them by hand means juggling octet boundaries; doing them with shifts makes every boundary; even odd ones like /13 or /27; mechanical and error-free.

### Wildcard masks in the wild

Cisco-style ACLs and OSPF network statements take wildcard masks rather than subnet masks. They are the exact complement: a /26 mask of 255.255.255.192 becomes wildcard 0.0.0.63.

### Choosing a prefix size

Plan for growth before carving blocks: a /25 holds 126 hosts, a /24 holds 254, a /23 holds 510. Reserving headroom now avoids painful re-addressing later, since usable counts double with each shorter prefix.

## FAQs
### Why does a /24 show only 254 usable hosts?

Two addresses are reserved: the lowest is the network identifier and the highest is the broadcast address, leaving 2^8 − 2 = 254 for hosts.

### What is special about /31 and /32?

RFC 3021 allows both addresses of a /31 on point-to-point links (no broadcast needed), and a /32 identifies exactly one host.

### Can I enter IPv6 or shorthand like “10.1”?

No; this tool validates strict four-octet IPv4 dotted decimal, rejecting out-of-range octets such as 999.1.1.1.

### Does this work for supernetting?

Yes. Prefixes shorter than /24 aggregate multiple class-C-sized blocks exactly the same way.

## Related calculators
- [IP Address Format Converter](https://codeasystem.com/calculators/developer/ip-converter/)
- [Port Number Lookup](https://codeasystem.com/calculators/developer/port-number-lookup/)
- [Chmod Calculator](https://codeasystem.com/calculators/developer/chmod-calculator/)

---
Last updated: 2026-08-23 · Version: 1.0.0 · [HTML version](https://codeasystem.com/calculators/developer/subnet-cidr-calculator/)
