Loading...
Split a VPC CIDR into evenly-sized subnets across AZs — network, range, and host counts per subnet, with leftover space shown. Plan before you Terraform.
/24 splits your block into up to 256 subnets of 256 addresses (251 usable each).
| # | CIDR | Range | Usable |
|---|---|---|---|
| 1 | 10.0.0.0/24 | 10.0.0.0 – 10.0.0.255 | 251 |
| 2 | 10.0.1.0/24 | 10.0.1.0 – 10.0.1.255 | 251 |
| 3 | 10.0.2.0/24 | 10.0.2.0 – 10.0.2.255 | 251 |
| 4 | 10.0.3.0/24 | 10.0.3.0 – 10.0.3.255 | 251 |
| 5 | 10.0.4.0/24 | 10.0.4.0 – 10.0.4.255 | 251 |
| 6 | 10.0.5.0/24 | 10.0.5.0 – 10.0.5.255 | 251 |
Spread these across AZs (e.g. 3 public + 3 private). AWS reserves the first 4 and last address of every subnet.
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
}
locals {
subnet_cidrs = ["10.0.0.0/24", "10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24", "10.0.4.0/24", "10.0.5.0/24"]
}
resource "aws_subnet" "this" {
count = length(local.subnet_cidrs)
vpc_id = aws_vpc.main.id
cidr_block = local.subnet_cidrs[count.index]
availability_zone = element(["a", "b", "c"], count.index) # map to real AZs
}