Clear methods, worked examples and practical results.toolsgenio.com
☰

IPv4 Subnet Calculator

Your inputs

Calculated result

192.168.1.0/24

Your result

Broadcast 192.168.1.255; 256 addresses

This calculator provides an estimate based on the entered values. Verify the assumptions and results before making decisions.

Intro

The mathematical foundation of IPv4 subnetting is a fixed-width binary partition. Every IPv4 address is a 32-bit integer, and a CIDR prefix specifies how many of its highest-order bits participate in the network identifier. This definition is more precise than the familiar dotted-decimal notation, which is simply a convenient way to display the underlying integer.

An IP subnet calculator performs the consequences of that binary division: it identifies an aligned address block, determines the ordinary directed broadcast boundary, and counts the bit patterns within the block. Understanding the operations behind these results makes subnet behavior predictable even when prefixes do not end at octet boundaries. This guide develops the logic from bit masks, explains why blocks follow powers of two, and examines why /31 and /32 require different operational interpretations.

About this result

How to use

Enter the requested values, then select Calculate to view the result.

Formula

Represent the IPv4 address as an unsigned integer I between 0 and 2^32 - 1. Let p be the prefix length. The subnet mask M consists of p leading one-bits and 32 - p trailing zero-bits.

For 0 <= p <= 32, the total number of numerical addresses is A = 2^(32 - p). The network identifier is N = I AND M. The 32-bit wildcard mask is W = NOT(M), with the complement confined to the IPv4 width.

The highest numerical address in the block is H = N OR W. Because the host bits form the low-order portion of the number, H also equals N + A - 1. In conventional IPv4 subnets with at least two host bits, N is the network address, H is the directed broadcast address, and the ordinary usable-host interval extends from N + 1 through H - 1.

Its size is A - 2. The interpretation differs for special-purpose prefixes, especially /31 and /32. The alignment condition is N modulo A = 0 when IPv4 addresses are interpreted as unsigned integers.

This follows from setting the final 32 - p bits to zero. It provides a way to check whether an apparent network identifier is actually aligned to the stated prefix. For /30, there are two host bits.

Thus A = 2^2 = 4, and the subnet mask is 255.255.255.252. The last mask octet is binary 11111100, while the wildcard's final octet is 00000011, or decimal 3. Consequently, /30 network starts in the final octet occur at multiples of four. The algebra, binary pattern, and decimal block-size shortcut all describe the same partition.

Worked example

Consider the address 10.0.8.6/30. We will derive the subnet directly from binary operations and confirm it using integer arithmetic. Step 1: Determine the bit division.

The prefix length is 30, so there are 32 - 30 = 2 host bits. The block contains 2^2 = 4 numerical IPv4 addresses. Step 2: Construct the subnet mask.

Thirty leading binary ones followed by two zeros produce 255.255.255.252. The final octet of this mask is binary 11111100. Step 3: Convert the relevant address octet into binary. The final octet of 10.0.8.6 is 6, whose eight-bit representation is 00000110.

Step 4: Apply bitwise AND. The operation 00000110 AND 11111100 yields 00000100, or decimal 4. The preceding three octets remain 10.0.8 because their mask octets are 255.

Therefore the network address is 10.0.8.4. Step 5: Determine the wildcard bits. The complement of the final mask octet is 00000011, or decimal 3. Setting those two host bits to one changes the last octet from binary 00000100 to 00000111, or decimal 7.

The conventional broadcast address is 10.0.8.7. Step 6: Identify the host interval. For this conventional /30 subnet, the ordinarily usable host addresses are 10.0.8.5 and 10.0.8.6. There are 4 - 2 = 2 such addresses.

Step 7: Check alignment and block size. The network's final octet is 4, a multiple of the four-address block size. The interval from 10.0.8.4 through 10.0.8.7 contains exactly four values.

The input address is the second usable host position. This calculation illustrates why the same mathematical procedure works for arbitrary valid IPv4 prefixes, even when the familiar dotted-decimal presentation hides the underlying bit operations.

Understand the calculation

IPv4 subnetting can be understood as a partition of the integer interval from 0 through 2^32 - 1. Every IPv4 address maps to exactly one integer in that interval. Dotted-decimal notation presents the integer as four base-256 components, but binary arithmetic determines the network boundaries.

A CIDR prefix length p fixes the first p bits of the address. The remaining 32 - p bits may vary, generating a set of 2^(32 - p) consecutive numerical addresses. Because the varying bits occupy the low-order portion of the integer, each subnet is aligned to a multiple of its block size.

This explains both the power-of-two capacity rule and the predictable boundaries observed in subnet calculations. The subnet mask is a binary word consisting of p leading ones followed by 32 - p zeros. When that mask is combined with an address through a bitwise AND operation, every host bit becomes zero, leaving the subnet's lowest address.

To obtain the highest address of the block, the host-bit positions are instead set to one. For conventional IPv4 prefixes, that highest value is the subnet's directed broadcast address. A wildcard mask is the bitwise complement of the subnet mask.

It has zeros where the network prefix is fixed and ones where host bits are permitted to vary. Wildcard masks are useful for understanding matching logic, although their use in configuration syntax varies by platform and should not be confused with universal interface behavior. An important distinction is the mathematical block versus address-assignment semantics.

The arithmetic always determines how many bit patterns a prefix contains. Whether particular positions can represent ordinary hosts depends on protocol rules and link type. In conventional IPv4 subnets with sufficient host bits, the first position is the network identifier and the final position serves as directed broadcast.

In a /31 point-to-point link, both addresses can represent endpoints under the applicable rules. A /32 identifies one specific address and does not require a two-address exclusion. Boundary cases also clarify the model.

A /0 prefix mathematically covers the entire IPv4 address space and contains 2^32 address patterns, but that does not imply those addresses are freely assignable or belong to one deployable local subnet. At the opposite end, a /32 matches precisely one address. These extremes illustrate why capacity arithmetic alone cannot describe operational suitability.

Once subnetting is viewed as binary masking and interval alignment, the dependence on historical address classes disappears. Prefixes of different lengths can be compared systematically without appealing to obsolete classful assumptions.

Questions

Why are IPv4 subnet sizes powers of two?

A CIDR prefix fixes a set of network bits and leaves a whole number of host bits. Each host bit independently has two possible values. Therefore, h host bits create exactly 2^h combinations, producing power-of-two address blocks.

What does a bitwise AND operation accomplish in subnetting?

Bitwise AND preserves an address bit only when the corresponding mask bit is also one. Because mask bits are zero in the host portion, applying AND removes the host-specific bits and leaves the aligned numerical identifier of the containing network.

What is the relationship between subnet masks and wildcard masks?

Within the 32-bit IPv4 width, the wildcard mask is the binary complement of the subnet mask. Network-fixed positions become zeros in the wildcard, while variable host positions become ones. This mathematical relationship is useful even though configuration syntax differs among systems.

Why can a /31 subnet contain two usable endpoint addresses?

RFC 3021 defines special handling for appropriate IPv4 point-to-point links. Because those links connect two endpoints and do not use the ordinary directed-broadcast model, the two address positions can represent endpoints rather than following conventional network-and-broadcast exclusions.

How should a /32 prefix be interpreted mathematically?

A /32 fixes all 32 bits of an IPv4 address and leaves zero host bits. Its block size is 2^0, or one address. It commonly represents a host-specific route or single-address assignment, so subtracting two would be meaningless.

Why does a valid CIDR network address need to be aligned?

All host bits of the network identifier must be zero. Since those bits represent the lowest-order portion of the address integer, the resulting value is a multiple of the block size. An unaligned candidate address instead belongs to an earlier aligned network boundary.