44

I have tried every combination of IP ranges for my CIDR block on my new VPC for AWS.

My current CIDR is 172.31.0.0/16

171.31.0.0/32 (CIDR Address is not within CIDR Address from VPC)
Jeff Voss
  • 3,637
  • 8
  • 46
  • 71
  • 2
    Appears like a correct error to me. You should read up on IP subnets and CIDR as 171.x.x.x is clearly not within 172.31.x.x. – dmulter Aug 07 '18 at 20:54

3 Answers3

76

An IPv4 address consists of 32 bits.

1) /32 in CIDR x.x.x.x/32 means use all 32 bits to form a range of addresses. In this case just one IP address is possible.

2) /24 in CIDR x.x.x.0/24 means fix the first 24 bits and use last 8 bits to form a range of addresses. In this case, there can be 2^8 IP addresses i.e. from x.x.x.0 to x.x.x.255.

3) /16 in CIDR x.x.0.0/16 means fix the first 16 bits and use the last 16 bits to form a range of addresses. In this case, there can be 2^16 IP addresses i.e. from x.x.0.0 to x.x.255.255.

4) /8 in CIDR x.0.0.0/8 means fix the first 8 bits and use the last 24 bits to form a range of addresses. In this case, there can be 2^24 IP addresses i.e. from x.0.0.0 to x.255.255.255.

5) /0 in CIDR 0.0.0.0/0 means fix the first 0 bits and use the last 32 bits to form a range of addresses. In this case, all the possible IP addresses are included in the range.

Hope it helps you in understanding your problem that first 16 bits needs to be fixed in x.x.0.0/16 CIDR.

Oden
  • 628
  • 6
  • 14
Manmohan Bohara
  • 916
  • 8
  • 8
21

A CIDR range ending in /16 means the last two numbers can change.

In your case, the range would be: 172.31.x.x

Thus, 171.31.0.0 is not in that CIDR range.

By the way, you probably don't want to create a VPC with a /16 range. It contains over 65,000 IP addresses and would make it difficult to peer with other VPC you might create in future. You could probably use a smaller (eg /22) CIDR range.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
0

https://www.ipaddressguide.com/cidr

This is a CIDR to IPV4 calculator if you wanna skip all manual calculation.

For example, if you're trying to create a subnet and it asks for it the IPv4 CIDR block then you would:

  • go to the calculator and enter your CIDR number. E.g.: 171.31.0.0/16
  • pick an IP between the first IP and last IP. E.g.: 171.31.255.254
  • Put the IP address in the IPv4 CIDR block field.

That should work.

Joseph Hui
  • 573
  • 6
  • 11