Checking inclusive IPv4 endpoints without dropping one address
Counting the addresses between a first and a last address is a fencepost problem. This guide shows why the count is the difference plus one and how a range lines up with a CIDR block.
The fencepost problem in address ranges
The range 192.0.2.8 through 192.0.2.15 lists the addresses 8, 9, 10, 11, 12, 13, 14 and 15 in the last octet. Subtracting the first from the last gives 7, but there are eight addresses, because both endpoints belong to the range. The same slip happens with fence posts: a fence with seven gaps has eight posts. In these tools a range is inclusive at both ends, so the count is last minus first plus one. Forgetting the extra one is the most common error when a range is counted in a spreadsheet, and it understates every range by exactly one address. The opposite slip also occurs: adding one to a count that was already inclusive, which turns 8 into 9. Settle early whether your source treats the last address as part of the range, and write that convention beside the figures, since some documents describe a range by its first address and a length instead.
Working with whole addresses as numbers
The calculators convert each address to an unsigned 32-bit integer before doing any arithmetic. The address 192.0.2.8 becomes 192 × 16,777,216 + 0 × 65,536 + 2 × 256 + 8 = 3,221,225,992. The address 192.0.2.15 becomes 3,221,225,999. The difference is 7, and adding one gives the count of 8. Doing the sum on the whole number matters when a range crosses an octet boundary, because the last octets alone no longer subtract sensibly. For this small example the last-octet shortcut happens to work, which is a reason to check it on a harder range before trusting it.
When the range is a single CIDR block
The eight addresses starting at 192.0.2.8 form the block 192.0.2.8/29. A /29 leaves three free bits, so it holds 2^3 = 8 addresses, and the block must start at a multiple of 8 in the last octet. 8 is a multiple of 8, and the last address is 8 + 7 = 15. That alignment is why the range converter returns one block for this range. The subnet calculator agrees, reporting network 192.0.2.8, last address 192.0.2.15 and 8 total addresses. When the count is a power of two and the start is a multiple of that count, one block covers the range.
More examples of inclusive counts
The range 192.0.2.64 through 192.0.2.127 spans 127 - 64 + 1 = 64 addresses, and the converter returns the single block 192.0.2.64/26. A full last octet, 192.0.2.0 through 192.0.2.255, holds 256 addresses and is the block 192.0.2.0/24. The smallest possible range has the same start and end. The range 10.0.0.0 through 10.0.0.0 has a difference of 0, and a count of 1, which is the /32 block 10.0.0.0/32. That last case is a good test of any formula you write yourself, since a formula that omits the plus one reports no addresses for a range that plainly contains one.
Total addresses versus usable hosts
The inclusive count describes the range itself. The subnet calculator also reports a conventional usable-host count, which subtracts the network and broadcast addresses from an ordinary block. For the /29 here that convention gives 6 hosts out of 8 addresses. Those are different questions. The range count answers how many address values lie between the endpoints. The host count answers how many addresses a typical network would hand to devices. Neither number is a rule that fits every context, and special cases such as point-to-point links change the convention. RFC 3021 describes /31 links that use both addresses, and a /32 names a single address, so the subtract-two shortcut fails for the smallest blocks. Where a pool is carved out of a larger network, the owner may also hold back addresses for gateways or infrastructure, which lowers the number available further. Use the figure that matches the question you are asking.
What the range converter checks
The range-to-CIDR converter repeatedly takes the largest power-of-two block that starts at the current address, aligns to its own size and still fits before the end, then moves on. For an aligned range it finishes after one block, as here. For a range that is not aligned it produces several blocks whose counts add up to the same inclusive total. That sum is a useful audit: add the sizes of the returned blocks and compare the result with last minus first plus one. If the totals differ, one of the endpoints was typed or interpreted differently from what you intended.
Keeping coverage separate from policy
This worksheet checks coverage of address values. It cannot tell you whether any address in the range is allocated, reserved or already in use, and it does not model firewall behavior, routing tables or assignment rules. A policy may exclude certain addresses from a pool even though they lie inside the range. When you record a range for another person, write the first and last addresses and the inclusive count together, so that a reader who recalculates the count gets 8 and not 7 and knows both endpoints were meant to be included.
Sizes that fit and sizes that do not
Only some counts can be a single CIDR block. The block sizes are the powers of two: 1, 2, 4, 8, 16, 32, 64 and so on, matching prefixes /32, /31, /30, /29, /28, /27 and /26. A range of 6 addresses cannot be one block, and neither can a range of 10 or 12. The range 192.0.2.1 through 192.0.2.6 holds six addresses and needs four entries. Even a power-of-two count fails if the start is misaligned: the eight addresses from 192.0.2.4 through 192.0.2.11 would not match any /29, because a /29 begins at 0, 8, 16 and so on. So a range count alone says little about the CIDR form.
Spreadsheet formulas for the count
If you keep address ranges in a spreadsheet, store each endpoint as its 32-bit integer in a helper column. The inclusive count is then the last column minus the first column plus 1. Convert with first octet times 16,777,216 plus second times 65,536 plus third times 256 plus fourth. Test the formula on 192.0.2.8 through 192.0.2.15, which must give 8, and on a single address, which must give 1. Keep the dotted text beside the integers, because the integers are hard to read, but never compute from the text. A column of integers also sorts correctly, whereas sorting dotted text puts 10.0.0.2 after 10.0.0.19.
Reproduce the checks
Inclusive block endpoints
Open the Subnet Calculator and enter:
- IP address
192.0.2.8- Prefix length
29
Expected output:
Network
192.0.2.8Last address
192.0.2.15Total addresses
8Both endpoint values belong to the block.
Range representation
Open the Ipv4 Range To Cidr Calculator and enter:
- Start
192.0.2.8- End
192.0.2.15
Expected output:
Blocks
192.0.2.8/29The exact aligned range needs one block.
References and implementation scope
The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.
Sources
- Primary definition and convention reference ↗ · 2026-10-08