I am trying to create a subnet within a default VPC.
The IPv4 CIDR block I am using is 172.31.56.0/22 but it keeps saying it overlaps with existing subnet CIDR block: 172.31.48.0/20.
what am I doing wrong?
I’ve tried /24 also and still the same error.
2
Answers
Let’s have look at below image to understand how CIDR works.
Your existing subnet CIDR is
172.31.48.0/20
, which means it holds 2 to the Power of 12 IP addresses, that is equal to 4096.Here is the range of your existing subnet. Screenshot captured from https://www.ipaddressguide.com/cidr website.
So, now if you want to create a new subnet with 256 IP addresses, then you can create it either before
172.31.48.0
or after172.31.63.255
IP addresses.For example, below CIDR examples will work for you.
And a lot more combinations you can try by your own.
You mention a CIDR of
172.31.48.0/20
. It goes from172.31.48.0
to172.31.63.255
.The CIDR of
172.31.56.0/22
goes from172.31.56.0
to172.31.59.255
.As you can see, they overlap.
When dealing with CIDRs, it’s a good idea to use a CIDR calculator such as cidr.xyz.
By the way, a Default VPC normally has a CIDR of
172.30.0.0/16
. The CIDRs you mention are unlikely to be an AWS-provided Default VPC.