liveBook · Manning

Subnetting

As explained in Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu

Subnetting is the process of dividing an IP network into smaller networks by extending its network prefix.

Subnetting divides an IP network into smaller networks by extending its network prefix. CIDR notation combines a base address with a prefix length that identifies network bits; the remaining bits support hosts or further subdivision. section 10.2.1

Use the prefix length to reason about subnet capacity:

  • Taking two additional bits creates four /18 networks, because each borrowed bit doubles the number of available networks. section 10.2.1
  • Terraform's cidrsubnet function accepts a parent CIDR, added subnet bits, and a subnet number, returning the selected subnet in CIDR notation. section 10.2.1

Generating Terraform subnets

Calling cidrsubnet("192.168.0.0/16", 2, 0) returns 192.168.0.0/18; subnet numbers 1, 2, and 3 return 192.168.64.0/18, 192.168.128.0/18, and 192.168.192.0/18. Use cidrnetmask("192.168.0.0/18") to obtain 255.255.192.0.

Building an uneven three-segment topology

When public, private, and isolated networks are needed, divide the parent network in half first. Assign one half to the private network, then divide the other half into public and isolated subnets. This accommodates three networks while respecting power-of-two subdivision. section 10.2.3

How Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu covers it

How deep it goes
Explains CIDR prefixes, borrowed bits, ranges, and Terraform calls, then stops short of provider-specific networking research.
Examples
Demonstrates /16-to-/18 subdivision, Terraform console calls, and nested allocation for three cloud network segments.
What it assumes
Assumes basic IP addressing and Terraform usage while defining CIDR prefixes and subnetting mechanics explicitly.
What you can do after
Builds Terraform subnet allocations and switches between compatible public-private and three-segment network modules.
How it connects
Connects CIDR to Terraform, VPCs, subnet resources, route tables, NAT gateways, and public, private, and isolated networks.

Also explained in

Compare how 2 books explain subnetting →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu. The section links point to the parts of the book it draws on.