VPC and subnets
The default VPC, VPC limits and allowed CIDR ranges, public and private subnets across Availability Zones, and the five IP addresses AWS reserves in every subnet.
Default VPC
- All new AWS accounts have a default VPC in every Region.
- New EC2 instances are launched into the default VPC if no subnet is specified.
- The default VPC has internet connectivity, and all EC2 instances inside it get public IPv4 addresses.
- They also get a public and a private IPv4 DNS name.
VPC in AWS (IPv4)
VPC = Virtual Private Cloud.
- An account can have multiple VPCs in an AWS Region (5 per Region by default, a soft limit that can be raised).
- Each VPC has a primary CIDR, and more can be added: 5 CIDRs per VPC by default. Each CIDR:
- minimum size /28 (16 IP addresses);
- maximum size /16 (65,536 IP addresses).
- Use the private IPv4 ranges:
10.0.0.0/8;172.16.0.0/12;192.168.0.0/16.
- The VPC CIDR should NOT overlap with other networks (for example the corporate network), or they can't be connected later.
Updated since the slides
The slides say a VPC can have at most 5 CIDRs and can only use private ranges. Today, 5 CIDRs is the default quota, adjustable up to 50. AWS recommends the private RFC 1918 ranges but also allows publicly routable CIDRs and 100.64.0.0/10. For the exam, use private ranges and avoid overlaps.
Subnets
- A subnet is a range of IPs (a CIDR inside the VPC CIDR) tied to one Availability Zone.
- Public subnet: its route table has a route to an internet gateway, so instances with public IPs are reachable.
- Private subnet: no route to an internet gateway.
- For high availability, create subnets in at least two AZs.
The 5 reserved IP addresses
AWS reserves 5 IP addresses (the first 4 and the last 1) in each subnet. They can't be assigned to an EC2 instance. For 10.0.0.0/24:
10.0.0.0: network address;10.0.0.1: reserved by AWS for the VPC router;10.0.0.2: reserved by AWS for mapping to the Amazon-provided DNS;10.0.0.3: reserved by AWS for future use;10.0.0.255: network broadcast address. AWS doesn't support broadcast in a VPC, so the address is reserved.
Exam tip: if 29 IP addresses are needed for EC2 instances:
- a subnet of size
/27can't be chosen (32 IPs − 5 = 27, less than 29); - a subnet of size
/26is needed (64 IPs − 5 = 59, more than 29).
Real-world examples
- A company creates VPC
10.20.0.0/16(its offices use10.0.0.0/16, so there's no overlap later for a VPN) with public and private/24subnets in three AZs.
Exam tips
- "How many usable IPs in a /28 subnet?" → 16 − 5 = 11.
- "Need N IPs" → pick the smallest subnet where 2^(32−n) − 5 ≥ N.
- "Plan to connect to on premises later" → choose a VPC CIDR that doesn't overlap.
- "Subnet spans two AZs" → impossible; one subnet = one AZ.
Common traps
- "A /24 subnet gives 256 usable IPs." 251.
- "The default VPC's instances are private." They get public IPv4 addresses.
Hands-on lab: build a VPC with subnets
Goal: create a VPC with a public and a private subnet.
Costs money
A VPC, subnets, route tables and an internet gateway are free. Don't create a NAT gateway in this lab (it costs about $0.045 an hour). Any Region works.
Create the VPC
VPC → Your VPCs → Create VPC → VPC only: name saa-vpc, IPv4 CIDR 10.0.0.0/16.
Create two subnets
Subnets → Create subnet in saa-vpc: saa-public-a with 10.0.0.0/24 in the first AZ, and saa-private-a with 10.0.16.0/20 in the same AZ.
Check the numbers
Select each subnet and read Available IPv4 addresses.
Expected result: 251 available addresses in the /24, and 4,091 in the /20 (4,096 − 5).
Clean up: keep the VPC for the next lab (internet gateway and route tables), or delete it (deleting the VPC deletes its subnets).
AWS documentation
CIDR and IP addressing
CIDR notation, base IPs and subnet masks, how many addresses a /24 or /16 holds, worked examples, and private vs public IPv4 ranges.
Internet gateway and route tables
The internet gateway that gives a VPC internet access, route tables and the local route, and what makes a subnet public.