Terminology (6)Terms used in this lesson
Term on the front, definition on the back. Paste with tabs between fields and a new line between cards, or import the download in Anki as Basic.
- Subnet
- A contiguous range of addresses whose size is a power of two.
- Prefix
- The number of fixed leading bits, written /n; a /n subnet has 2^(32 − n) addresses.
- Reserved addresses
- Addresses the provider keeps in every subnet; standard AWS-provided IPv4 subnets reserve5, including network and broadcast addresses; address modes can differ.
- Block
- The power-of-two size a subnet takes, whatever it uses of it.
- Alignment
- A subnet starts at a multiple of its own size within its parent.
- Parent range
- The larger range the network team assigned, which the subnets are carved from.
Why this matters
Subnets are hard to change once a cluster runs in them: moving existing resources into new subnets can require migration. If a pod subnet runs out, new pods cannot start, usually at the busiest moment. Getting the sizes right is a little arithmetic with powers of two, done before the first node joins.
This lesson assumes powers of two and rounding up.
What a subnet allocates
An IPv4 address has 32 bits. A prefix /p fixes p of those bits, leaving 32 − p bits to vary within the subnet, so its block contains 2^(32 − p) addresses. A subnet occupies that whole block even when some addresses are unused.
Demand counts endpoints that need addresses; capacity counts the addresses a subnet can supply after reservations. Growth allowances change demand, while prefix lengths and alignment constrain which blocks can be allocated. The provider’s size and reservation rules are additional constraints.
01Size one subnet
Size one subnet
An online grocery company plans an IPv4 Kubernetes network on AWS, using pod addresses from VPC subnets. The network team assigned a /19. Each of three zones needs subnets for pods, nodes and load-balancer interfaces, with room to grow. The capacity sheet adds up the addresses and says it fits.
Allow 25% growth, round up to a whole address, and add the standard 5 reserved addresses for this AWS-provided IPv4 subnet model. AWS permits IPv4 subnet sizes from /28 (16 addresses) to /16 (65,536), so also apply those provider limits. The examples here already fall within that range; the lab below separately practices generic power-of-two blocks with caller-supplied reservations. For the arithmetic, grown=ceil(n(100+g)/100), needed=grown+reserved and block=2ᵏ for the least k with 2ᵏ≥needed. IPv4 prefix length is 32−k. On whole inputs, ceil division is floor((n(100+g)+99)/100), so no floating tolerance is needed.
| Tier | Endpoints | Needed | Block |
|---|---|---|---|
| Pods | 1,700 | 2,125 + 5 = 2,130 | 4,096 (/20) |
| Nodes | 90 | 113 + 5 = 118 | 128 (/25) |
| Load balancers | 20 | 25 + 5 = 30 | 32 (/27) |
Neither Node.js nor browsers parse CIDR prefixes; the arithmetic above is a few lines of integer code.
02Sum blocks, not demand
Sum blocks, not demand
Predict the two lines this program prints.
function block(endpoints: number): number {
const needed = Math.ceil(endpoints * 1.25) + 5; // 25% growth, 5 addresses reserved per subnet
let size = 1;
while (size < needed) size *= 2;
return size;
}
const tiers = [1700, 90, 20]; // pods, nodes, load-balancer interfaces in one zone
console.log(tiers.map(block).join(" "));
console.log(3 * tiers.map(block).reduce((sum, size) => sum + size, 0), 2 ** (32 - 19)); // three zones vs a /19
Three zones need 6,834 addresses, which is what the capacity sheet added. They take 3 × 4,256 = 12,768 addresses of blocks, against the /19’s 8,192. The plan does not fit.
03Alignment
Alignment
Within an aligned parent, a subnet starts at a multiple of its own size. The same allocation problem now arises in a separate /22 extension range: 1,024 addresses already hold two subnets. Offsets below count from that parent’s base; they are not final-octet address strings.
| Offsets | Use |
|---|---|
| 0–191 | free (192) |
| 192–255 | existing /26 |
| 256–639 | free (384) |
| 640–767 | existing /25 |
| 768–1,023 | free (256) |
832 addresses are free. A /23 of 512 can start only at 0 or 512, and each of those ranges contains an existing subnet, so it does not fit. A /24 of 256 can start at 0, 256, 512 or 768; 256 is the first that is clear.
04What is left
What is left
Return to the three-zone plan in a fresh /18. For an empty aligned power-of-two parent, largest-first placement works whenever total blocks fit: every earlier block size is a multiple of each smaller size, so each next offset remains aligned. The 12,768 addresses of blocks placed that way leave 3,616. Placed that way, the leftover splits into aligned subnets by its binary digits: 2,048 + 1,024 + 512 + 32, a /21, a /22, a /23 and a /27. A fourth zone’s pod subnet, a /20, would not fit in any of them.
05What the arithmetic leaves out
What the arithmetic leaves out
06Carve the cluster’s range
Carve the cluster’s range
The cluster request first needs fixed reservations included after rounded growth. The whole plan then needs block totals, not endpoint demand. Once a parent has allocations, total free space is insufficient: the new subnet needs a complete aligned interval, including its far edge, without overlapping any existing block.
A cluster’s address plan
Size one subnet, check the plan, then place a new subnet.
In the frontend A subnet request form in Next.js and Svelte Optional
An internal request form can show the block and prefix as the user types, and say when reservations push beyond the otherwise required block. This AWS-specific form enforces the minimum /28 and maximum /16, validates whole inputs including empty fields, and reports an oversized request rather than producing a negative or unsupported prefix. The generic lab deliberately takes its reservation count from the caller.
"use client";
import { useState } from "react";
// AWS-specific form: standard IPv4 reservations and /28.. /16 provider limits.
function describe(endpoints: number | undefined, growth: number | undefined) {
if (
!Number.isSafeInteger(endpoints) ||
!Number.isSafeInteger(growth) ||
endpoints! < 0 ||
endpoints! > 65531 ||
growth! < 0 ||
growth! > 1000
)
return { error: "Enter whole endpoints0..65531 and growth0..1000%." };
const grown = Math.floor((endpoints! * (100 + growth!) + 99) / 100);
const needed = grown + 5;
if (needed > 65536)
return {
error: "This demand exceeds one AWS IPv4 /16 subnet; revise the allocation."
};
let block = 16,
withoutReserved = 16,
prefix = 28;
while (block < needed) {
block *= 2;
prefix--;
}
while (withoutReserved < grown) withoutReserved *= 2;
return { needed, block, prefix, pushed: block > withoutReserved };
}
export function SubnetRequest() {
const [endpoints, setEndpoints] = useState<number | undefined>(100);
const [growth, setGrowth] = useState<number | undefined>(25);
const plan = describe(endpoints, growth);
return (
<form>
<input
type="number"
min={0}
max={65531}
step={1}
value={endpoints ?? ""}
onChange={(e) =>
setEndpoints(e.target.value === "" ? undefined : Number(e.target.value))
}
aria-label="Endpoints"
/>
<input
type="number"
min={0}
max={1000}
step={1}
value={growth ?? ""}
onChange={(e) =>
setGrowth(e.target.value === "" ? undefined : Number(e.target.value))
}
aria-label="Growth %"
/>
{"error" in plan ? (
<p>{plan.error}</p>
) : (
<>
<p>
{plan.needed} addresses: a /{plan.prefix} ({plan.block}).
</p>
{plan.pushed && (
<p>The five reserved addresses push this to the next block.</p>
)}
</>
)}
</form>
);
}
Check this idea later
Sources
- AWS: subnet CIDR blocks (five reserved addresses)
- RFC 4632: Classless Inter-domain Routing
- Go: net/netip
Values above were computed in Node 22 and run in Go 1.27, Rust 1.99 and Apple clang 17. The cluster plan is a worked model.
Sign in to keep your read marks on every device. Sign in
Was this helpful?