CIDR divides an IP network into smaller networks and represents each block with a base address and prefix, such as 192.168.0.0/16. The prefix states how many of an IPv4 address’s 32 bits identify the network; remaining bits identify hosts or support further subnetting. section 10.2.1
Increasing the prefix by taking bits from the host portion creates more, smaller networks. Taking two bits from 192.168.0.0/16 produces four /18 networks, each with a distinct address range. section 10.2.1
Generating subnets with Terraform
Terraform’s cidrsubnet function accepts an original CIDR block, the number of additional subnet bits, and a subnet number. For example, cidrsubnet("192.168.0.0/16", 2, 1) returns 192.168.64.0/18; cidrnetmask returns 255.255.192.0. section 10.2.1
A practical network module can derive public and private subnet blocks from one input CIDR. A two-segment design uses one additional bit, assigns separate subnet numbers, enables public IP mapping on the public subnet, and routes private traffic through a NAT gateway. section 10.2.3
Operational considerations:
- Research provider-specific networking resources before designing a module; Terraform’s IP-network functions remain provider-independent. section 10.2.1
- Treat NAT gateways as simple but potentially expensive; NAT instances can reduce cost while requiring more involved setup. section 10.2.3




