Amazon VPC (Virtual Private Cloud)

Amazon VPC is the network layer of AWS — a logically isolated section of the AWS cloud where you launch resources into subnets of your own IP ranges. Every EC2, RDS, Lambda-VPC, EKS node, and most other services live in a VPC, making it the foundation of AWS network security and connectivity.


Core Building Blocks:


Connecting VPCs and On-Premises:


Reference Design for Application VPCs:


Common Gotchas:


Service Limits & Quotas:


Pricing Model:


Code Example:

A minimal Terraform-style configuration creating a VPC with public and private subnets across 2 AZs and a single NAT Gateway. Using AWS CLI for clarity:

# 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=app-vpc}]' \
  --query 'Vpc.VpcId' --output text)

aws ec2 modify-vpc-attribute --vpc-id $VPC_ID --enable-dns-hostnames

# 2) Public + private subnets in two AZs
PUB_A=$(aws ec2 create-subnet --vpc-id $VPC_ID \
  --cidr-block 10.0.0.0/24 --availability-zone us-west-2a \
  --query 'Subnet.SubnetId' --output text)
PUB_B=$(aws ec2 create-subnet --vpc-id $VPC_ID \
  --cidr-block 10.0.1.0/24 --availability-zone us-west-2b \
  --query 'Subnet.SubnetId' --output text)
PRIV_A=$(aws ec2 create-subnet --vpc-id $VPC_ID \
  --cidr-block 10.0.10.0/24 --availability-zone us-west-2a \
  --query 'Subnet.SubnetId' --output text)
PRIV_B=$(aws ec2 create-subnet --vpc-id $VPC_ID \
  --cidr-block 10.0.11.0/24 --availability-zone us-west-2b \
  --query 'Subnet.SubnetId' --output text)

# 3) IGW + default route for the public subnets
IGW_ID=$(aws ec2 create-internet-gateway \
  --query 'InternetGateway.InternetGatewayId' --output text)
aws ec2 attach-internet-gateway --vpc-id $VPC_ID --internet-gateway-id $IGW_ID

PUB_RT=$(aws ec2 create-route-table --vpc-id $VPC_ID \
  --query 'RouteTable.RouteTableId' --output text)
aws ec2 create-route --route-table-id $PUB_RT \
  --destination-cidr-block 0.0.0.0/0 --gateway-id $IGW_ID

# 4) S3 Gateway Endpoint — free egress to S3
aws ec2 create-vpc-endpoint --vpc-id $VPC_ID \
  --service-name com.amazonaws.us-west-2.s3 \
  --route-table-ids $PUB_RT


Common Interview Questions:

What is the difference between a Security Group and a Network ACL?

Security Groups are stateful and instance-level — they track flows so return traffic is implicitly allowed; they support allow rules only. NACLs are stateless and subnet-level — both directions must be explicitly allowed; they support both allow and deny rules and are evaluated in numeric order. SGs handle 95% of access control; NACLs are useful for broad deny patterns at the subnet edge.

How do public and private subnets actually differ?

The distinction is purely about routing. A subnet is "public" if its route table has a default route (0.0.0.0/0) pointing to an Internet Gateway and instances have public IPs. A subnet is "private" if its default route points to a NAT Gateway (egress-only) or has no internet route. AWS doesn't explicitly tag subnets — it's a convention based on routing.

VPC Peering vs. Transit Gateway — when to use each?

VPC Peering is point-to-point and non-transitive — fine for two or three VPCs. Beyond that, the mesh becomes unmanageable (n*(n-1)/2 connections). Transit Gateway is a hub-and-spoke router; each VPC attaches once and TGW handles all routing. TGW is also the bridge to Direct Connect and VPN. Peering is free for traffic; TGW costs per attachment-hour and per GB.

What is a VPC Endpoint and why use one?

A VPC Endpoint provides private connectivity from your VPC to AWS services without traversing the public internet or NAT. Two types: Gateway Endpoints (free, only for S3 and DynamoDB) and Interface Endpoints (paid, PrivateLink, for almost every other service). Using endpoints reduces NAT data-processing fees, eliminates a public-internet dependency, and lets private subnets call AWS APIs.

How would you design VPC CIDR blocks for a multi-account organization?

Centrally allocate non-overlapping CIDRs from a master IPAM pool (AWS IPAM helps). Reserve clear regions in the address space (e.g., 10.0.0.0/8 for AWS, segmented per environment and account). Avoid the common 10.0.0.0/16 default in every account because it'll bite you the moment you peer or use Transit Gateway. Leave headroom — VPC CIDRs cannot overlap their attached extension blocks either.

How does NAT Gateway pricing trip people up?

NAT GW costs per-hour and per-GB-processed. Workloads that pull large container images, push logs to non-VPC destinations, or fetch packages from public repos can rack up hundreds or thousands of dollars per month. Mitigations: S3 Gateway Endpoints (free), ECR Interface Endpoints, pull-through cache, route logs to CloudWatch via interface endpoint, and one NAT per AZ (not per region) to avoid cross-AZ surcharges on top.