Volume 2 · Chapter 1 — AWS Networking Deep Dive (VPC)
VPC Fundamentals and Subnets
1.1 Introduction
The Virtual Private Cloud (VPC) is the network foundation that every other AWS resource lives inside, and it is one of the most heavily tested topics in cloud interviews because it is where security, availability, and connectivity all meet. A VPC is your own logically isolated section of the AWS network - a private data-centre network defined entirely in software - in which you launch resources like EC2 instances and databases. Nothing about a well-designed system makes sense until you understand how the VPC, its subnets, and its routing work, because those decisions determine what is reachable from the internet, what is private, how traffic flows, and how a failure in one Availability Zone is contained. This chapter builds that foundation.
1.2 What a VPC Is
A VPC is a virtual network that you fully control, isolated from every other customer’s network and from the internet unless you deliberately open a path. When you create a VPC you give it a private IP address range using CIDR notation - for example10.0.0.0/16, which reserves roughly 65,000 private addresses for your resources to use. Everything you deploy - instances, load balancers, databases - gets a private IP from within that range and can talk to other resources in the VPC over private networking. The VPC is regional: it spans all the Availability Zones in one Region, which is exactly what lets you build a single network that stretches across multiple AZs for high availability. The core mental model is that the VPC is your private, software-defined data-centre network, and you decide precisely what connectivity it has.
flowchart TB
subgraph VPC["VPC 10.0.0.0/16 (spans the Region)"]
subgraph AZa[Availability Zone A]
PubA[Public subnet 10.0.1.0/24]
PrivA[Private subnet 10.0.11.0/24]
end
subgraph AZb[Availability Zone B]
PubB[Public subnet 10.0.2.0/24]
PrivB[Private subnet 10.0.12.0/24]
end
end
Internet((Internet)) --- PubA
Internet --- PubB
PubA -. no direct path .-x PrivA 1.3 Subnets: Public and Private
A VPC is subdivided into subnets, each a slice of the VPC’s address range that lives in exactly one Availability Zone. This one-subnet-per-AZ rule is fundamental: to build a multi-AZ system you create subnets in each AZ and spread your resources across them. Subnets are classified as public or private not by a checkbox but by their routing: a public subnet has a route to the internet through an internet gateway, so resources in it can be reachable from and reach the internet; a private subnet has no such route, so its resources are unreachable directly from the internet. The standard design places internet-facing components (like load balancers) in public subnets and everything sensitive (application servers, databases) in private subnets, so the sensitive tier has no direct internet exposure at all - which is exactly why banks put their core systems in private subnets.
1.4 CIDR Planning
Choosing address ranges deliberately matters more than beginners expect. You allocate the VPC a CIDR block and then carve non-overlapping subnet blocks out of it - for instance a/16VPC divided into several/24subnets of 256 addresses each. Good CIDR planning avoids two future problems: overlap with other networks you’ll need to connect to (if your VPC’s range overlaps a corporate network or another VPC, you can’t peer or route between them cleanly), and running out of space (too-small subnets that can’t grow). The practical discipline is to pick a private range that won’t collide with your on-premises networks or other VPCs, leave room to add subnets and AZs later, and size subnets for their expected workload plus headroom.
# Create a VPC and a subnet placed in a specific Availability Zone.
aws ec2 create-vpc --cidr-block 10.0.0.0/16 \
--tag-specifications 'ResourceType=vpc,Tags=[{Key=Name,Value=banking-vpc}]'
aws ec2 create-subnet --vpc-id vpc-0abc123 \
--cidr-block 10.0.11.0/24 \
--availability-zone ca-central-1a \ # a subnet lives in exactly one AZ
--tag-specifications 'ResourceType=subnet,Tags=[{Key=tier,Value=private-app}]'
1.5 Banking Production Scenario
A bank builds its VPC as10.0.0.0/16in a Canadian Region, chosen so its range doesn’t overlap the corporate network it will later connect over Direct Connect. It creates public subnets in two AZs to hold internet-facing load balancers, and private subnets in the same two AZs for the application servers and managed database. Customer traffic reaches the load balancers in the public subnets, which forward it over private networking to the application servers in the private subnets; the database sits in private subnets with no route to the internet whatsoever. Because subnets are duplicated across two AZs, the loss of one Availability Zone removes only half the capacity, and the load balancer routes around it - the resilience baseline every production VPC should have.
1.6 Troubleshooting: Subnet and CIDR Mistakes
Two VPC-design mistakes cause recurring pain. The first is putting everything in one Availability Zone - all subnets, instances, and the database in a single AZ - which works until that AZ fails and the whole system goes down; the fix is always to create subnets across at least two AZs and spread resources over them. The second is CIDR overlap: choosing a VPC range that collides with the corporate network or another VPC, which later makes peering, VPN, or Direct Connect routing impossible without re-addressing the entire network. The fix is to plan address ranges up front so nothing overlaps anything you’ll ever need to connect. A subtler issue is undersized subnets that exhaust their addresses as the workload grows - avoided by sizing with headroom from the start.
What is a VPC, and what makes a subnet public versus private?
A VPC - Virtual Private Cloud - is your own logically isolated, software-defined network within AWS, in which you launch resources like EC2 instances, load balancers, and databases. It’s isolated from every other customer’s network and from the internet unless you deliberately create a path, and you define it with a private IP range in CIDR notation, such as10.0.0.0/16, from which all your resources draw their private addresses. A VPC is regional - it spans all the Availability Zones in one Region - which is what lets you build a single network that stretches across multiple AZs for high availability. Within the VPC you create subnets, each of which is a slice of the VPC’s address range that lives in exactly one Availability Zone; that one-subnet-per-AZ rule is why building multi-AZ means creating subnets in each zone and spreading resources across them. Now the key point: what makes a subnet public or private is not a setting called “public” - it’s the subnet’s routing. A public subnet has a route to an internet gateway, so resources in it can send traffic to and be reached from the internet (given a public IP and permissive security rules); a private subnet has no route to an internet gateway, so its resources have no direct internet path at all. This distinction is the backbone of secure network design: you place internet-facing components like load balancers in public subnets, and you place everything sensitive - application servers and databases - in private subnets so they have no direct exposure to the internet, receiving traffic only from other resources inside the VPC. For a bank, the core application and database live entirely in private subnets precisely because there is no route by which an external attacker could reach them directly. So a VPC is your private network in AWS, subnets divide it per Availability Zone, and public versus private is determined purely by whether the subnet’s route table sends traffic to an internet gateway - which is the lever you use to decide what is exposed and what is protected.
Why does CIDR planning matter, and what goes wrong if you get it wrong?
CIDR planning - deliberately choosing the IP address ranges for your VPC and subnets - matters because those ranges are hard to change later and they determine whether you can connect and grow. When you create a VPC you give it a CIDR block like10.0.0.0/16(about 65,000 addresses), and you carve non-overlapping subnet blocks out of it, such as several/24subnets of 256 addresses each. Getting this right avoids two serious future problems. The first is overlap. If your VPC’s range overlaps the range of a network you later need to connect to - your on-premises corporate network, or another VPC - you cannot cleanly route between them, because the same IP addresses would exist on both sides and routing becomes ambiguous. That means you can’t establish VPC peering, a VPN, or Direct Connect routing to that network without re-addressing, which in a running production environment is enormously disruptive. So you must choose a private range up front that won’t collide with any network you might ever connect - your other VPCs, your data centres, partner networks. The second problem is running out of space: if you size subnets too small, a growing workload exhausts the available addresses and you can’t launch more resources in that subnet, forcing painful re-architecture. So you size subnets for their expected load plus headroom and leave room in the VPC to add more subnets and more AZs later. The practical discipline is: pick a VPC CIDR that doesn’t overlap anything you’ll connect to, divide it into non-overlapping subnet ranges spread across Availability Zones, size each subnet with growth headroom, and reserve space for future expansion. Getting it wrong leads to the two classic outcomes - an inability to connect networks because ranges collide, or address exhaustion that blocks growth - both of which are expensive to fix after the fact because IP ranges underpin everything built on top. That’s why experienced engineers treat CIDR planning as an up-front architectural decision rather than an afterthought.
Chapter Revision Notes
- A VPC is your isolated, software-defined network in AWS, defined by a CIDR range (e.g. 10.0.0.0/16); it spans all AZs in a Region.
- Subnets are slices of the VPC in exactly one AZ; multi-AZ means subnets in each zone with resources spread across them.
- Public vs private is determined by routing: a public subnet has a route to an internet gateway; a private one does not.
- Put internet-facing components (load balancers) in public subnets and sensitive tiers (app, database) in private subnets.
- Plan CIDR to avoid overlap with networks you’ll connect to and to leave growth headroom.