Erraform AWS VPC module - Understanding subnet separation

HI friends, im creating a new VPC using the terraform <> module.

I would like to understand the separation of the subnets a little better.

public_subnets   = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 6, k + 4)]
database_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 6, k + 8)]```

In total i end up with 9 subnets. I chose /22 so that i have a larger 1024 available ip addresses to work with.

One thing i don't understand is the gap in between them for example. What is the purpose of this and why?


``` ->```


Is it just because IP subnetting is binary, and therefore splits subnets nicely in 2s/4s/8s etc, but because you’re using 3 x AZs, there is a “spare” subnet? “spare private subnet” “spare public subnet” “spare db subnet”

Assuming you chose as your VPC CIDR?

This tool helps with IP subnetting:

To clarify the cidr range is ""

ill take a look at that link, thanks

I think i still don’t understand the splitting of subnets you mention nicely in 2s/4s/8s.

Using that site i can divide it to 1022 hosts, i can see the subnet increments by 4s everytime.

But in the above example i have created using terraform i can see between public, private, db subnet groups there is a gap of 8, is there some reason for that?

I think it’s just the way the Terraform was written.

In terms of subnetting, using your example, if you allocate, you can’t then allocate is not a valid subnet, because it /21 boundary would be, i.e. overlapping with