What Is Subnetting? CIDR, Host Ranges and a Worked Example

Subnetting divides an address block into smaller prefixes. In IPv4, the prefix length tells you how many of the 32 bits identify the network; the remaining bits determine the block size. Splitting a /24 into four equal /26 blocks gives 64 addresses in each block. For the ordinary multi-access example below, that leaves 62 host addresses after the network and broadcast addresses.

Aug 21, 2024 - 17:53
Updated: 
104.4k

Networking in IT Infrastructure · Explainer

What Is Subnetting? CIDR, Host Ranges and a Worked Example

Quick answer: Subnetting divides an address block into smaller prefixes. In IPv4, the prefix length tells you how many of the 32 bits identify the network; the remaining bits determine the block size. Splitting a /24 into four equal /26 blocks gives 64 addresses in each block. For the ordinary multi-access example below, that leaves 62 host addresses after the network and broadcast addresses. Special link types and cloud-provider reservations need separate rules. Calculate the ranges first, then verify them with the checked offline Python example before considering any real network configuration.

Key takeaways

  • A longer prefix identifies a smaller block within the same address family.
  • Calculate boundaries from bits rather than the first address that looks free.
  • Distinguish block membership from an assignable host address.
  • Handle /31, /32, IPv6 and provider reservations explicitly.
  • Treat an address plan as input to routing and access design.

Table of Contents

What does subnetting change?

An address prefix describes a contiguous block. Dividing a parent prefix allocates smaller blocks for different purposes while retaining a clear relationship to the parent. The CIDR specification explains classless assignment and aggregation; classful A, B and C labels are unnecessary for solving this example.

In an invented classroom plan, four groups need separate address blocks from one /24. The arithmetic identifies which addresses belong to each group. It does not configure a switch, create a VLAN, install a route or deny traffic between groups. Those are operational decisions with their own requirements. Do not promise faster applications or isolation merely because a spreadsheet contains four subnet rows.

How do a prefix and subnet mask determine block size?

IPv4 has 32 bits. A /26 uses 26 network bits and leaves 6 remaining bits, so its block contains 2 to the power of 6, or 64 addresses. Its dotted-decimal mask is 255.255.255.192. Relative to a /24 parent, adding two prefix bits produces four equal child blocks.

The final octet boundaries in this particular /24 example advance by 64: 0, 64, 128 and 192. That shortcut depends on the actual prefix and octet boundary; it is not a universal instruction to add 64. Write the parent, requested child length and remaining bits before calculating. A /25 is larger than a /26, despite the smaller number after the slash.

What are the four /26 ranges in the worked example?

The documentation-address specification reserves 192.0.2.0/24 for examples. We use it as text and numbers only, not as a live destination. The table describes an ordinary IPv4 multi-access allocation, with network and broadcast addresses separated from the host range.

Notice the boundary at .63 and .64. Address .63 belongs to the first block but is its broadcast address under this example's rules. Address .64 begins the second block and is its network address. Neither is made assignable merely by appearing inside a block. Ask whether a question concerns membership, host assignment or routing before answering it.

SubnetNetworkOrdinary host rangeBroadcast
192.0.2.0/26192.0.2.0.1 to .62192.0.2.63
192.0.2.64/26192.0.2.64.65 to .126192.0.2.127
192.0.2.128/26192.0.2.128.129 to .190192.0.2.191
192.0.2.192/26192.0.2.192.193 to .254192.0.2.255

How can Python check the calculation without using a network?

The Python ipaddress module performs address arithmetic without opening sockets. This standalone Python 3 example splits one supplied block and checks the disputed boundary. Only these four small IPv4 host lists are materialised; do not enumerate an enormous IPv6 block merely to count it.

from ipaddress import ip_address, ip_network

parent = ip_network("192.0.2.0/24")
parts = list(parent.subnets(new_prefix=26))
for subnet in parts:
    hosts = list(subnet.hosts())
    print(f"{subnet}: {hosts[0]} to {hosts[-1]}; broadcast {subnet.broadcast_address}")
print(".63 belongs to first:", ip_address("192.0.2.63") in parts[0])
print(".64 belongs to first:", ip_address("192.0.2.64") in parts[0])
print(".64 belongs to second:", ip_address("192.0.2.64") in parts[1])

Expected output:

192.0.2.0/26: 192.0.2.1 to 192.0.2.62; broadcast 192.0.2.63
192.0.2.64/26: 192.0.2.65 to 192.0.2.126; broadcast 192.0.2.127
192.0.2.128/26: 192.0.2.129 to 192.0.2.190; broadcast 192.0.2.191
192.0.2.192/26: 192.0.2.193 to 192.0.2.254; broadcast 192.0.2.255
.63 belongs to first: True
.64 belongs to first: False
.64 belongs to second: True

The first membership result is True even though .63 is the broadcast address in this example. The next two results place .64 in the second block. The output verifies the supplied arithmetic, not address availability, a route, a firewall rule or a device configuration.

Why is subtracting two not a universal host-count rule?

For the ordinary /26 example, excluding network and broadcast addresses gives 64 minus 2, or 62. RFC 3021 specifies /31 use on IPv4 point-to-point links, where the two addresses have the link-specific interpretation described there. A /32 identifies one address; subtracting two would produce a meaningless negative host count.

IPv6 has a different addressing architecture. The IPv6 addressing specification defines unicast, anycast and multicast rather than an IPv4-style broadcast address. Do not transfer the minus-two rule or assume every possible interface arrangement uses one universal prefix length. Start with the address family, link type and platform rules. A calculator's convenience method is not a substitute for knowing which allocation model the exercise intends.

Why can cloud-provider capacity differ from the textbook count?

The AWS VPC subnet-sizing guide documents reservations beyond the ordinary network and broadcast pair for its standard IPv4 subnet arrangement: the first four addresses and the last address are unavailable to resources. It also describes special arrangements and separate IPv6 rules. Check the relevant service and configuration rather than extending that count to every cloud.

For a planning worksheet, record total addresses, the applicable reservations and addresses required by actual resources. A /26's 64 mathematical addresses are not a promise of 64 assignable VM addresses. Likewise, a correctly calculated block does not establish that a particular resource type can use it. Keep provider allocation constraints beside the arithmetic so another reviewer can reproduce the planned capacity.

Which subnetting mistakes should you check first?

Check that each child starts at a valid boundary, lies within its parent and does not overlap another allocated child. Then compare the intended host capacity with the applicable reservations and planned growth. A host address written with /26 is not necessarily a canonical network definition; distinguish an interface address from a network object.

Python's strict network parsing can expose host bits in a supposed network definition. Relaxing strict parsing normalises that input; it does not prove the original plan was intended or approved. In the classroom case, ask a partner to move one boundary by one address and explain which rule fails. This gives a concrete correction instead of memorising a row of masks without understanding their scope.

CheckReason
Address family and parentEstablishes the bit width and allocation scope
Canonical boundaryPrevents accidental host-address substitution
Overlap and containmentKeeps child allocations consistent
Assignment rulesSeparates total size from usable capacity
Operational designRouting and access still need review

Related reading: Network-engineer learning and handoff tasks; Cloud infrastructure dependency questions.

References

Frequently Asked Questions

A /26 leaves six of IPv4’s thirty-two bits outside the prefix, giving sixty-four total addresses under the mathematical block definition.

Sixty-two applies to the ordinary multi-access example here, while link-specific and provider reservation rules can change assignment capacity.

It belongs to 192.0.2.0/26 but is that block’s broadcast address under the stated ordinary IPv4 example rules.

It performs arithmetic on supplied values using ipaddress and does not create sockets, discover devices or contact a network.

RFC 3021 describes a specific point-to-point interpretation for /31 links, so the ordinary minus-two calculation must not be applied blindly.

IPv6 uses its own addressing architecture without IPv4-style broadcast, so apply its link and platform rules instead of subtracting two automatically.

The calculation creates an address plan, while routing, switching and access controls need their own appropriate configuration and verification.

It establishes the calculated properties of the supplied inputs, without proving live availability, provider support, actual assignment or network reachability.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Wow Wow 0
Sad Sad 0
Angry Angry 0
Anjali

I am passionate about technology, invention and big challenging tasks on my to- do list. In terms of the work I am doing also at Bunnyshell, I am most passionate about the technologies that we are using., I'm devoted to delivering content that not only informs but also inspires. Whether you need in- depth analysis pieces, educational attendants, or study- provoking opinion pieces, I draft content that resonates with tech suckers and professionals likewise.