A VPC (Virtual Private Cloud) is your own private network inside AWS where you can launch resources like EC2 instances, RDS databases, Load Balancers, and more.
VPC Architecture
Internet │ Internet_Gateway │ +----------------+ | VPC | | 10.0.0.0/16 | +----------------+ │ │ Public Subnet Private Subnet 10.0.1.0/24 10.0.2.0/24 │ │ EC2 Server Database Server │ Public IP Address
Step 1: Login to AWS Console
- Login to AWS
- Search VPC
- Open VPC Dashboard
Step 2: Create VPC
Click
Create VPC
Choose
VPC only
Fill details
| Field | Value |
|---|---|
| Name | My-VPC |
| IPv4 CIDR | 10.0.0.0/16 |
| IPv6 | None |
| Tenancy | Default |
Click
Create VPC
Your VPC is ready.
Step 3: Create Public Subnet
Go to
Subnets → Create subnet
Choose your VPC
Enter
| Field | Value |
|---|---|
| Name | Public-Subnet |
| Availability Zone | ap-south-1a |
| IPv4 CIDR | 10.0.1.0/24 |
Click
Create Subnet
Step 4: Create Private Subnet
Again click
Create Subnet
| Field | Value |
|---|---|
| Name | Private-Subnet |
| AZ | ap-south-1b |
| CIDR | 10.0.2.0/24 |
Click
Create
Step 5: Create Internet Gateway
Go to
Internet Gateways
Click
Create Internet Gateway
Name
My-IGW
Click
Create
Now
Select the IGW
Click
Actions → Attach to VPC
Choose
My-VPC
Done.
Step 6: Create Route Table
Go to
Route Tables
Click
Create Route Table
Name
Public-RouteTable
Select
My-VPC
Create.
Step 7: Add Internet Route
Open the Route Table
Click
Routes → Edit Routes
Add
| Destination | Target |
|---|---|
| 0.0.0.0/0 | Internet Gateway |
Save.
This route means:
"Send all internet traffic through the Internet Gateway."
Step 8: Associate Public Subnet
Inside Route Table
Choose
Subnet Associations
Click
Edit
Select
Public-Subnet
Save.
Now only this subnet has internet access.
Step 9: Enable Auto-Assign Public IP
Go to
Subnets
Select
Public-Subnet
Choose
Edit subnet settings
Enable
✅ Auto-assign Public IPv4
Save.
Step 10: Launch EC2 Instance
Go to EC2
Launch Instance
Choose
- Amazon Linux
- t2.micro (Free Tier)
Under Network
Select
My-VPC
Select
Public-Subnet
Enable
Assign Public IP = Enabled
Launch.
Now your EC2 can access the internet.
Final Architecture
Internet │ Internet Gateway │ ----------------------------- | My-VPC | | 10.0.0.0/16 | | | | Public Subnet | | 10.0.1.0/24 | | │ | | EC2 (Public IP) | | | |---------------------------| | Private Subnet | |10.0.2.0/24 | | │ | | RDS / Private EC2 | -----------------------------
Components Summary
| Component | Purpose |
|---|---|
| VPC | Creates your private AWS network |
| Subnet | Divides the VPC into smaller networks |
| Public Subnet | Resources can access the internet |
| Private Subnet | Resources stay isolated from the internet |
| Internet Gateway | Connects the VPC to the internet |
| Route Table | Controls where network traffic goes |
| Security Group | Instance-level firewall |
| Network ACL | Subnet-level firewall |
Best Practices
- Use separate public and private subnets.
- Keep databases (RDS) in private subnets.
- Allow only necessary ports in Security Groups (e.g., SSH: 22, HTTP: 80, HTTPS: 443).
-
Use CIDR blocks that don't overlap with other networks (e.g.,
10.0.0.0/16). - Use at least two Availability Zones for high availability.
- For private subnets that need outbound internet access (e.g., software updates), use a NAT Gateway in a public subnet instead of exposing them directly.
Interview Questions
- What is a VPC?
- What is the difference between a public and private subnet?
- What is an Internet Gateway?
- What is the purpose of a Route Table?
- Why do we use CIDR notation?
- What is the difference between a Security Group and a Network ACL?
- Can an EC2 instance in a private subnet access the internet? (Yes, via a NAT Gateway if configured.)
- Why should databases be placed in a private subnet?
- Can multiple subnets exist in one VPC? (Yes.)
- What happens if you don't attach an Internet Gateway to a VPC?
This workflow creates a basic, production-style VPC that you can use for hosting web applications while keeping backend services such as databases securely isolated.
AWS VPC Creation – Step-by-Step Checklist
| Step |
|---|
