Course outline

Networking / Basic: packet paths and addressing / Lesson 2

Calculate IPv4 prefixes and subnet boundaries

Use binary prefix reasoning and offline address arithmetic to plan subnets without relying on historical address classes.

About 4 min readContent reviewed
On this page

Lesson goals

  • Explain prefix length, network identity, and host bits.
  • Calculate ordinary subnet ranges and recognize /31 and /32 context.
  • Validate overlap and capacity before assigning addresses.

CIDR defines a bit boundary

An IPv4 address contains 32 bits. A /p prefix fixes the first p bits as the network portion and leaves the remainder for addresses within that block. The mask is a representation of the same boundary, not an independent source of extra capacity. Historical class A, B, and C labels are poor substitutes for an explicit prefix. Two addresses that look similar in dotted decimal can belong to different subnets, and different-looking final octets can still share a larger prefix. Perform the bit-based membership test rather than comparing text fragments.

Count addresses before counting usable hosts

A prefix contains 2 raised to the number of remaining bits addresses. In an ordinary IPv4 broadcast subnet, the all-zero host part identifies the network and the all-one host part is its directed broadcast address. Many beginner exercises therefore subtract two, but that is not universal: point-to-point /31 addressing and /32 host routes have different contexts. State the link design before applying a host-count rule. Reservations for routers, redundancy, devices, and future growth further reduce the addresses available to ordinary endpoints. Capacity planning is not only a mathematical maximum.

python Calculate a documentation subnet offline
from ipaddress import ip_network
network = ip_network('192.0.2.64/27')
print(network.network_address, network.broadcast_address)
print('addresses=', network.num_addresses, sep='')
print('ordinary_hosts=', len(list(network.hosts())), sep='')
Expected output
192.0.2.64 192.0.2.95
addresses=32
ordinary_hosts=30

The standard-library calculation finds 32 total addresses and 30 ordinary host addresses for this /27. It assigns nothing and sends no packet.

A host address and a network declaration are different

An interface address includes a host value and prefix, while a network declaration usually requires host bits to be zero. Tools may reject a noncanonical network or normalize it if explicitly requested. Silent normalization can hide a typo, so review the resulting network boundary. Membership means the address shares the prefix, not that a route, lease, or firewall permission exists. A locally configured prefix influences whether a host attempts direct neighbor delivery or uses a router. An incorrect mask can therefore create confusing one-way behavior without changing the textual destination address.

Plan aligned blocks and detect overlap

Dividing a larger block into equal smaller prefixes creates aligned boundaries. Arbitrary start and end ranges are not always expressible as one prefix. Allocate a contiguous plan that can be summarized where policy permits, and document which segments must remain separate. Overlapping subnets can be intentional in isolated routing domains but become a conflict when connected without a translation or routing design. Check overlaps mechanically before deployment and include management, transit, and service networks in the inventory. Documentation addresses in this course are examples, not a source of deployable public address space.

python Split a /24 into aligned /26 blocks
from ipaddress import ip_network, ip_address
parent = ip_network('198.51.100.0/24')
children = list(parent.subnets(new_prefix=26))
print(', '.join(str(n) for n in children))
print('member=', ip_address('198.51.100.70') in children[1], sep='')
Expected output
198.51.100.0/26, 198.51.100.64/26, 198.51.100.128/26, 198.51.100.192/26
member=True

Four subnets cover the parent without overlap. The membership check is arithmetic only and does not imply that any endpoint exists.

Validate the plan against operational needs

Write endpoint counts, reservations, growth, routing boundaries, and address ownership before choosing prefixes. Keep a machine-readable inventory and test containment, overlap, and gateway membership using offline calculations. Do not assume that a larger subnet is always easier: it also enlarges the broadcast and failure domain in a conventional shared-link design. Conversely, excessively small allocations can force disruptive renumbering. Explain the tradeoff and retain the intended topology with the numbers. No example here changes an interface or DHCP pool; the output is a reviewable address plan for a later authorized environment.

Common errors and fixes

Subtracting two for every prefix

Why it happens
Ordinary broadcast subnet rules were generalized to all links.
How to fix it
Identify /31 point-to-point and /32 cases separately.
Prevent it next time
Record link purpose with host-count calculations.

Comparing dotted-decimal text for membership

Why it happens
A binary prefix was treated as a string prefix.
How to fix it
Use validated address arithmetic.
Prevent it next time
Test boundary addresses and adjacent subnets.

An overlapping allocation is connected accidentally

Why it happens
Isolated plans were merged without routing-domain review.
How to fix it
Inventory overlap and redesign the connection.
Prevent it next time
Run offline overlap checks before changes.

Check your understanding

1. How many total addresses are in a /28, and what qualification applies to the usual usable-host answer?

Show worked solution

There are 16 addresses. In an ordinary broadcast subnet, 14 are host addresses before local reservations. That usable count assumes this conventional link model and does not establish that 14 endpoints should be deployed without growth or redundancy planning.

2. Why should a tool reject or explicitly normalize 192.0.2.70/27 as a network declaration?

Show worked solution

The host bits are not zero; its containing network is 192.0.2.64/27. Explicit handling exposes the distinction between interface address and network identity and prevents a typo from silently changing the allocation boundary.

Key takeaways

  • Use explicit prefixes and bit-based calculations.
  • Plan reservations, overlap, and failure domains as well as counts.

Official references