VPC Fundamentals
Overview
A Virtual Private Cloud (VPC) is your own logically isolated virtual network inside the AWS Cloud. You decide the IP address range, carve it into subnets, control how traffic flows in and out, and attach the resources (EC2 instances, RDS databases, Lambda functions, load balancers) that live inside it.
Think of an AWS Region as a huge shared office complex. A VPC is the floor you rent: nobody else can walk in, you choose where the walls (subnets) and doors (gateways) go, and you hire the security guards (security groups and network ACLs).
Every networking decision you make later in the course — public vs. private subnets, NAT, peering, VPN, endpoints — builds on the VPC, so it is one of the most heavily tested topics on the SAA-C03 exam.
Key Concepts
- A VPC is regional: it spans every Availability Zone in one Region, but never crosses Regions.
- A VPC is defined by a CIDR block (IPv4 between /16 and /28) and optionally an IPv6 CIDR (AWS-assigned /56).
- A subnet lives in exactly one AZ and is carved from the VPC CIDR.
- A subnet is public only if its route table has a route to an Internet Gateway; otherwise it is private.
- Every VPC has an implicit router and a main route table; each subnet is associated with exactly one route table.
- Each account gets a default VPC (172.31.0.0/16) in every Region with public subnets pre-wired for internet access.
- AWS reserves 5 IP addresses in every subnet (network, router, DNS, future use, broadcast).
- VPCs are isolated by default. Connectivity is explicit: IGW, NAT Gateway, VPC Peering, Transit Gateway, VPN, Direct Connect, VPC Endpoints.
Detailed Notes
What is a VPC and why does it exist?
Before VPCs, early EC2 ran on a single flat shared network (EC2-Classic, retired in 2022). Customers could not control IP ranges, isolate workloads, or connect cleanly to on-premises networks. The VPC solves this by giving every customer a software-defined network with:
- Isolation — your traffic is separated from other customers at the hypervisor/network layer.
- Control — you choose IP ranges, subnets, routing and filtering.
- Hybrid connectivity — extend your data centre into AWS using VPN or Direct Connect without IP clashes.
- Compliance — place sensitive tiers (databases) in subnets with no internet path at all.
CIDR blocks explained
CIDR (Classless Inter-Domain Routing) notation is written as IP/prefix. The prefix says how many leading bits are fixed for the network; the remaining bits are available for hosts.
10.0.0.0/16
^^^^^^^^ ^^
network prefix length = first 16 bits are fixed
Host bits = 32 - 16 = 16 -> 2^16 = 65,536 addresses
| CIDR | Host bits | Total IPs | Usable in a subnet (minus 5) |
|---|---|---|---|
| /16 | 16 | 65,536 | 65,531 (largest VPC) |
| /20 | 12 | 4,096 | 4,091 |
| /24 | 8 | 256 | 251 |
| /27 | 5 | 32 | 27 |
| /28 | 4 | 16 | 11 (smallest VPC / subnet) |
Rule of thumb: each step down in prefix number doubles the size (/23 = 512, /22 = 1,024).
Private ranges to use (RFC 1918)
| Range | CIDR | Notes |
|---|---|---|
| 10.0.0.0 – 10.255.255.255 | 10.0.0.0/8 | Most popular for VPCs – very large |
| 172.16.0.0 – 172.31.255.255 | 172.16.0.0/12 | The default VPC uses 172.31.0.0/16 |
| 192.168.0.0 – 192.168.255.255 | 192.168.0.0/16 | Common on home/office networks – avoid if you plan a VPN |
You can also add secondary CIDR blocks to an existing VPC when you run out of addresses. You cannot resize or change the primary CIDR, so plan carefully. CIDR ranges of VPCs you want to peer or connect through Transit Gateway must not overlap.
The 5 reserved addresses
In a subnet 10.0.1.0/24 AWS reserves:
| Address | Purpose |
|---|---|
| 10.0.1.0 | Network address |
| 10.0.1.1 | VPC router |
| 10.0.1.2 | Amazon-provided DNS (VPC base + 2) |
| 10.0.1.3 | Reserved for future use |
| 10.0.1.255 | Network broadcast (broadcast is not supported, still reserved) |
So a /24 gives 251 usable IPs, and a /28 only 11.
Subnets: public vs. private
A subnet is a range of the VPC CIDR placed in a single Availability Zone. To build highly available systems you create at least one subnet per tier per AZ (usually two or three AZs).
| Public subnet | Private subnet | |
|---|---|---|
| Route to Internet Gateway (0.0.0.0/0 -> igw-xxx) | Yes | No |
| Resources need a public/Elastic IP to reach the internet | Yes | No (use NAT) |
| Typical residents | ALB, NAT Gateway, bastion/jump hosts | App servers, RDS, ElastiCache, Lambda in VPC |
| Reachable from the internet | Yes, if SG/NACL allow | Never directly |
There is no "public" checkbox on a subnet in the way people expect. "Public" is a consequence of the route table plus the instance having a public IPv4 address. The
MapPublicIpOnLaunchsetting only controls whether new instances get an auto-assigned public IP.
Route tables
A route table is a set of rules (routes) that determines where network traffic from a subnet is directed.
Public route table Private route table
Destination Target Destination Target
10.0.0.0/16 local 10.0.0.0/16 local
0.0.0.0/0 igw-0abc123 0.0.0.0/0 nat-0def456
- The
localroute (VPC CIDR) is always present and cannot be deleted, so every subnet can talk to every other subnet in the VPC by default. - The most specific route wins (longest prefix match).
- A main route table is created with the VPC; any subnet without an explicit association uses it. Best practice: keep the main table private and create a separate custom public route table.
- A gateway route table can be associated with an IGW or VGW for edge routing (advanced).
Core VPC components at a glance
| Component | What it does |
|---|---|
| Internet Gateway (IGW) | Horizontally scaled, highly available gateway enabling two-way internet access for public IPs |
| NAT Gateway | Lets private resources start outbound connections to the internet; blocks inbound |
| Security Group | Stateful firewall at the ENI/instance level, allow rules only |
| Network ACL | Stateless firewall at the subnet level, allow and deny rules, numbered and evaluated in order |
| VPC Endpoint | Private connection to AWS services without traversing the internet |
| VPC Peering / Transit Gateway | Connect VPCs together |
| VPN / Direct Connect | Connect to on-premises networks |
| Elastic Network Interface (ENI) | Virtual network card carrying private IPs, public IP, SGs and a MAC address |
| DHCP option set | DNS servers, domain name, NTP for the VPC |
| VPC Flow Logs | Capture IP traffic metadata to CloudWatch Logs or S3 |
Default VPC vs. custom VPC
| Default VPC | Custom VPC | |
|---|---|---|
| CIDR | 172.31.0.0/16 | You choose |
| Subnets | One public /20 subnet per AZ | You create them |
| Internet Gateway | Attached | You attach |
| Public IP on launch | Yes (auto-assign) | Off unless you enable it |
| Use for | Quick tests, labs | Production workloads |
Building a VPC with the CLI
# 1. Create the VPC
VPC_ID=$(aws ec2 create-vpc --cidr-block 10.0.0.0/16 \
--tag-specifications 'ResourceType=vpc,Tags=[{Key=Name,Value=prod-vpc}]' \
--query 'Vpc.VpcId' --output text)
# 2. Enable DNS hostnames (needed for private hosted zones & endpoints)
aws ec2 modify-vpc-attribute --vpc-id $VPC_ID --enable-dns-hostnames
# 3. Create a public subnet in AZ a
PUB_SUBNET=$(aws ec2 create-subnet --vpc-id $VPC_ID \
--cidr-block 10.0.1.0/24 --availability-zone us-east-1a \
--query 'Subnet.SubnetId' --output text)
# 4. Create + attach an Internet Gateway
IGW_ID=$(aws ec2 create-internet-gateway --query 'InternetGateway.InternetGatewayId' --output text)
aws ec2 attach-internet-gateway --internet-gateway-id $IGW_ID --vpc-id $VPC_ID
# 5. Public route table with a default route to the IGW
RT_ID=$(aws ec2 create-route-table --vpc-id $VPC_ID --query 'RouteTable.RouteTableId' --output text)
aws ec2 create-route --route-table-id $RT_ID --destination-cidr-block 0.0.0.0/0 --gateway-id $IGW_ID
aws ec2 associate-route-table --route-table-id $RT_ID --subnet-id $PUB_SUBNET
The same VPC as CloudFormation
Resources:
Vpc:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsSupport: true
EnableDnsHostnames: true
PublicSubnetA:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref Vpc
CidrBlock: 10.0.1.0/24
AvailabilityZone: !Select [0, !GetAZs ""]
MapPublicIpOnLaunch: true
Igw:
Type: AWS::EC2::InternetGateway
IgwAttach:
Type: AWS::EC2::VPCGatewayAttachment
Properties: { VpcId: !Ref Vpc, InternetGatewayId: !Ref Igw }
IPv6 in a VPC
- IPv6 addresses are globally unique and public — there are no private IPv6 ranges.
- Dual-stack subnets get an IPv6 CIDR (/64) out of the VPC's /56.
- For outbound-only IPv6 traffic from private subnets use an Egress-only Internet Gateway (the IPv6 equivalent of NAT).
Tenancy
VPC instance tenancy is default (shared hardware) or dedicated (single-tenant hardware, extra cost). You can change dedicated → default, never default → dedicated for the VPC itself.
Monitoring and troubleshooting
- VPC Flow Logs (VPC, subnet or ENI level) show ACCEPT/REJECT decisions – the first tool for "why can't A reach B?".
- Reachability Analyzer statically analyses the path between two endpoints and tells you which component blocks it.
- Traffic Mirroring copies packets to a security appliance for deep inspection.
Real World Example
Scenario — a fintech launches a customer-facing payments API.
The security team requires that card-processing databases are never reachable from the internet, and the platform must survive the loss of a data centre.
The architects create a VPC 10.20.0.0/16 in eu-west-1 and split it across three AZs with three subnet tiers each:
- Public tier (
10.20.0.0/24,.1.0/24,.2.0/24) — Application Load Balancer and one NAT Gateway per AZ. - App tier (
10.20.10.0/24…) — Auto Scaling group of EC2 instances; no public IPs; outbound calls to payment partners go via the NAT Gateways. - Data tier (
10.20.20.0/24…) — Multi-AZ RDS PostgreSQL; the route table has no default route at all.
Traffic flows from the customer -> ALB (public subnet) -> app servers (private) -> database (isolated). Security groups chain together (ALB-SG -> App-SG -> DB-SG), so the database only accepts connections from app servers. S3 access for receipts uses a gateway VPC endpoint, which removes NAT data-processing charges and keeps traffic on the AWS network. VPC Flow Logs ship to S3 for audit.
The result: a defence-in-depth network that passes the PCI-DSS segmentation review, scales horizontally, and tolerates an AZ outage.
Architecture Diagram
Public subnets hold the load balancer and NAT; application and database tiers are private.
- 1Route 53 resolves the domain to the Application Load Balancer inside the public subnets.
- 2The Internet Gateway delivers the request; the ALB forwards it to healthy EC2 targets in the private app subnets.
- 3App servers query the RDS primary in the isolated data subnets. Synchronous replication keeps the standby in the other AZ current.
- 4Outbound calls from app servers (patches, third-party APIs) leave via the NAT Gateway in their own AZ; inbound connections from the internet are never possible.
Best Practices
- ✓Plan CIDRs up front. Use a /16 per VPC from 10.0.0.0/8 and keep a central register (or VPC IPAM) so VPCs, on-premises networks and other accounts never overlap.
- ✓Use at least two AZs and one subnet per tier per AZ; size subnets generously (/24 or larger) because the 5 reserved IPs and ENIs for Lambda/EKS consume addresses quickly.
- ✓Keep workloads private by default. Only load balancers, NAT Gateways and bastions (or better, SSM Session Manager) belong in public subnets.
- ✓Deploy one NAT Gateway per AZ to avoid cross-AZ data charges and a single point of failure.
- ✓Use VPC endpoints (Gateway for S3 and DynamoDB; Interface/PrivateLink for others) so traffic to AWS services bypasses the internet and NAT.
- ✓Layer your defences: security groups as the primary control (reference other SGs instead of IPs) and NACLs for coarse subnet-level deny rules.
- ✓Enable VPC Flow Logs and tag everything (
Name,Environment,Owner) so networking is auditable and costs are attributable. - ✓Do not use the default VPC for production. Delete it or leave it empty, and define networking as code with CloudFormation, CDK or Terraform.
Common Interview Questions
Exam Tips
SAA-C03 focus
- VPC = regional, subnet = AZ. Any question that needs high availability expects subnets in multiple AZs.
- Largest VPC CIDR is /16, smallest is /28. You can add up to 5 CIDR blocks by default (adjustable), but you can't edit the primary one.
- 5 reserved IPs per subnet shows up in capacity calculations: a /28 subnet has only 11 usable addresses.
- "Private instances need to download patches from the internet" -> NAT Gateway in a public subnet (not an IGW directly, not a NAT instance unless cost is the focus).
- "Reach S3 or DynamoDB privately without NAT" -> Gateway VPC endpoint (free). Other services -> Interface endpoint (PrivateLink).
- Overlapping CIDRs block peering and Transit Gateway. Peering is not transitive; use Transit Gateway for hub-and-spoke.
- Security Groups are stateful and allow-only; NACLs are stateless and support explicit deny – the way to block a specific malicious IP is a NACL rule.
- Default VPC = 172.31.0.0/16, public subnets in every AZ, IGW attached. Expect it in "quick launch" scenarios; expect custom VPC in production scenarios.
Finished this lesson?
0 of 64 lessons done · 0% of the course

