Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
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.

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.

The shortcut

For each resource ask "Must strangers on the internet start a conversation with it?" Yes → public subnet. No → private subnet. When unsure, choose private.

Placing Inkwell's resourcesStep 1 of 4
  1. Web servers

    Shoppers must reach them. Public subnets, one per zone.

The trap: naming a subnet "public" does nothing. If its route table has no route to the internet gateway, it is private however it is labelled; if a "private" subnet gains that route, it is now public.

Drills

Answer fast — trust the rule.

quick drill

What makes a subnet public?

quick drill

How many Availability Zones can one subnet span?

quick drill

Where should Inkwell put its order database?

quick drill

Inkwell stops and starts a web server that has an automatic public IP. What happens to that address?

Remember

  • A subnet lives in one AZ; it is public only if its route table leads to an internet gateway.
  • Ask: must strangers start a conversation with it? If not, private.
  • Trap: labels do nothing; routes decide. Elastic IPs give a fixed public address, at a charge.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainLay out Inkwell's subnets

Design Inkwell's subnets inside 10.0.0.0/16 across two Availability Zones. Say which subnets are public and which are private, give each a CIDR block, say where the web servers and the database go, and explain what actually makes a subnet public.