Developer Runs locally Ready to use Built-in examples No tracking

IPv4 Subnet Calculator

Enter an IPv4 address or CIDR to get network, broadcast, mask, wildcard, usable host range and count, plus class and private-IP detection. RFC 3021 /31 handling. Runs locally.

IPv4 subnetting underlies configuring a server, dividing an internal network and writing firewall rules: given an address and a mask, the network address, broadcast address, usable host range and mask notation all need to be known. CIDR notation such as 192.168.1.0/24 replaces the traditional mask with a prefix length, which is more compact than 255.255.255.0 and is the form cloud security groups and routing tables use.

Two points easily misremembered: the usable host count subtracts the network and broadcast addresses, so a /24 gives 254 rather than 256, while /31 and /32 are exceptions — a /31 follows the point-to-point convention where both addresses are usable, and a /32 is a single host. And the private ranges number three (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16); pick from them when planning an internal network, and check they do not overlap the other end.

How to use

  1. Enter an IPv4 address or a CIDR block.
  2. Read the network, broadcast and mask values.
  3. Check the usable host range and count.
  4. Confirm whether the block is private before planning.

How it works

Accepted input forms

Two input forms work: full CIDR (192.168.1.10/24) or a bare IP (10.0.0.5, treated as /32). If you enter a host address, the host bits are masked to zero automatically, yielding the network address of its segment.

How usable hosts are counted

Usable hosts follow the standard basis: total addresses minus the reserved network and broadcast addresses. /31 point-to-point links allow both addresses per RFC 3021; /32 is a single host. Mask and wildcard mask derive from shifting and inverting the prefix length.

Private-network and class detection

Private-network detection covers the RFC 1918 ranges (10/8, 172.16/12, 192.168/16) plus loopback 127/8 and link-local 169.254/16; everything else is public. A/B/C classes divide by the first byte's range.

Code example

Shell Cross-checking on the command line (ipcalc / ip route)

# With ipcalc installed you can compute a subnet directly
ipcalc 192.168.1.10/24

# Show local addresses and netmask (Linux)
ip addr show

# Show the routing table (to confirm the default gateway and subnet)
ip route

# On macOS, use ifconfig for addresses and netmask
ifconfig en0 | grep "inet "

Python Computing a subnet with the standard library

import ipaddress

net = ipaddress.ip_network("192.168.1.0/24", strict=False)
net.network_address    # 192.168.1.0
net.broadcast_address  # 192.168.1.255
net.netmask            # 255.255.255.0
net.num_addresses      # 256
list(net.hosts())[0]   # 192.168.1.1 (first usable address)

# Private-range check
ipaddress.ip_address("10.0.0.5").is_private  # True

FAQ

What does CIDR notation mean?

CIDR (Classless Inter-Domain Routing) writes a segment as IP/prefix: 192.168.1.0/24 means the first 24 bits are network bits and the last 8 host bits — mask 255.255.255.0. Shorter prefixes mean bigger segments: /24 has 256 addresses, /16 has 65,536.

Why subtract 2 from usable hosts?

Two addresses in every segment can't go to hosts: all-zero host bits is the network address (the segment itself) and all-ones is the broadcast address (received by every host). So /24 offers 254 usable of its 256.

Why are /31 and /32 special?

/31 has only two addresses — subtracting 2 would leave none — but RFC 3021 lets point-to-point links (router-to-router) use both, halving waste; /32 is a single host address, common for loopback or exact matches, with one usable address.

Which ranges are private?

RFC 1918 defines three: 10.0.0.0/8, 172.16.0.0/12 (172.16–172.31) and 192.168.0.0/16 — internal only, never routed on the public internet. Also 127.0.0.0/8 loopback (your own machine) and 169.254.0.0/16 link-local (self-assigned when DHCP fails).

Does a host address get masked to the network automatically?

Yes. Enter 192.168.1.10/24 and the tool zeroes the host bits to get network 192.168.1.0, then computes broadcast and host range from it — no manual conversion needed.

How are A/B/C classes divided?

By first byte: 1–126 is class A (default mask /8), 128–191 class B (/16), 192–223 class C (/24); 224–239 is class D multicast, 240+ reserved as class E. Classes are historical — modern networks use CIDR — but they still surface in troubleshooting.

Are the results accurate?

Computation uses 32-bit unsigned bitwise operations (AND, OR, NOT, shifts) matching the RFC algorithms, and the engine tests cover /8 /12 /24 /29 /31 /32 against known answers. Invalid input (octets over 255, prefix over 32) errors out clearly rather than returning wrong numbers.