3.2
VPC, Subnets and the Five Reserved Addresses
What a VPC is, how subnets map to Availability Zones, the default VPC, VPC limits, and why a /27 cannot hold 29 servers.
26 min Reading + animations
Tip: tap or hover any dotted-underlined term to see what it means.
By the end of this lesson you will be able to
- Explain what a VPC is, what it isolates, and why it belongs to exactly one Region.
- State the VPC limits that the exam tests: CIDR sizes, secondary blocks, VPCs per Region.
- Explain how subnets relate to Availability Zones, and lay out subnets so an application survives the loss of a whole AZ.
- Name the five addresses AWS reserves in every subnet and size a subnet correctly for a given number of instances.
- Describe exactly what the default VPC gives you, how to recover it, and why production should not use it.
#What a VPC is
A VPC (Virtual Private Cloud) is your own private, logically isolated network inside AWS. Physically, your servers share AWS data centres and cables with millions of other customers; logically, a VPC behaves like a separate network that only you can see. Nothing from another customer, and nothing from the internet, can reach a resource inside your VPC unless you deliberately open a way in.
Inside a VPC you decide:
- the address range (a CIDR block, lesson 3.1);
- how it is split into subnets, and in which data centres each subnet lives;
- where traffic may go, with route tables (lesson 3.3);
- what is allowed in and out, with security groups and network ACLs (lesson 3.5);
- how it connects to the internet, to your office, or to other VPCs (lessons 3.3–3.4 and Chapter 22).
#The rules of a VPC
These limits appear in exam questions as scenario details, so learn them as facts:
| Rule | Value |
|---|---|
| Scope | One VPC belongs to one Region and is available in every Availability Zone of that Region. It can never stretch to another Region. |
| CIDR size | Between /16 (65,536 addresses) and /28 (16 addresses). |
| Primary CIDR | Chosen at creation, cannot be changed later. |
| Secondary CIDRs | You can add more blocks later; 5 IPv4 blocks per VPC by default (a quota you can raise). They must not overlap existing ones. |
| VPCs per Region | 5 by default (a soft limit, raised on request). |
| IPv4 | Always required. IPv6 is optional and added alongside it (Chapter 22). |
#Subnets and Availability Zones
A subnet is a slice of the VPC’s range, for example 10.0.10.0/24 out of 10.0.0.0/16. Every resource that has an address in the VPC (an EC2 instance, a database, a load balancer node) lives in a subnet.
Two facts about subnets matter more than anything else:
- A subnet lives in exactly one Availability Zone. An Availability Zone (AZ) is one or more data centres with independent power, cooling and networking, separated from the other AZs of the Region by a meaningful distance and connected to them by fast, low-latency private links. Every Region has at least three. A VPC spans all of them, but each subnet is pinned to one.
- “Public” and “private” are not settings on the subnet. A subnet is public if its route table sends internet traffic to an internet gateway, and private if it does not. Lesson 3.3 shows exactly how.
A VPC spans a Region; each subnet lives in one AZ
Build a two-AZ VPC piece by piece, then knock out a whole Availability Zone.
Scenario
Region → VPC → Availability Zones → subnets → instances.
Everything starts in a Region: a geographic area such as Singapore (ap-southeast-1) made of several isolated data-centre groups. A VPC always belongs to exactly one Region.
Because a subnet cannot span AZs, high availability is built by repeating the same layout in two or more AZs: a public subnet and a private subnet in AZ A, the same pair in AZ B, and one copy of each tier in each. If one AZ fails, the copies in the other AZ keep the application running.
A common production layout uses three tiers in each AZ:
| Tier | Holds | Reachable from the internet? |
|---|---|---|
| Public | Load balancers, NAT gateways, (rarely) bastion hosts | Yes, by design |
| Private (app) | Application servers, containers, Lambda network interfaces | No; reaches out through a NAT gateway if needed |
| Private (data) | Databases, caches | No, and usually no internet access at all |
#The five reserved addresses
In every subnet, AWS keeps five addresses for itself: the first four and the last one. You can never assign them to an instance. For 10.0.0.0/24:
| Address | Reserved for |
|---|---|
10.0.0.0 | Network address: names the subnet itself |
10.0.0.1 | VPC router: the default gateway of the subnet |
10.0.0.2 | DNS: the Amazon-provided DNS resolver (strictly, it answers at the VPC range’s base + 2, but base + 2 is reserved in every subnet) |
10.0.0.3 | Reserved for future use by AWS |
10.0.0.255 | Broadcast address: a VPC does not support broadcast, so AWS simply blocks it |
So usable addresses = total − 5:
| Subnet | Total | Reserved | Usable |
|---|---|---|---|
/28 | 16 | 5 | 11 |
/27 | 32 | 5 | 27 |
/26 | 64 | 5 | 59 |
/25 | 128 | 5 | 123 |
/24 | 256 | 5 | 251 |
/16 | 65,536 | 5 | 65,531 |
Every address in one subnet
Each square is one IPv4 address of the subnet 10.0.1.0/n. Red squares are the five AWS keeps; hover or tap one to see why.
10.0.1.0/28: 16 total − 5 reserved = 11 usable
Hover or tap a square.
#Leave room to grow
Instances are not the only things that use subnet addresses. Plan for:
- Load balancers: each load balancer node takes addresses in its subnets, and an Application Load Balancer needs subnets of at least
/27with at least 8 free addresses so it can scale. - Containers and Lambda: with modern networking every container task, and every VPC-connected Lambda network interface, takes its own address. A busy Kubernetes cluster can exhaust a
/24quickly. - Rolling deployments and Auto Scaling: during a deployment the old and new instances run side by side, briefly doubling the count.
A subnet cannot be resized after creation. When in doubt, choose a bigger subnet or leave space in the VPC range for new ones.
Self-checkQuestion
A VPC uses 10.0.0.0/16. Which statement is true?
#The default VPC
Every AWS account comes with a default VPC in every Region, so you can launch an instance in seconds without any networking knowledge. It is useful for learning, and it is exactly what a careless launch ends up in.
The default VPC: ready to use, public by default
Every Region of every account comes with one. Launch an instance without choosing a network and it lands here.
Scenario
The default VPC always uses 172.31.0.0/16, in every Region and every account. That is why it overlaps with every other default VPC: fine for experiments, a problem if you ever connect two of them.
What the default VPC contains:
- CIDR
172.31.0.0/16, the same in every Region and every account. - One default subnet per AZ, each a
/20(4,096 addresses). - Every default subnet is public: an internet gateway is attached, the main route table sends
0.0.0.0/0to it, and auto-assign public IPv4 is turned on. A new instance gets a public address automatically. - A default network ACL that allows all traffic in and out.
- A default security group that allows all outbound traffic and allows inbound traffic only from other members of the same security group. It does not allow traffic from the internet.
If the default VPC is deleted, you cannot restore it from a backup, but you can recreate it: in the VPC console choose Actions → Create default VPC, or run aws ec2 create-default-vpc. AWS rebuilds it with the same layout.
#Try it yourself
With the AWS CLI configured (any Region; these resources are free while they hold nothing that costs money):
# Which AZs does this Region have, and what are their IDs?
aws ec2 describe-availability-zones --query "AvailabilityZones[].[ZoneName,ZoneId]" --output table
# Create a VPC and two subnets in different AZs
VPC=$(aws ec2 create-vpc --cidr-block 10.0.0.0/16 --query Vpc.VpcId --output text)
aws ec2 create-subnet --vpc-id $VPC --cidr-block 10.0.0.0/24 --availability-zone-id apse1-az1
aws ec2 create-subnet --vpc-id $VPC --cidr-block 10.0.10.0/24 --availability-zone-id apse1-az2
# Add a secondary CIDR block
aws ec2 associate-vpc-cidr-block --vpc-id $VPC --cidr-block 10.1.0.0/16
# How many addresses are still free in each subnet?
aws ec2 describe-subnets --filters Name=vpc-id,Values=$VPC \
--query "Subnets[].[CidrBlock,AvailabilityZone,AvailableIpAddressCount]" --output table
The last command shows 251 free addresses in each new /24, not 256: the five reserved ones are already subtracted. Replace the AZ IDs with ones from the first command if your Region differs. Delete the subnets and the VPC when you are done.
#Summary
Key takeaways
- A VPC is a logically isolated private network in one Region, available in every AZ of that Region. Nothing gets in or out unless you add a path.
- VPC CIDR blocks are
/16to/28. The primary block cannot change; add secondary blocks (5 per VPC by default) for more space. Default quota: 5 VPCs per Region. - A subnet is a slice of the VPC range in exactly one AZ. High availability = the same subnet layout in at least two AZs, one copy of each tier per AZ.
- Public vs private is decided by the route table, not by a subnet setting.
- AWS reserves 5 addresses per subnet (first four + last): network, VPC router, DNS, future use, broadcast. Usable = total − 5:
/28= 11,/27= 27,/26= 59,/24= 251. - The default VPC (
172.31.0.0/16, a public/20per AZ, internet gateway, auto-assign public IP) exists in every Region; recreate it with “Create default VPC”. Use a custom VPC for production.
Answer on your own first, then read the explanation, even when you got it right.
Self-checkQuestion
An instance in the default VPC has only the default security group attached. Can you open its web page from your laptop?
Self-checkQuestion
Which of these is not one of the five addresses AWS reserves in 10.0.2.0/24?
Self-checkQuestion
A team needs 120,000 private IPv4 addresses in a single VPC. What should they do?
Self-checkQuestion
A VPC is created in ap-southeast-1. Where can its subnets be placed?
Self-checkQuestion
Which of these CIDR blocks can be the primary IPv4 block of a new VPC?
Self-checkQuestion
What makes a subnet a public subnet?
Self-checkQuestion
Which two statements about Availability Zones are true?
Choose 2
Self-checkQuestion
A VPC is created with the smallest CIDR block AWS allows, and one subnet uses the whole range. At most how many instances can that subnet hold, one address each?
Self-checkQuestion
Each default subnet in the default VPC is a /20. How many of its addresses can be given to instances?
Self-checkQuestion
Which two statements about the default VPC are true?
Choose 2
Self-checkQuestion
Which statement about subnets is NOT true?
Self-checkQuestion
A team already has five VPCs in a Region. Creating a sixth fails with a limit error. What should they do?
Self-checkQuestion
A VPC uses 10.20.0.0/24, and the team splits it into equal /26 subnets. How many subnets do they get, and how many addresses in each can go to instances?
Self-checkQuestion
A VPC’s primary block is 10.0.0.0/20. How many /24 subnets can be created from it?
Self-checkQuestion
A batch workload needs 60 EC2 instances in a single subnet, one private IP each. What is the smallest subnet that fits?
Self-checkQuestion
Which two addresses in the subnet 172.16.4.0/22 does AWS reserve?
Choose 2
Self-checkQuestion
An engineer tries to launch an instance with the fixed private IP 10.0.1.255 in the subnet 10.0.1.0/24, and the launch fails. Why?
Self-checkQuestion
A VPC’s primary CIDR is 10.0.0.0/16. Instances in the subnet 10.0.8.0/24 use the Amazon-provided DNS. Which statement is accurate?
Self-checkQuestion
A team created a VPC with 10.0.0.0/24 for a test. It is now going to production and has run out of addresses. What can they do without rebuilding the VPC?
Self-checkQuestion
A VPC uses 10.0.0.0/16. Which secondary CIDR block can be associated with it?
Self-checkQuestion
A VPC’s 10.0.0.0/16 block is almost full. Which two actions together give the workload more addresses inside the same VPC?
Choose 2
Self-checkQuestion
A company runs its web servers in one public subnet in a single Availability Zone. During an outage of that AZ the whole site went down. What should a solutions architect change?
Self-checkQuestion
A solutions architect designs a three-tier application (public, application and data tiers) that must survive the loss of one AZ, using two AZs. What is the minimum number of subnets?
Self-checkQuestion
Two AWS accounts must run resources in the same physical Availability Zone to keep latency between them low. Account A uses ap-southeast-1a. What should Account B use?
Self-checkQuestion
An administrator accidentally deleted the default VPC in eu-west-1. Scripts that launch instances without naming a subnet now fail there. What is the quickest fix?
Self-checkQuestion
A startup launched its production web servers and database in the default VPC. A security review flags this. What is the main reason?
Self-checkQuestion
A company wants to connect the default VPCs of three of its accounts privately so their services can talk to each other. Why does the plan fail at once?
Self-checkQuestion
To save addresses, a team plans to put an internet-facing Application Load Balancer into two /28 subnets, one per AZ. What is wrong with this plan?
Self-checkQuestion
A Kubernetes cluster gives every pod its own VPC address. Its pods run in two /24 subnets, and new pods now fail with ‘no free IP addresses’ although the nodes have spare CPU and memory. What is the best long-term fix?
Self-checkQuestion
Each of two subnets must hold 100 instances, plus room for 20 more that run alongside them during rolling deployments. Which two subnet sizes meet the need?
Choose 2