HomeBlogAboutPricingContact🌐 δΈ­ζ–‡
← Back to HomeAWS
AWS VPC Tutorial: Virtual Private Cloud Setup, Subnets, Security Configuration [2025]

AWS VPC Tutorial: Virtual Private Cloud Setup, Subnets, Security Configuration [2025]

πŸ“‘ Table of Contents

AWS VPC Tutorial: Virtual Private Cloud Setup, Subnets, Security Configuration [2025]AWS VPC Tutorial: Virtual Private Cloud Setup, Subnets, Security Configuration [2025]

AWS VPC Tutorial: Virtual Private Cloud Setup, Subnets, Security Configuration [2025]

Why shouldn't your database have a public IP? Why should Web Servers and Databases be in different subnets? Why do identical security group settings sometimes allow connections and sometimes not? The answers to all these questions lie in VPC.

VPC is the foundation of AWS network architecture. Understanding VPC enables you to design secure, reliable cloud architectures. This article will guide you through VPC from the ground upβ€”from basic concepts and core components to actually building a standard three-tier architecture.



What is AWS VPC?

πŸ’‘ Key Takeaway: VPC (Virtual Private Cloud) is your private network in the AWS cloud. Think of it as carving out a dedicated area just for you within AWS's data center, with your own IP range, subnets, and routing rules.

Core Value of VPC

1. Isolation

VPCs are completely isolated from each other. Your resources can't be seen or accessed by other users.

2. Control

You have complete control over network settings:

3. Connectivity

VPCs can connect to:

VPC vs Traditional Networks

AspectTraditional Enterprise NetworkAWS VPC
Setup TimeWeeks to monthsMinutes
ScalabilityLimited by hardwareVirtually unlimited
ConfigurationPhysical devices + CLIAWS Console / API
CostHardware + maintenancePay as you go
Cross-regionRequires dedicated linesNative support

Why Do You Need VPC?

When you create EC2, RDS, Lambda, and other resources on AWS, they need a network environment. VPC is that environment.

Problems without VPC:

Benefits of VPC:



VPC Core Components

To understand VPC, you need to know these core components:

Subnets

A subnet is an IP address block within a VPC. Each subnet maps to one Availability Zone (AZ).

Public Subnet vs Private Subnet

FeaturePublic SubnetPrivate Subnet
Can receive internet trafficYesNo
Can initiate internet connectionYes (via IGW)Need NAT Gateway
What to place hereWeb Server, Bastion HostDatabase, App Server
Route table points toInternet GatewayNAT Gateway

Subnet Planning Example:

VPC: 10.0.0.0/16 (65,536 IPs)
β”‚
β”œβ”€β”€ Public Subnet 1:  10.0.1.0/24 (256 IP) - AZ-a
β”œβ”€β”€ Public Subnet 2:  10.0.2.0/24 (256 IP) - AZ-b
β”œβ”€β”€ Private Subnet 1: 10.0.11.0/24 (256 IP) - AZ-a
β”œβ”€β”€ Private Subnet 2: 10.0.12.0/24 (256 IP) - AZ-b
β”œβ”€β”€ DB Subnet 1:      10.0.21.0/24 (256 IP) - AZ-a
└── DB Subnet 2:      10.0.22.0/24 (256 IP) - AZ-b

Route Tables

Route tables determine where network traffic should go. Each subnet is associated with one route table.

Public Subnet Route Table:

DestinationTarget
10.0.0.0/16local (within VPC)
0.0.0.0/0igw-xxxxx (Internet Gateway)

Private Subnet Route Table:

DestinationTarget
10.0.0.0/16local
0.0.0.0/0nat-xxxxx (NAT Gateway)

Internet Gateway (IGW)

Internet Gateway allows resources within VPC to communicate with the internet.

Features:

Requirements for use:

  1. VPC has IGW attached
  2. Subnet route table has route pointing to IGW
  3. Instance has Public IP or Elastic IP
  4. Security group allows traffic

NAT Gateway

NAT Gateway allows private subnet resources to initiate connections to the internet (e.g., download updates), but internet cannot initiate connections in.

Features:

Architecture Diagram:

Internet
                        β”‚
                        β–Ό
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β”‚Internet Gatewayβ”‚
                β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚               β”‚               β”‚
        β–Ό               β–Ό               β–Ό
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ Public  β”‚    β”‚ Public  β”‚    β”‚   NAT   β”‚
   β”‚ Subnet  β”‚    β”‚ Subnet  β”‚    β”‚ Gateway β”‚
   β”‚(Web Tier)β”‚   β”‚(Web Tier)β”‚   β”‚         β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
                                      β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚ Private β”‚
              β”‚ Subnet  β”‚
              β”‚(App/DB) β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Security Groups

Security Groups are instance-level firewalls that control traffic entering and leaving instances.

Features:

Common Configuration Examples:

TypeProtocolPortSourceDescription
SSHTCP2210.0.0.0/16Only allow SSH from within VPC
HTTPTCP800.0.0.0/0Allow everyone HTTP
HTTPSTCP4430.0.0.0/0Allow everyone HTTPS
MySQLTCP3306sg-appOnly allow from App tier security group

Network ACL (NACL)

NACL is a subnet-level firewall, serving as a second line of defense.

Features:

Security Group vs NACL:

AspectSecurity GroupNACL
LevelInstanceSubnet
StateStatefulStateless
Rule TypesAllow onlyAllow and Deny
Rule EvaluationAll evaluatedSequential evaluation
DefaultDeny all in, allow all outAllow all

General recommendation: Primarily use Security Groups for control, with NACL as an additional protection layer.



Subnet Planning

Good subnet planning is key to VPC design.

CIDR Block Planning

CIDR (Classless Inter-Domain Routing) defines IP address ranges.

Common CIDRs:

CIDRIP CountUse Case
/1665,536VPC
/204,096Large subnet
/24256Standard subnet
/2816Small subnet

Private IP Ranges (RFC 1918):

Planning Recommendations:

Public vs Private Subnets

Public Subnets:

Private Subnets:

Multi-AZ Design

For high availability, deploy resources in at least two AZs.

Standard Three-Tier Architecture:

VPC: 10.0.0.0/16
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚                                             β”‚
    β”‚   AZ-a                      AZ-b            β”‚
    β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
    β”‚   β”‚ Public      β”‚          β”‚ Public      β”‚  β”‚
    β”‚   β”‚ 10.0.1.0/24 β”‚          β”‚ 10.0.2.0/24 β”‚  β”‚
    β”‚   β”‚   [ALB]     │──────────│   [ALB]     β”‚  β”‚
    β”‚   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜          β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β”‚
    β”‚          β”‚                        β”‚         β”‚
    β”‚   β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”  β”‚
    β”‚   β”‚ Private     β”‚          β”‚ Private     β”‚  β”‚
    β”‚   β”‚ 10.0.11.0/24β”‚          β”‚ 10.0.12.0/24β”‚  β”‚
    β”‚   β”‚   [EC2]     │──────────│   [EC2]     β”‚  β”‚
    β”‚   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜          β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β”‚
    β”‚          β”‚                        β”‚         β”‚
    β”‚   β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”  β”‚
    β”‚   β”‚ DB Subnet   β”‚          β”‚ DB Subnet   β”‚  β”‚
    β”‚   β”‚ 10.0.21.0/24β”‚          β”‚ 10.0.22.0/24β”‚  β”‚
    β”‚   β”‚   [RDS]     │◄─────────│   [RDS]     β”‚  β”‚
    β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Primary   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
    β”‚                   Standby                   β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜


VPC Security Configuration

Security Group Design Principles

1. Principle of Least Privilege

Only open necessary ports, restrict sources as much as possible.

❌ Wrong: Open 0.0.0.0/0 access to database
βœ“ Correct: Only allow application layer security group to access database

2. Layered Design

Each tier has its own security group:

TierSecurity GroupAllow Source
Web Tiersg-web0.0.0.0/0 (80, 443)
App Tiersg-appsg-web (8080)
DB Tiersg-dbsg-app (3306)

3. Use Security Group References

Don't use IPs, use security group IDs as sources:

❌ Source: 10.0.11.0/24
βœ“ Source: sg-app

Benefit: Rules remain effective even if IPs change.

Security Group Examples

Web Server (sg-web):

DirectionTypePortSource/Destination
InboundHTTP800.0.0.0/0
InboundHTTPS4430.0.0.0/0
InboundSSH22sg-bastion
OutboundAllAll0.0.0.0/0

Application Server (sg-app):

DirectionTypePortSource/Destination
InboundCustom8080sg-web
InboundSSH22sg-bastion
OutboundMySQL3306sg-db
OutboundHTTPS4430.0.0.0/0

Database (sg-db):

DirectionTypePortSource/Destination
InboundMySQL3306sg-app
OutboundAllAll0.0.0.0/0

NACL Best Practices

Usually keep default NACL (allow all), primarily rely on Security Groups for control.

Scenarios needing NACL:

NACL Configuration Example:

Rule #DirectionTypePortSourceAction
100InboundHTTP800.0.0.0/0Allow
110InboundHTTPS4430.0.0.0/0Allow
120InboundSSH2210.0.0.0/16Allow
130InboundCustom1024-655350.0.0.0/0Allow
*InboundAllAll0.0.0.0/0Deny

Note: Because it's stateless, you need to allow ephemeral ports (1024-65535) for response traffic.

Get the network architecture right, and security naturally improves

VPC design seems simple, but the devil is in the details. How to divide subnets? How to design security groups? How many NAT Gateways? These decisions affect security, performance, and cost.

The CloudSwap team has extensive VPC architecture experience. Schedule a free consultation and let us design a secure, efficient network architecture for you.



VPC Creation Tutorial

Here are complete steps to create a standard three-tier architecture VPC.

Step 1: Create VPC

  1. Go to AWS Console > VPC
  2. Click "Create VPC"
  3. Select "VPC and more" (automatically creates subnets, route tables, etc.)

Settings:

  1. Click "Create VPC"

Step 2: Review Created Resources

AWS automatically creates:

Step 3: Verify Route Tables

Public subnet route table should have:

DestinationTarget
10.0.0.0/16local
0.0.0.0/0igw-xxxxx

Private subnet route table should have:

DestinationTarget
10.0.0.0/16local
0.0.0.0/0nat-xxxxx

Step 4: Create Security Groups

Web Tier Security Group (sg-web):

  1. VPC > Security Groups > Create security group
  2. Settings:
    • Name: sg-web
    • VPC: my-vpc
  3. Inbound rules:
    • HTTP (80) from 0.0.0.0/0
    • HTTPS (443) from 0.0.0.0/0

App Tier Security Group (sg-app):

  1. Settings:
    • Name: sg-app
    • VPC: my-vpc
  2. Inbound rules:
    • Custom TCP (8080) from sg-web

DB Tier Security Group (sg-db):

  1. Settings:
    • Name: sg-db
    • VPC: my-vpc
  2. Inbound rules:
    • MySQL (3306) from sg-app

Step 5: Test Connectivity

Create Test EC2:

  1. Create EC2 in public subnet (select sg-web)
  2. Verify you can SSH from internet
  3. Verify you can ping external websites

Test Private Subnet:

  1. Create EC2 in private subnet (select sg-app)
  2. Connect via jump from public subnet EC2
  3. Verify you can ping external websites (via NAT Gateway)
  4. Verify external cannot connect directly


VPC Best Practices

Network Design

1. Reserve Enough IP Space

2. Deploy Across Multiple AZs

3. Use VPC Flow Logs

Security Design

1. Layered Protection

2. Limit SSH/RDP Access

3. Regularly Review Security Groups

Cost Optimization

1. NAT Gateway Costs

2. VPC Endpoints

3. Cross-AZ Traffic



FAQ

Why can't EC2 connect to the internet?

Checklist:

  1. βœ“ EC2 in public subnet?
  2. βœ“ Subnet route table has route pointing to IGW?
  3. βœ“ EC2 has Public IP or Elastic IP?
  4. βœ“ Security group allows outbound traffic?
  5. βœ“ NACL allows traffic?

How does private subnet access the internet?

Use NAT Gateway:

  1. Create NAT Gateway in public subnet
  2. Add 0.0.0.0/0 β†’ NAT Gateway to private subnet route table

VPC Peering vs Transit Gateway?

Use Peering for few VPCs, Transit Gateway for many VPCs.

How to connect to corporate network?

Options:

  1. Site-to-Site VPN: Encrypted connection over internet
  2. Direct Connect: Dedicated line, more stable but higher cost
  3. Client VPN: Remote users connect to VPC


Next Steps

VPC is the foundation of all AWS architecture. Master VPC, and you can design secure, reliable cloud environments.

Recommended Learning Path:

  1. Hands-on: Build three-tier architecture VPC, deploy simple application
  2. Security: Design layered security groups
  3. Connectivity: Try VPC Peering
  4. Advanced: Transit Gateway, Direct Connect

Need a second opinion on your VPC architecture?

Network architecture mistakes can lead to security vulnerabilities or unexpectedly high costs. The CloudSwap team has helped hundreds of enterprises design VPC architectures, with rich experience in both new builds and migrations.

Schedule a free architecture consultation and let us review and optimize your VPC design.



Further Reading


Need Professional Cloud Advice?

Whether you're evaluating cloud platforms, optimizing existing architecture, or looking for cost-saving solutions, we can help

Book Free Consultation

AWS
← Previous
AWS vs Azure vs GCP 2025 Complete Comparison: Features, Pricing, Selection Guide
Next β†’
AWS Taiwan Resources Complete Guide: Partners, Salaries, Events, Data Center [2025]