Skip to the workspace
Pebellslearn by building
VPC — Your Private Network  ›  Lesson

Subnets — Public and Private

Subnets 14 minA subnet is a slice of a VPC's address range in one Availability Zone, and it is public only if its route table sends internet traffic to an internet gateway; otherwise it is private.

aws / Subnets — Public and Private

Explore each scene at your own pace.

01 · The rule

The rule

Subnets — Public and Private

Inkwell's VPC now has 65,536 addresses, but one big flat network would put the order database on the same footing as the public web server. Subnets let Inkwell carve the VPC into rooms: some with a door to the street, some deliberately without one.

The rule

A subnet is public only if its route table leads to an internet gateway.

A subnet is a slice of the VPC's CIDR block that lives in exactly one Availability Zone. Its block must sit inside the VPC's block and must not overlap any other subnet.

"Public" and "private" are not tick boxes on a subnet. They describe how traffic is routed:

  • A public subnet has a route table with a route for 0.0.0.0/0 (everywhere) pointing to the VPC's internet gateway. Instances there can talk to the internet directly, if they also have a public IP address.
  • A private subnet has no such route. Nothing on the internet can start a connection to its instances.

Inkwell's layout, one pair per zone:

10.0.1.0/24   public-1a    ap-south-1a
10.0.2.0/24   public-1b    ap-south-1b
10.0.11.0/24  private-1a   ap-south-1a
10.0.12.0/24  private-1b   ap-south-1b

The web servers go in the public subnets; the database goes in the private ones.

An instance in a public subnet still needs a public IPv4 address. The automatically assigned one changes whenever the instance is stopped and started. An Elastic IP is a static public address you keep until you release it, and can move between instances. AWS charges for public IPv4 addresses, whether attached or idle, so release ones you do not need.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.