Course outline

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:

RuleValue
ScopeOne VPC belongs to one Region and is available in every Availability Zone of that Region. It can never stretch to another Region.
CIDR sizeBetween /16 (65,536 addresses) and /28 (16 addresses).
Primary CIDRChosen at creation, cannot be changed later.
Secondary CIDRsYou 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 Region5 by default (a soft limit, raised on request).
IPv4Always 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:

  1. 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.
  2. “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.

AWS Cloud
Regionap-southeast-1
Step 1 of 6
1

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:

TierHoldsReachable from the internet?
PublicLoad balancers, NAT gateways, (rarely) bastion hostsYes, by design
Private (app)Application servers, containers, Lambda network interfacesNo; reaches out through a NAT gateway if needed
Private (data)Databases, cachesNo, 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:

AddressReserved for
10.0.0.0Network address: names the subnet itself
10.0.0.1VPC router: the default gateway of the subnet
10.0.0.2DNS: 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.3Reserved for future use by AWS
10.0.0.255Broadcast address: a VPC does not support broadcast, so AWS simply blocks it

So usable addresses = total − 5:

SubnetTotalReservedUsable
/2816511
/2732527
/2664559
/251285123
/242565251
/1665,536565,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.

Subnet size

10.0.1.0/28: 16 total − 5 reserved = 11 usable

Instances to place29 does not fit (/28: 11)
i

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 /27 with 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 /24 quickly.
  • 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

AWS Cloud
Region
Default VPC172.31.0.0/16
AZ a/20
AZ b/20
AZ c/20
Internet gateway
Internet
Step 1 of 5
1

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/0 to 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 /16 to /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 /20 per AZ, internet gateway, auto-assign public IP) exists in every Region; recreate it with “Create default VPC”. Use a custom VPC for production.