Calculate Netmask From an IPv4 Address and Prefix
- Wildcard mask
- Result
- Usable host addresses
- addresses
- Result
- Prefix length
- 24
- You entered
Calculate a netmask by converting an IPv4 prefix length, such as /24, into its dotted-decimal subnet mask; the calculator also shows the wildcard mask and the number of usable host addresses. Enter a prefix from 0 to 32 to see the corresponding values.
Formula
An IPv4 netmask has 32 bits. A prefix length p marks the first p bits as network bits (1s); the remaining 32 − p bits are host bits (0s). The calculator’s first result encodes those 32 mask bits as a dotted-decimal IPv4 address. Its expression computes the mask’s 32-bit integer value; to read it in dotted-decimal form, split it into four 8-bit octets. For /24, that value is 4294967040, or 255.255.255.0.
The wildcard mask is the bitwise inverse of the netmask: each 0 becomes 1 and each 1 becomes 0. It is shown here as a 32-bit integer; for /24 it is 255 in the last octet, or 0.0.0.255 in dotted decimal. The host-count formula is 2h − 2, where h = 32 − p is the number of host bits. The subtraction conventionally excludes the network and broadcast addresses on ordinary IPv4 subnets. /31 and /32 have special uses, so their practical address availability does not follow that usual subtraction rule.
All prefix lengths and addresses are unitless; an IPv4 address is four decimal octets, each from 0 through 255. A prefix may range from /0 to /32. The formula in the calculator represents the mask as a number because its output field cannot assemble dotted notation; use the octet explanation below to interpret it.
Worked Example
With the default prefix /24:
- The first 24 bits are 1 and the last 8 bits are 0: 11111111.11111111.11111111.00000000.
- Each 8-bit group converts to decimal as 255, 255, 255, and 0. The netmask is 255.255.255.0.
- Invert each octet to get the wildcard mask: 0.0.0.255, represented by 255 in the calculator’s integer output.
- There are 32 − 24 = 8 host bits. The ordinary usable-host calculation is 28 − 2 = 254 addresses.
How a Netmask Works
Devices use a netmask to distinguish the network portion of an IPv4 address from its host portion. A device applies a bitwise AND operation to an address and its mask to find the network address. For example, with 192.168.1.37/24, the mask is 255.255.255.0, so the network address is 192.168.1.0. Addresses that share that network portion belong to the same subnet under this prefix.
CIDR notation writes the prefix length after a slash, such as 192.168.1.37/24. This notation is a compact way to specify the same information as an address plus dotted-decimal netmask. The prefix counts consecutive 1 bits from the left; it does not mean that every subnet must end on a whole-octet boundary.
Common Prefix Examples
- /8: 255.0.0.0; 24 host bits; 16,777,214 conventionally usable host addresses.
- /16: 255.255.0.0; 16 host bits; 65,534 conventionally usable host addresses.
- /24: 255.255.255.0; 8 host bits; 254 conventionally usable host addresses.
- /25: 255.255.255.128; 7 host bits; 126 conventionally usable host addresses.
- /30: 255.255.255.252; 2 host bits; 2 conventionally usable host addresses.
- /32: 255.255.255.255; a single IPv4 address, commonly used to identify one host or route.
For a non-octet prefix such as /25, the mask changes partway through the last octet: 128 is binary 10000000. That is why /25 divides a /24-sized address range into two smaller blocks, rather than producing a mask ending in 255 or 0 only.
Choosing a Prefix and Reading Results
Choose a prefix based on the number of addresses and the network plan, not merely on the familiar shape of a mask. A longer prefix leaves fewer host bits and creates a smaller subnet; a shorter prefix provides a larger address block. To estimate the traditional usable-host capacity, find the host-bit count (32 minus the prefix) and calculate 2 to that power minus 2.
For instance, /26 leaves 6 host bits, giving 64 total addresses and ordinarily 62 usable host addresses. The subnet’s network and broadcast addresses are reserved under the conventional subnet model. Actual configuration requirements can also depend on routing design and equipment, so confirm the assigned prefix and address range with the network plan rather than choosing one in isolation.
Common Mistakes and Limitations
- Confusing a prefix with an address: /24 is a bit count, not an IP address or a number of hosts.
- Assuming every mask ends in 0 or 255: prefixes such as /20, /25, and /27 create partial-octet values.
- Counting all addresses as assignable: the familiar 2h − 2 rule excludes network and broadcast addresses for ordinary IPv4 subnets. /31 point-to-point links and /32 host routes are exceptions to that simple rule.
- Rounding too early: preserve the exact prefix and binary structure; convert each complete octet to decimal only after identifying its bits.
- Applying IPv4 rules to IPv6: IPv6 uses prefix lengths too, but it has 128-bit addresses and no dotted-decimal netmask. This calculator is for IPv4 only.
The calculator accepts a prefix from 0 to 32, but its arithmetic output encodes the mask as an integer rather than formatting it into four dotted octets. The results are mathematical conversions, not a check that a particular address block is available, correctly routed, or suitable for a network.
Frequently Asked Questions
What is the netmask for /24?
A /24 netmask is 255.255.255.0. It has 24 network bits and 8 host bits.
How do I calculate a netmask from an IP address?
You also need the prefix length. The IP address alone does not determine its subnet mask; for example, an address can be configured with different valid prefixes.
How many usable hosts are in a /24?
Under the conventional IPv4 subnet rule, /24 has 8 host bits, so 28 − 2 = 254 usable host addresses.
What is the difference between a netmask and a wildcard mask?
They are bitwise inverses. A /24 netmask is 255.255.255.0, while its wildcard mask is 0.0.0.255.
Can a netmask have a value such as /27?
Yes. /27 is a valid prefix and corresponds to 255.255.255.224. Prefix lengths need not be multiples of eight.
Related
Formula used
in prefix | Prefix length | - | 24 | 0 out netmask | Netmask | - | floor(prefix / 8) * 255 + floor((prefix - floor(prefix / 8) * 8) / 4) * 128 + floor(((prefix - floor(prefix / 8) * 8) - floor((prefix - floor(prefix / 8) * 8) / 4) * 4) / 2) * 64 + ((prefix - floor(prefix / 8) * 8) - floor((prefix - floor(prefix / 8) * 8) / 4) * 4 - floor(((prefix - floor(prefix / 8) * 8) - floor((prefix - floor(prefix / 8) * 8) / 4) * 4) / 2) * 2) * 32 | 0 out wildcard | Wildcard mask | - | 4294967295 - (floor(prefix / 8) * 4278190080 + floor((prefix - floor(prefix / 8) * 8) / 4) * 2147483648 + floor(((prefix - floor(prefix / 8) * 8) - floor((prefix - floor(prefix / 8) * 8) / 4) * 4) / 2) * 1073741824 + ((prefix - floor(prefix / 8) * 8) - floor((prefix - floor(prefix / 8) * 8) / 4) * 4 - floor(((prefix - floor(prefix / 8) * 8) - floor((prefix - floor(prefix / 8) * 8) / 4) * 4) / 2) * 2) * 536870912) | 0 out hosts | Usable host addresses | addresses | max(0, 2^(32 - prefix) - 2) | 0
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.