Calculating a subnet in a network means turning one IPv4 address plus either a CIDR prefix or a dotted-decimal subnet mask into the full set of block boundaries the address belongs to — the network address (the first address in the block), the broadcast address (the last), the first and last usable host, the total and usable host counts, and the wildcard mask. The number of usable hosts for any prefix up to /30 is 2^(32 − prefix) − 2, because the first and last addresses are reserved as the network identifier and the broadcast and cannot be assigned to a device; a /24 therefore gives 256 total addresses but only 254 usable hosts. Two edge prefixes — /31, defined in RFC 3021 for point-to-point links, and /32, used for loopbacks and single-host firewall rules — handle the reserved-address rule differently. Whether you work the math out by hand, in a script, or with a browser-based tool, the inputs and outputs are the same: one IP, one prefix length, and a small table of derived values that tells you everything you need to plan an addressing scheme or troubleshoot why a host can or cannot reach another.

how to calculate subnet in network
How to Calculate a Subnet in a Network: Full Method

The Outputs of a Subnet Calculation

A complete subnet calculation answers six practical questions about a single IP and prefix. The network address is the first address in the block and identifies the subnet itself; the broadcast address is the last address in the block and is the destination for packets meant for every host on the subnet at once. The first and last usable host are the smallest and largest addresses that can be assigned to a device, and the usable host count tells you how many devices the subnet can hold at most. The subnet mask and the wildcard mask are two ways of describing the same boundary: the subnet mask has 1-bits where the network portion lives and 0-bits where hosts live, while the wildcard mask — the bit-for-bit inverse — is what Cisco access-control lists and OSPF network statements use to match address ranges, where a 1-bit means "any value" and a 0-bit means "must match." RFC 4632 is the modern standard for expressing the split, and the IP class (A, B, C, D, or E) is a historical label based on the first octet that still appears in routing software and many diagnostic tools. The Subnet Calculator surfaces all of these values in one results table the moment you press enter, including an RFC 1918 private-status flag so you can tell at a glance whether the address is routable on the public internet.

The Two Inputs You Need

Every IPv4 subnet calculation starts with the same two pieces of information: the address itself, written in dotted-decimal form — four numbers from 0 to 255 separated by dots, such as 192.168.1.10 — and a prefix length that says how many of the 32 bits identify the network. You can give the prefix length in two ways. The CIDR way is to write a slash and the number of network bits directly after the IP, as in 192.168.1.10/24; the slash is shorthand for the subnet mask. The mask way is to write the IP and a separate dotted-decimal mask whose binary form has exactly N leading 1-bits where N is the prefix length; /24 therefore corresponds to 255.255.255.0, /16 to 255.255.0.0, and /30 to 255.255.255.252. Both forms describe the same boundary, and the Subnet Calculator accepts either, so you can paste an address in whichever notation you already have. The mask in particular has one useful property: because the boundary falls cleanly on an octet only for /8, /16, and /24, prefixes like /20 or /27 produce masks with non-255 octets in the middle — 255.255.240.0 for /20 and 255.255.255.224 for /27 — and the calculator handles those without any special input from you.

Calculate a Subnet Step by Step

The fastest way to get a complete subnet breakdown for a given IPv4 address is to use a browser-based calculator that handles the bitwise math and the edge cases for you.

  1. Type an IPv4 address such as 192.168.1.10 into the address field.
  2. Choose CIDR prefix (for example /24) or switch to Subnet mask and enter one like 255.255.255.0.
  3. Read the results table: network and broadcast addresses, the first and last usable host, usable and total host counts, subnet and wildcard masks, IP class, and RFC 1918 private status update instantly.

For a deeper walk-through of how the same answers are produced by hand, see the next section.

How the Bit Math Works

The result of a subnet calculation is not magic — it is 32-bit unsigned bitwise arithmetic applied to the address and the mask. The network address is the bitwise AND of the IP and the subnet mask, which zeroes out every host bit and keeps every network bit. The broadcast address is the bitwise OR of the network address and the wildcard mask, which sets every host bit to 1. The wildcard mask itself is just the subnet mask with every 1-bit flipped to 0 and every 0-bit flipped to 1 — the bit-for-bit inverse — and is the format Cisco ACLs and OSPF network statements use to match address ranges. The usable host count for any prefix up to /30 is 2^(32 − prefix) − 2, because the network address and the broadcast address are reserved and cannot be assigned to a device.

To see this work end to end, take 192.168.1.10/24. The address in binary is 11000000.10101000.00000001.00001010 and the /24 mask in binary is 11111111.11111111.11111111.00000000. ANDing them keeps the first 24 bits and zeroes the last 8, giving 11000000.10101000.00000001.00000000 — or 192.168.1.0, the network address. The wildcard mask is the inverse of the subnet mask: 00000000.00000000.00000000.11111111, or 0.0.0.255. ORing the network address with the wildcard sets the last 8 bits to 1, giving 192.168.1.255, the broadcast address. The first usable host is 192.168.1.1 and the last usable host is 192.168.1.254, giving 2^8 − 2 = 254 usable hosts in total — which is exactly the number the calculator reports.

/31 and /32: Two Prefixes That Break the Rule

Two prefixes follow different rules, and a correct subnet calculator needs to handle them explicitly. A /31, defined in RFC 3021, has only two addresses in the entire block. Because both addresses are usable as hosts and there is no separate network or broadcast address, the calculator reports 2 usable hosts rather than the usual 0. /31 subnets are designed for point-to-point links between two routers, where reserving two addresses as network and broadcast wastes half of a scarce address block — and modern routers happily forward traffic on both ends without sending broadcasts. A /32 describes a single host: the network address, the broadcast address, and the host are all the same address, and the calculator reports 1 usable host. /32 is the standard way to write a loopback interface (127.0.0.1/32 is a common example), a single-host firewall rule, or a host route in a routing table that points at one specific machine rather than a subnet.

RFC 1918 Private Range Detection

The IP class alone does not tell you whether an address is routable on the public internet. RFC 1918 reserves three blocks specifically for use inside private networks behind NAT: 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16. These addresses are never routed on the public internet, so any service that listens only on a private address is unreachable from outside the local network without a NAT or port-forwarding rule. Knowing that an address is private matters before you try to expose a service, debug a connectivity issue, or document an addressing scheme for a new deployment — for example, an address that looks like a public IP by class can still fall inside 172.16.0.0/12 because that block straddles the upper part of Class B. The Subnet Calculator flags RFC 1918 status in its results table alongside the network and broadcast addresses, so you can confirm private-versus-public in the same glance that you read the host range.

CIDR Prefix Sizes at a Glance

Here is a quick reference for the most common IPv4 prefix lengths and what each looks like in subnet-mask notation. The full host range and host count for any prefix follow from the formulas in the previous section — for exact host counts and host ranges for arbitrary prefixes, paste the address and prefix into the Subnet Calculator.

CIDRSubnet mask (dotted)Network bits
/8255.0.0.08
/16255.255.0.016
/24255.255.255.024
/30255.255.255.25230
/31255.255.255.25431
/32255.255.255.25532

For IPv6 addressing, the calculation looks superficially similar but the address space is 128 bits instead of 32, the slash notation is the same, and there is no equivalent of the network/broadcast reserved-address rule. The steps for IPv6 are covered in How to Calculate an IPv6 Subnet Mask Step by Step.

For a deeper look, see How to Verify Results From a Common Network Ports List.