Services

Resources

Company

CIDR (Classless Inter-Domain Routing)

CIDR (Classless Inter-Domain Routing) is how IP ranges are written and routed today. A CIDR block such as 10.0.0.0/20 is a base address and a prefix length. The prefix length says how many leading bits of the address are fixed for the whole block; the remaining bits number the hosts inside it. Cloud networks, firewall rules, route tables and Kubernetes pod ranges are all set as CIDR blocks.

How it works

An IPv4 address has 32 bits, so a /n block holds 2 to the power (32 minus n) addresses. A /20 leaves 12 bits, which is 4,096 addresses. A /24 is 256, a /32 is one host, and 0.0.0.0/0 is every IPv4 address. Each step down in prefix length doubles the size.

The base address must have all host bits set to zero: 10.0.0.0/20 runs from 10.0.0.0 to 10.0.15.255, and 10.0.4.0/20 is not a valid block. IPv6 works the same way over 128 bits, and a standard IPv6 subnet is a /64.

Two blocks either do not touch at all, or the one with the shorter prefix contains the other. Containment is what breaks things. VPC peering in AWS refuses to connect two VPCs whose CIDRs overlap. Over a VPN, a router that sees the same range on both sides sends the packet to the local route.

Going the other way, neighbouring blocks of equal size merge into one block with a prefix one bit shorter, provided the first one starts on the bigger boundary. Routers call this aggregation or summarization: one route for 10.0.0.0/19 covers both 10.0.0.0/20 and 10.0.16.0/20.

For example, prod runs in a VPC of 10.0.0.0/20: 4,096 addresses, 10.0.0.0 to 10.0.15.255. A new staging VPC is proposed at 10.0.8.0/21, which covers 10.0.8.0 to 10.0.15.255. That is the upper half of prod, so the peering request fails. Staging moves to 10.0.16.0/20 instead. That block starts right where prod ends. The two VPCs are now neighbours, so the office VPN needs a single route for 10.0.0.0/19 to reach both. Splitting each VPC into subnets is the next step, and has its own sums.

Why it matters in production

An AWS VPC takes an IPv4 CIDR between /16 and /28, and the primary one can never be changed. When it runs short, as it often does on Amazon EKS where every pod takes a VPC address through the CNI, the answer is a secondary CIDR. That is an extra, non-overlapping block associated with the same VPC and carved into new subnets for pods. Ranges from 100.64.0.0/10 are a common pick for this.

The expensive mistakes are in planning. Two companies, two VPCs or an office and a cloud that all chose 10.0.0.0/16 will collide the day someone connects them. Renumbering a running network costs far more than writing down an IP plan up front.

See also

On the One2N blog

References

  1. RFC 4632: Classless Inter-domain Routing (CIDR)

  2. Amazon VPC User Guide: VPC CIDR blocks

Number line of IP addresses starting at 10.0.0.0. A /20 leaves 12 host bits, so prod at 10.0.0.0/20 holds 4,096 addresses and staging at 10.0.16.0/20 starts right where prod ends. A red block, 10.0.8.0/21, sits inside the upper half of prod, so VPC peering fails. A bracket under both /20 blocks merges them into 10.0.0.0/19, one VPN route that covers prod and staging.