AWS Learning Journey

Public or Private? Your First AWS VPC, Explained

Subnets, route tables, internet gateways, NAT gateways, security groups, and network ACLs — and the one route that makes a subnet "public."

9 min read · 1722 words
AWSNetworkingAmazon VPCCloud ArchitectureDevOps
Public or Private? Your First AWS VPC, Explained cover image

AWS from Zero to Production — Phase 3, Part 2 of 5 · See the full series roadmap


Here’s a question that trips up a surprising number of engineers:

What makes a subnet public?

It’s not a checkbox called “public.” It’s not the name you gave it. It’s not even whether instances inside it have public IP addresses.

A subnet is public because its route table sends internet-bound traffic to an internet gateway. That’s it. One route.

Once that clicks, the rest of the Amazon VPC falls into place. This article walks through every building block — and how they fit together into a network you’d actually run production on.

What you’ll walk away with


What is a VPC?

An Amazon Virtual Private Cloud (VPC) is your own isolated network inside an AWS Region. You choose its IP range, split it into subnets, and decide what can reach what.

Default vs. custom VPCs

Every Region in your account comes with a default VPC:

That’s great for a quick test. It’s a poor fit for production, where you want private subnets, your own CIDR plan, and nothing public by accident.

Engineer’s note: For real workloads, create a custom VPC. Many teams also delete or lock down default VPCs so nobody launches resources there by mistake.


Subnets: where resources actually live

A subnet is a slice of your VPC’s CIDR block in one Availability Zone.

The three-tier layout

Most production VPCs look like this:

VPC 10.0.0.0/16
|
+-- AZ a
|     public    10.0.1.0/24    load balancers, NAT gateway
|     app       10.0.11.0/24   app servers, containers
|     data      10.0.21.0/24   databases
|
+-- AZ b
      public    10.0.2.0/24
      app       10.0.12.0/24
      data      10.0.22.0/24

Route tables: the traffic rules

Every subnet is associated with exactly one route table. Each route says: “traffic for this destination goes to this target.”

Every route table includes a local route for the VPC’s own CIDR, so all subnets can reach each other by default. Security groups and network ACLs then decide what’s actually allowed.

Public subnet route table

Destination     Target
10.0.0.0/16     local
0.0.0.0/0       igw-0abc123     <- this line makes it public

Private subnet route table

Destination     Target
10.0.0.0/16     local
0.0.0.0/0       nat-0def456     <- outbound only, through NAT

Isolated subnet route table

Destination     Target
10.0.0.0/16     local           <- no internet at all

Data subnets are often isolated — no route to the internet in either direction.


Internet gateways

An internet gateway (IGW) connects a VPC to the internet.

For a resource to be reachable from the internet, it needs all three:

  1. A subnet whose route table sends 0.0.0.0/0 to the IGW
  2. A public IP or Elastic IP address
  3. A security group and network ACL that allow the traffic

Miss any one, and the connection fails.


NAT gateways: outbound-only internet

Private servers still need to reach the internet sometimes — to download packages, call external APIs, or reach AWS services without endpoints.

A NAT gateway lets them connect out while blocking connections in.

Cost warning: NAT gateways charge per hour and per GB processed. They’re one of the most common surprise line items on AWS bills. Delete them after labs, and consider VPC endpoints for AWS services (Part 3) to keep that traffic off the NAT gateway.


Elastic IP addresses

An Elastic IP address is a static public IPv4 address that you allocate to your account and can move between resources.

Watch out: Release Elastic IPs you no longer need. An unattached one quietly costs money every hour.


Security groups: the firewall around each resource

A security group is a stateful firewall attached to a resource’s network interface — an EC2 instance, a load balancer, an RDS database, or an ECS task.

Chaining security groups

alb-sg     inbound 443 from 0.0.0.0/0
app-sg     inbound 8080 from alb-sg
db-sg      inbound 5432 from app-sg

Nobody hard-codes IP addresses. If the app scales from 2 to 20 servers, they all carry app-sg, and the database accepts all of them — and nothing else.


Network ACLs: the firewall around each subnet

A network ACL (NACL) filters traffic at the subnet boundary.

Security groups vs. NACLs

Engineer’s note: Most teams leave NACLs at the default and do everything with security groups. If you customize NACLs, test carefully — forgetting ephemeral ports is the classic outage.


VPC Flow Logs: who talked to whom

VPC Flow Logs record metadata about IP traffic: source, destination, ports, protocol, bytes, and whether it was ACCEPTED or REJECTED.

A typical record looks like this:

2 123456789012 eni-0a1b2c3d 10.0.11.25 10.0.21.40 49152 5432 6 10 840 1735689600 1735689660 REJECT OK

That REJECT on port 5432 tells you a security group or NACL blocked a database connection. Flow logs turn “it doesn’t connect” into evidence.

Cost note: Flow logs are charged by data ingested at the destination. Send them to S3 for cheaper long-term storage, or filter to rejected traffic only while troubleshooting.


DHCP option sets

When resources start, they get network settings through DHCP: the DNS server, domain name, and NTP servers.

Most VPCs never need to change this. Part 3 shows the more common hybrid approach: Route 53 Resolver.


Common mistakes


Key takeaways


Quick self-check

Test yourself before moving on:

  1. How many usable IP addresses does a /24 subnet have on AWS?
  2. An instance has a public IP, but its subnet routes 0.0.0.0/0 to a NAT gateway. Can the internet reach it?
  3. Why should the database security group reference app-sg instead of an IP range?
  4. You allowed inbound port 443 in a NACL, but responses never arrive. Why?

Answers

  1. 251 — AWS reserves five addresses.
  2. No. Without a route to an internet gateway, the subnet isn’t public.
  3. It automatically includes every app resource, however many there are, and nothing else.
  4. NACLs are stateless — you also need an outbound rule for the ephemeral ports.

What’s next

In Part 3, we connect VPCs to each other and to the outside world: peering, Transit Gateway, PrivateLink, VPC endpoints, VPNs, Direct Connect, and hybrid DNS.

Do you use network ACLs, or leave them at the default? Tell me in the comments.


Share this article

LinkedIn post draft