Fundamental VPC Concepts
What is a VPC?
A VPC (Virtual Private Cloud) is your virtual private network in AWS. It's an isolated network space where you deploy your AWS resources.
┌─────────────────────────────────────────────────────────────┐
│ AMAZON VPC │
├─────────────────────────────────────────────────────────────┤
│ │
│ "Your virtual datacenter in the cloud" │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ VPC (10.0.0.0/16) │ │
│ │ │ │
│ │ Your private and isolated network space │ │
│ │ │ │
│ │ ┌─────────────┐ ┌─────────────┐ │ │
│ │ │ Subnet 1 │ │ Subnet 2 │ │ │
│ │ │ 10.0.1.0/24 │ │ 10.0.2.0/24 │ │ │
│ │ │ │ │ │ │ │
│ │ │ ┌─────┐ │ │ ┌─────┐ │ │ │
│ │ │ │ EC2 │ │ │ │ RDS │ │ │ │
│ │ │ └─────┘ │ │ └─────┘ │ │ │
│ │ │ │ │ │ │ │
│ │ └─────────────┘ └─────────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ Features: │
│ • Isolated from other VPCs and the Internet (by default) │
│ • You control the IP address range │
│ • You define the security rules │
│ • Regional (spans all AZs in the region) │
│ │
└─────────────────────────────────────────────────────────────┘
Analogy: VPC = Office Building
┌─────────────────────────────────────────────────────────────┐
│ ANALOGY: OFFICE BUILDING │
├─────────────────────────────────────────────────────────────┤
│ │
│ REAL WORLD AWS │
│ ────────── ─── │
│ │
│ 🏢 Building = VPC │
│ (your private space) (your private network) │
│ │
│ 🚪 Floors = Subnets │
│ (internal divisions) (sub-networks) │
│ │
│ 🔐 Reception/Security = Internet Gateway │
│ (controlled entry) (Internet access) │
│ │
│ 📋 Access badge = Security Group │
│ (who can enter where) (firewall rules) │
│ │
│ 🗺️ Evacuation plan = Route Table │
│ (traffic paths) (traffic routing) │
│ │
│ 🏠 Offices = EC2 Instances │
│ (workspaces) (your servers) │
│ │
└─────────────────────────────────────────────────────────────┘
Components of a VPC
Overview
┌─────────────────────────────────────────────────────────────┐
│ VPC COMPONENTS │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ VPC │ │
│ │ (container) │ │
│ │ │ │
│ │ ┌─────────────┐ ┌─────────────┐ │ │
│ │ │ SUBNET │ │ SUBNET │ ← Subnets │ │
│ │ │ (public) │ │ (private) │ │ │
│ │ └──────┬──────┘ └──────┬──────┘ │ │
│ │ │ │ │ │
│ │ └────────┬───────┘ │ │
│ │ │ │ │
│ │ ┌────────┴────────┐ │ │
│ │ │ ROUTE TABLE │ ← Where traffic goes │ │
│ │ └────────┬────────┘ │ │
│ │ │ │ │
│ │ ┌───────────────┼───────────────┐ │ │
│ │ │ │ │ │ │
│ │ ▼ ▼ ▼ │ │
│ │ ┌─────┐ ┌─────────┐ ┌──────────┐ │ │
│ │ │ IGW │ │ NAT │ │ VPC │ │ │
│ │ │ │ │ Gateway │ │ Peering │ │ │
│ │ └─────┘ └─────────┘ └──────────┘ │ │
│ │ Internet Outbound for Other VPC │ │
│ │ private subnet │ │
│ │ │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
Component Table
| Component | Description | Mandatory |
|---|---|---|
| VPC | Isolated virtual network | Yes |
| Subnet | Subnet in an AZ | Yes (at least 1) |
| Route Table | Routing rules | Yes (auto-created) |
| Internet Gateway | Internet access | No (if private) |
| NAT Gateway | Internet outbound for private | No |
| Security Group | Instance-level firewall | Yes |
| NACL | Subnet-level firewall | Yes (default) |
Default VPC vs Custom VPC
┌─────────────────────────────────────────────────────────────┐
│ DEFAULT VPC vs CUSTOM VPC │
├─────────────────────────────────────────────────────────────┤
│ │
│ DEFAULT VPC CUSTOM VPC │
│ ────────────── ──────────────── │
│ │
│ • Automatically created • You create it │
│ • 1 per region • As many as you want │
│ • CIDR: 172.31.0.0/16 • CIDR: you choose │
│ • Auto public subnets • You configure everything │
│ • IGW attached • You attach the IGW │
│ │
│ When to use: When to use: │
│ ✅ Quick tests ✅ Production │
│ ✅ Learning ✅ Enhanced security │
│ ❌ Production ✅ Multi-tier │
│ │
│ ⚠️ In production, ALWAYS use a custom VPC for better │
│ security control │
│ │
└─────────────────────────────────────────────────────────────┘
IP Address Range (CIDR)
What is CIDR?
┌─────────────────────────────────────────────────────────────┐
│ CIDR NOTATION │
├─────────────────────────────────────────────────────────────┤
│ │
│ CIDR = Classless Inter-Domain Routing │
│ │
│ Format: NETWORK_ADDRESS / PREFIX │
│ │
│ Example: 10.0.0.0/16 │
│ │ │ │
│ │ └── 16 fixed bits (network) │
│ │ 16 variable bits (hosts) │
│ │ │
│ └── Starting network address │
│ │
│ Calculating the number of addresses: │
│ Formula: 2^(32 - prefix) │
│ │
│ /16 = 2^(32-16) = 2^16 = 65,536 addresses │
│ /24 = 2^(32-24) = 2^8 = 256 addresses │
│ /28 = 2^(32-28) = 2^4 = 16 addresses │
│ │
└─────────────────────────────────────────────────────────────┘
Private Ranges (RFC 1918)
┌─────────────────────────────────────────────────────────────┐
│ PRIVATE IP RANGES (RFC 1918) │
├─────────────────────────────────────────────────────────────┤
│ │
│ These ranges are NOT routed on the Internet │
│ → Use them for your VPCs │
│ │
│ CLASS A: 10.0.0.0/8 │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ 10.0.0.0 → 10.255.255.255 │ │
│ │ 16,777,216 addresses │ │
│ │ Usage: Large enterprises │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ CLASS B: 172.16.0.0/12 │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ 172.16.0.0 → 172.31.255.255 │ │
│ │ 1,048,576 addresses │ │
│ │ Usage: Medium enterprises │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ CLASS C: 192.168.0.0/16 │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ 192.168.0.0 → 192.168.255.255 │ │
│ │ 65,536 addresses │ │
│ │ Usage: Home networks, small businesses │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ RECOMMENDATION FOR AWS: │
│ Use 10.0.0.0/16 to start (65,536 addresses) │
│ │
└─────────────────────────────────────────────────────────────┘
AWS VPC Sizes
| CIDR | Addresses | Recommended Usage |
|---|---|---|
| /16 | 65,536 | Standard VPC, recommended |
| /20 | 4,096 | Medium VPC |
| /24 | 256 | Small VPC, test |
| /28 | 16 | Minimum AWS |
AWS Limits
- Minimum CIDR: /28 (16 addresses)
- Maximum CIDR: /16 (65,536 addresses)
- A VPC can have multiple CIDRs (up to 5)
AWS Reserved Addresses
┌─────────────────────────────────────────────────────────────┐
│ AWS RESERVED ADDRESSES PER SUBNET │
├─────────────────────────────────────────────────────────────┤
│ │
│ For each subnet, AWS reserves 5 addresses: │
│ │
│ Example: Subnet 10.0.1.0/24 (256 addresses) │
│ │
│ 10.0.1.0 → Network address │
│ 10.0.1.1 → Reserved by AWS (VPC router) │
│ 10.0.1.2 → Reserved by AWS (DNS) │
│ 10.0.1.3 → Reserved by AWS (future use) │
│ 10.0.1.255 → Broadcast (not supported but reserved) │
│ │
│ Usable addresses: 256 - 5 = 251 addresses │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Subnet /24: 251 usable addresses │ │
│ │ Subnet /25: 123 usable addresses │ │
│ │ Subnet /26: 59 usable addresses │ │
│ │ Subnet /27: 27 usable addresses │ │
│ │ Subnet /28: 11 usable addresses │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
Typical VPC Architecture
┌─────────────────────────────────────────────────────────────────────────┐
│ 3-TIER VPC ARCHITECTURE │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ INTERNET │
│ │ │
│ ▼ │
│ ┌───────────────┐ │
│ │Internet Gateway│ │
│ └───────┬───────┘ │
│ │ │
│ ┌─────────────────────────────┼─────────────────────────────┐ │
│ │ VPC │(10.0.0.0/16) │ │
│ │ │ │ │
│ │ ┌─────────────────────────┴─────────────────────────┐ │ │
│ │ │ PUBLIC SUBNETS │ │ │
│ │ │ │ │ │
│ │ │ ┌─────────────────┐ ┌─────────────────┐ │ │ │
│ │ │ │ Public 1a │ │ Public 1b │ │ │ │
│ │ │ │ 10.0.1.0/24 │ │ 10.0.2.0/24 │ │ │ │
│ │ │ │ │ │ │ │ │ │
│ │ │ │ [ALB/NAT] │ │ [ALB/NAT] │ │ │ │
│ │ │ │ │ │ │ │ │ │
│ │ │ └────────┬────────┘ └────────┬────────┘ │ │ │
│ │ │ │ │ │ │ │
│ │ └───────────┼──────────────────────┼─────────────────┘ │ │
│ │ │ │ │ │
│ │ ┌───────────┼──────────────────────┼─────────────────┐ │ │
│ │ │ │ PRIVATE SUBNETS (App)│ │ │ │
│ │ │ │ │ │ │ │
│ │ │ ┌────────▼────────┐ ┌────────▼────────┐ │ │ │
│ │ │ │ Private 1a │ │ Private 1b │ │ │ │
│ │ │ │ 10.0.11.0/24 │ │ 10.0.12.0/24 │ │ │ │
│ │ │ │ │ │ │ │ │ │
│ │ │ │ [EC2 App] │ │ [EC2 App] │ │ │ │
│ │ │ │ │ │ │ │ │ │
│ │ │ └────────┬────────┘ └────────┬────────┘ │ │ │
│ │ │ │ │ │ │ │
│ │ └───────────┼──────────────────────┼─────────────────┘ │ │
│ │ │ │ │ │
│ │ ┌───────────┼──────────────────────┼─────────────────┐ │ │
│ │ │ │ PRIVATE SUBNETS (DB) │ │ │ │
│ │ │ │ │ │ │ │
│ │ │ ┌────────▼────────┐ ┌────────▼────────┐ │ │ │
│ │ │ │ Database 1a │ │ Database 1b │ │ │ │
│ │ │ │ 10.0.21.0/24 │ │ 10.0.22.0/24 │ │ │ │
│ │ │ │ │ │ │ │ │ │
│ │ │ │ [RDS] │ │ [RDS Standby] │ │ │ │
│ │ │ │ │ │ │ │ │ │
│ │ │ └─────────────────┘ └─────────────────┘ │ │ │
│ │ │ │ │ │
│ │ └────────────────────────────────────────────────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────┘
Create a VPC
Via Console
1. VPC → Your VPCs → Create VPC
2. Name tag: my-vpc-prod
3. IPv4 CIDR block: 10.0.0.0/16
4. Tenancy: Default
5. Create VPC
Via AWS CLI
# Create the VPC
aws ec2 create-vpc \
--cidr-block 10.0.0.0/16 \
--tag-specifications 'ResourceType=vpc,Tags=[{Key=Name,Value=my-vpc-prod}]'
# Enable DNS names (recommended)
aws ec2 modify-vpc-attribute \
--vpc-id vpc-xxx \
--enable-dns-hostnames '{"Value":true}'
Summary
| Concept | Description |
|---|---|
| VPC | Isolated virtual private network |
| CIDR | Notation to define the IP range |
| Subnet | Subdivision of the VPC in an AZ |
| /16 | Recommended size (65,536 IPs) |
| RFC 1918 | Private IP ranges to use |
| 5 reserved IPs | AWS reserves 5 IPs per subnet |
Validation Quiz
- What is a VPC?
- How many IP addresses in a /24?
- Why does AWS reserve 5 addresses per subnet?
- What IP range to use for a VPC?
- What is the difference between default and custom VPC?
Next section: Subnets and Routing