Introduction
When I first heard about VPC (Virtual Private Cloud), it felt overwhelming — CIDR blocks, subnets, gateways, and route tables sounded too complex. But once I broke it down and actually launched an EC2 instance inside a custom VPC, everything started making sense.
In this blog, We'll learn:
- What a VPC is and why we use it
- Key components like subnets, gateways, and routing
- How to create a VPC step-by-step
- How to launch an EC2 instance inside it and test the internet connection
What is a VPC?
A VPC (Virtual Private Cloud) is our own private space in the AWS cloud.Like our own virtual data center, where all our resources (EC2, databases, etc.) live — securely and privately.
VPC Components and its Explanation:
| Component | Description |
| -------------------------- | ---------------------------------------------------------------------- |
| VPC | our private cloud with a defined IP range |
| Public Subnet | A subnet that can access the internet |
| Private Subnet | A subnet isolated from the internet |
| Internet Gateway (IGW) | Enables resources in public subnet to access the internet |
| NAT Gateway | Allows private subnet resources to access the internet (outbound only) |
| Route Table | Controls routing decisions for subnets |
| Subnet Association | Binds a route table to a specific subnet |
| CIDR | IP address range for our VPC (like 10.0.0.0/16) |
What is CIDR?
CIDR (Classless Inter-Domain Routing) defines the size of the IP address block for our VPC or subnet.
For example:
- 10.0.0.0/16 gives you ~65,000 IPs
- 10.0.1.0/24 gives you 256 IPs
In AWS, VPC CIDRs can range from /16 (biggest) to /28 (smallest). For our demo, we’ll use 10.0.0.0/16.
Step-by-Step: Create a Custom VPC and Launch EC2:
Create a VPC
- Go to VPC Dashboard
- Click Create VPC
- Choose:
- Name:
my-custom-vpc
- IPv4 CIDR block:
10.0.0.0/16
- Click Create
Now we have a VPC with 65,536 IPs!
Create a Public Subnet
- Go to Subnets > Create Subnet
- Choose our VPC:
my-custom-vpc
- CIDR block:
10.0.1.0/24
- Availability Zone: (Choose one)
- Enable auto-assign public IPv4 address
Create and Attach an Internet Gateway (IGW)
- Go to Internet Gateways > Create IGW
- Name it:
my-igw
- Click Create and then Attach to VPC → Choose my-custom-vpc
Create a Route Table
- Go to Route Tables > Create
- Name it:
my-public-rt
- Choose my-custom-vpc
- After creating, click Edit Routes:
- Add route: Destination 0.0.0.0/0, Target Internet Gateway
- Go to Subnet Associations, attach our Public Subnet
- Now our public subnet is internet-enabled.
Launch EC2 inside VPC
- Go to EC2 > Launch Instance
- Choose:
- Name:
my-ec2
- Amazon Linux 2
- Instance type:
t2.micro
(Free Tier) - Key pair: Create or choose existing
- Network: Choose my-custom-vpc
- Subnet: Choose my-public-subnet
- Auto-assign Public IP: Enable
- Add Security Group rule:
- Allow SSH from our IP
- Optional: Allow HTTP/HTTPS
- Launch the instance
Connect to EC2 and Test Internet:
- Open Git Bash or terminal
- Run
chmod 400 your-key.pem
ssh -i your-key.pem ec2-user@<your-public-ip>
- After login:
ping google.com
- If we can see replies, our EC2 is connected to the internet via our custom VPC!
Points to Remember:
- Every subnet must be within the VPC’s CIDR range
- Public subnets require an IGW + correct route table
- Auto-assigning Public IP is essential for internet access
- Security groups act like firewalls — allow only what we need
Thanks for reading!
If you’re just getting started with AWS, this guide should help you take that first confident step into cloud networking.And wait for the next part of Connecting with Private Subnet and NAT Gateway..!
Happy cloud building! ☁️💻🚀