Skip to content

How to calculate the VPC subnet CIDRs?

To calculate subnets this calculator can be used

Note in this link a few params were added: the base network and mask, and the division number. In this case the example is for the shared account networking.

This table will be shown: subnet-cidr-calculator

Note how this information is set in the tf file:

  vpc_cidr_block = ""
  azs = [

  private_subnets_cidr = [""]
  private_subnets = [

  public_subnets_cidr = [""]
  public_subnets = [

Note the main CIDR is being used for the VPC. See on the left how the /20 encompasses all the rows.

Then two divisions for /21. Note the first subnet address of the first row for each one is being used for private_subnets_cidr and public_subnets_cidr.

Finally the /23 are being used for each subnet.

Note we are using the first two subnet addresses for each /21. This is due to we are reserving the other two to allow adding more AZs in the future. (up to two in this case)

If you want you can take as a reference this page to select CIDRs for each account.