title: CIDR blocks for AWS VPC and its subnets
body: <p>I have a CIDR block of 172.30.0.0/21 and need to create 2 private subnets and then 2 public subnets for it.</p>
  <p>At first I created:
  for private: [&quot;172.30.8.0/21&quot;, &quot;172.30.16.0/21&quot;]
  for public: [&quot;172.30.0.0/22&quot;, &quot;172.30.8.0/22&quot;]</p>
  <p>but then I got the following errors:</p>
  <pre><code>Error: Error creating subnet: InvalidSubnet.Range: The CIDR '172.30.8.0/22' is invalid.
  10:59:12    status code: 400, request id: 9***
  10:59:12  
  10:59:12    on .terraform/modules/vpc-us-west-2/main.tf line 335, in resource &quot;aws_subnet&quot; &quot;public&quot;:
  10:59:12   335: resource &quot;aws_subnet&quot; &quot;public&quot; {
  10:59:12  
  10:59:12  
  10:59:12  
  10:59:12  Error: Error creating subnet: InvalidSubnet.Range: The CIDR '172.30.16.0/21' is invalid.
  10:59:12    status code: 400, request id: d**
  10:59:12  
  10:59:12    on .terraform/modules/vpc-us-west-2/main.tf line 363, in resource &quot;aws_subnet&quot; &quot;private&quot;:
  10:59:12   363: resource &quot;aws_subnet&quot; &quot;private&quot; {
  10:59:12  
  10:59:12  
  10:59:12  
  10:59:12  Error: Error creating subnet: InvalidSubnet.Range: The CIDR '172.30.8.0/21' is invalid.
  10:59:12    status code: 400, request id: d**
  10:59:12  
  10:59:12    on .terraform/modules/vpc-us-west-2/main.tf line 363, in resource &quot;aws_subnet&quot; &quot;private&quot;:
  10:59:12   363: resource &quot;aws_subnet&quot; &quot;private&quot; {
  </code></pre>
  <p>So NOW:-</p>
  <ul>
  <li>I created:</li>
  </ul>
  <p>for private:[&quot;172.30.0.0/21&quot;, &quot;172.30.4.0/21&quot;]
  for public: [&quot;172.30.0.0/22&quot;, &quot;172.30.2.0/22&quot;]</p>
  <p>are they fine? will they work and fix the errors?</p>
  <ul>
  <li>This is part of my code:</li>
  </ul>
  <pre><code># List of private subnets to create in the environment, e.g. [&quot;172.18.0.0/21&quot;, &quot;172.18.8.0/21&quot;]
  variable &quot;private_subnets-west-2&quot; {
    type    = list(string)
    default = [&quot;172.30.0.0/22&quot;, &quot;172.30.6.0/23&quot;]
  }
  
  # List of public subnets to create in the environment, e.g. [&quot;172.18.168.0/22&quot;, &quot;172.18.172.0/22&quot;]
  variable &quot;public_subnets-west-2&quot; {
    type    = list(string)
    default = [&quot;172.30.0.0/22&quot;, &quot;172.30.4.0/23&quot;]
  }
  </code></pre>
  <p>(the values currently in the subnets, I am not sure they work)</p>
  <p>and these are the subnets I need to create. Again my CIDR is 172.30.0.0/21</p>
  <p>Update: my private subnets work fine:</p>
  <pre><code># List of private subnets to create in the environment, e.g. [&quot;172.18.0.0/21&quot;, &quot;172.18.8.0/21&quot;]
  variable &quot;private_subnets-west-2&quot; {
    type    = list(string)
    default = [&quot;172.30.0.0/22&quot;, &quot;172.30.6.0/23&quot;]
  }
  </code></pre>
  <p>However, I have been trying different subnets for my public one's since an hour now, and cannot find the proper ones:</p>
  <pre><code>
  # List of public subnets to create in the environment, e.g. [&quot;172.18.168.0/22&quot;, &quot;172.18.172.0/22&quot;]
  variable &quot;public_subnets-west-2&quot; {
    type    = list(string)
    default = [&quot;172.30.0.64/26&quot;, &quot;172.30.0.128/26&quot;]
  }
  </code></pre>
  <p>keep on getting errors for conflict or invalid:</p>
  <pre><code>Error: Error creating subnet: InvalidSubnet.Conflict: The CIDR '172.30.0.128/26' conflicts with another subnet
          status code: 400, request id:
  
    on .terraform/modules/vpc-us-west-2/main.tf line 335, in resource &quot;aws_subnet&quot; &quot;public&quot;:
   335: resource &quot;aws_subnet&quot; &quot;public&quot; {
  
  Error: Error creating subnet: InvalidSubnet.Conflict: The CIDR '172.30.0.64/26' conflicts with another subnet
          status code: 400, request id: 
  
    on .terraform/modules/vpc-us-west-2/main.tf line 335, in resource &quot;aws_subnet&quot; &quot;public&quot;:
   335: resource &quot;aws_subnet&quot; &quot;public&quot; {
  </code></pre>
  <p>I have been stuck for long, if someone can help me and tell me exactly which 2 subnets I can use, it would be great help!</p>