published: true
description: "What a VPC is, how CIDR notation works, and how to choose a CIDR block that won't cause problems later with subnets, peering or VPN."
tags: aws, devops, networking, beginners
canonical_url:https://builder.aws.com/content/3MUND2CiPe78JKgXIysnCjkevcC/aws-vpc-and-cidr-blocks-explained-plan-your-network-the-right-way
This article was first published on AWS Builder Center. Sharing it here for the dev.to community.
Introduction
Every resource you launch on AWS, such as an EC2 instance, an RDS database or a Jenkins server, lives inside a VPC (Virtual Private Cloud). And every VPC starts with one important decision: its CIDR block.
Beginners often click "Create VPC", accept a default range, and move on. Later they hit problems: no free IP addresses, subnets that overlap, or two VPCs that can't be connected. In this post I explain what a VPC is, what CIDR notation means, and how to choose a CIDR block that won't cause trouble later.
What is a VPC?
A VPC is your own logically isolated network inside AWS. You control:
- The IP address range
- The subnets (smaller networks inside the VPC)
- The route tables, gateways and firewalls
Think of AWS as a big city and your VPC as your own gated community. You decide how many streets (subnets) it has, who can enter (gateways), and who can talk to whom (security groups and NACLs).
A few key facts:
- A VPC belongs to one Region and spans all Availability Zones in that Region
- A subnet belongs to one Availability Zone
- Every AWS account gets a default VPC in each Region (CIDR
172.31.0.0/16) - You can create custom VPCs for your projects
What is a CIDR Block?
CIDR (Classless Inter-Domain Routing) is a way of writing an IP range in short form:
10.0.0.0/16
It has two parts:
-
10.0.0.0is the network address (where the range starts) -
/16is the prefix length (how many bits are fixed for the network)
An IPv4 address has 32 bits. The smaller the prefix number, the bigger the network:
Total IPs = 2^(32 - prefix)
| CIDR | Calculation | Total IPs |
|---|---|---|
| /16 | 2^16 | 65,536 |
| /20 | 2^12 | 4,096 |
| /24 | 2^8 | 256 |
| /28 | 2^4 | 16 |
AWS limits: A VPC CIDR block must be between /16 and /28.
Private IP Ranges to Use (RFC 1918)
For a VPC, use the private IP ranges:
| Range | CIDR | Size |
|---|---|---|
| 10.0.0.0 – 10.255.255.255 | 10.0.0.0/8 | Very large |
| 172.16.0.0 – 172.31.255.255 | 172.16.0.0/12 | Medium |
| 192.168.0.0 – 192.168.255.255 | 192.168.0.0/16 | Small |
Most teams choose something from 10.x.x.x, for example 10.0.0.0/16, because it gives plenty of room.
From VPC CIDR to Subnets
Once you have a VPC CIDR, you divide it into subnets. Each subnet CIDR must fit inside the VPC CIDR and must not overlap with other subnets.
Example: VPC 10.0.0.0/16
| Subnet | CIDR | AZ | Type |
|---|---|---|---|
| public-subnet-1 | 10.0.1.0/24 | ap-south-1a | Public |
| public-subnet-2 | 10.0.2.0/24 | ap-south-1b | Public |
| private-subnet-1 | 10.0.11.0/24 | ap-south-1a | Private |
| private-subnet-2 | 10.0.12.0/24 | ap-south-1b | Private |
Each /24 subnet has 256 addresses.
The 5 Reserved IPs in Every Subnet
AWS reserves 5 IP addresses in every subnet, so you can't use them. For 10.0.1.0/24:
| IP | Purpose |
|---|---|
| 10.0.1.0 | Network address |
| 10.0.1.1 | VPC router |
| 10.0.1.2 | DNS server |
| 10.0.1.3 | Reserved for future use |
| 10.0.1.255 | Broadcast address (not supported, but reserved) |
So a /24 subnet gives 251 usable IPs, not 256. A /28 subnet gives only 11.
How to Choose the Right CIDR Block
1. Don't go too small
You can add secondary CIDR blocks to a VPC later, but it's much easier to start with enough room. /16 is a safe choice for most projects.
2. Avoid overlapping ranges
This is the most common mistake. If two VPCs, or your VPC and your office network, use the same range, you cannot connect them using VPC Peering, Transit Gateway or VPN.
Bad plan:
- Dev VPC:
10.0.0.0/16 - Prod VPC:
10.0.0.0/16(overlap, so peering is not possible)
Good plan:
- Dev VPC:
10.0.0.0/16 - Test VPC:
10.1.0.0/16 - Prod VPC:
10.2.0.0/16
3. Avoid the default VPC range for real projects
The default VPC uses 172.31.0.0/16, and many people also use it, so it often clashes later.
4. Plan for multiple Availability Zones
Create at least 2 public and 2 private subnets across 2 AZs for high availability.
5. Leave spare room
Don't use up the whole range. Keep some unused blocks for future subnets such as database, cache or management tiers.
6. Document your plan
Keep a simple table of VPC and subnet ranges. It saves hours of troubleshooting.
Hands-On: Create a VPC with a Custom CIDR
- Open the AWS Console and go to VPC → Your VPCs → Create VPC.
- Choose VPC only.
- Enter the name
demo-vpcand the IPv4 CIDR10.0.0.0/16. - Click Create VPC.
- Go to Subnets → Create subnet, select
demo-vpcand create:-
public-subnet-1:10.0.1.0/24in AZ 1 -
private-subnet-1:10.0.11.0/24in AZ 1
-
- Create an Internet Gateway, attach it to
demo-vpc, and add the route0.0.0.0/0 → IGWto the public subnet's route table. - Launch an EC2 instance in each subnet and check the private IPs they receive. They should fall inside the subnet ranges.
- Clean up: delete the EC2 instances, Internet Gateway, subnets and VPC.
Common Mistakes to Avoid
- Choosing a CIDR that is too small and running out of IPs
- Using the same CIDR in two VPCs you plan to connect
- Forgetting that AWS reserves 5 IPs per subnet
- Creating subnets that overlap with each other
- Assuming a subnet is public just because of its name (it needs a route to an Internet Gateway)
- Using a public IP range as your VPC CIDR
Quick Summary
| Concept | Remember this |
|---|---|
| VPC | Your isolated network, in one Region, across all AZs |
| CIDR | IP range written as IP/prefix, e.g. 10.0.0.0/16 |
| VPC size | Between /16 and /28 |
| Subnet | A slice of the VPC CIDR, in one AZ |
| Reserved IPs | 5 per subnet |
| Golden rule | Never overlap CIDR ranges |
Conclusion
A VPC is the base of your AWS architecture, and the CIDR block is the foundation of the VPC. A few minutes of planning at the start can save you from painful redesigns later, especially when you need VPC Peering, Transit Gateway or VPN. Choose a private range, keep it big enough, avoid overlaps, and document it.
In my next posts I'll cover public vs private subnets, route tables and VPC Endpoints. Follow along if you're learning AWS networking too.
Connect with me:
- LinkedIn: Vishal Patil
- GitHub: VishalPatil-DevOps-AWS
- dev.to: @vishal_patil_aws
