Public and Private Subnets in an AWS VPC

A two-AZ VPC showing shared public ingress, zonal NAT egress, private application replicas, and an RDS Multi-AZ database.

Explore diagram

Explore on mobile. Create and edit manually or with AI on a computer.

Two-AZ AWS VPC diagram with a shared public Application Load Balancer, NAT gateways A and B, private application replicas, and RDS Multi-AZExplore diagram

Two-AZ AWS VPC diagram with a shared public Application Load Balancer, NAT gateways A and B, private application replicas, and RDS Multi-AZ. Open the image to explore this ready-made diagram.

Overview

A subnet belongs to one Availability Zone; its route table determines whether it is public or private. This two-AZ VPC uses one internet-facing ALB attached to public subnets in both zones, matching private application subnets, and RDS Multi-AZ in private data subnets. Each application replica uses a NAT gateway in its own zone for outbound internet access. The public and database A+B boundaries each summarize two distinct subnets. Internet gateway and route-table resources are omitted from the canvas to keep the ingress, egress, compute, and data responsibilities clear.

Components

  • Public Load Balancer: Spans public subnets in AZ A and AZ B and forwards requests to healthy private application replicas.
  • NAT Gateway: Each AZ has its own public NAT gateway for private compute to initiate outbound connections.
  • Application Server: Matching application instances run in private subnets A and B and receive traffic from the load balancer.
  • RDS Database: Keeps a primary and synchronous standby in separate private data subnets across two AZs.

Network Flow

  1. Internet users connect to the public load balancer.
  2. The load balancer routes application traffic to the private application server.
  3. The application server reads and writes data in the private RDS database.
  4. When outbound access is needed, the application server routes through the NAT gateway.

Customize First

  • Use Auto Scaling to maintain healthy application capacity in both Availability Zones.
  • Replace broad security-group rules with the smallest required source-to-destination rules.
  • Add VPC endpoints for AWS services that should not require NAT egress.

Related AWS guides

Use these practical explanations to compare services, failure boundaries, and operating tradeoffs before adapting the architecture.

Design rationale

Decisions that shape this architecture

1

The route table, not the name, makes a subnet public

A subnet is public when its associated route table contains a route for 0.0.0.0/0 pointing at an internet gateway. That is the whole definition. Two subnets with identical names, tags, and CIDR sizes can differ in exposure purely because one is associated with the public route table and the other is not. This is why VPC reviews should start with route table associations rather than with resource names: a subnet labeled "private" that was associated with the public route table during a migration is public, whatever the tag says.

2

Use the load balancer as the ingress boundary

The application tier stays private and its security group allows traffic only from the load balancer security group, referenced by group ID rather than by CIDR. This removes public addressing from compute entirely, so an instance cannot be reached even if someone later attaches an Elastic IP or opens a port by mistake. It also means the set of internet-reachable resources in the account is small enough to enumerate: the load balancer and the NAT gateway.

3

Separate outbound access from inbound access

Private compute usually still needs the internet for package repositories, operating system updates, and third-party APIs. A NAT gateway provides that outbound path while remaining one-directional: it translates connections initiated from inside the VPC and has no mechanism for accepting connections initiated from outside. This is the distinction an internet gateway does not make, and it is why replacing the NAT gateway with a second internet gateway route would silently make the application tier reachable.

4

Give the load balancer at least two subnets in different zones

The ALB attaches to public subnets in two Availability Zones. The Public AZs A+B boundary summarizes that pair; it does not represent a subnet spanning zones. The DB AZs A+B boundary likewise represents the private subnet pair used by the RDS Multi-AZ primary and standby.

5

Size CIDR blocks for the growth you cannot undo

A subnet CIDR cannot be resized after creation, and AWS reserves five addresses in every subnet (the network address, the VPC router, DNS, one reserved for future use, and the broadcast address), so a /28 yields eleven usable addresses rather than sixteen. Subnets can range from /28 to /16. Private application subnets are the ones that run out first, because container tasks and Elastic Network Interfaces consume addresses far faster than instances do. Allocating a /20 to each private subnet and a /24 to each public subnet costs nothing and avoids a rebuild.

6

Keep the database in its own subnet tier

Placing RDS in dedicated database subnets rather than sharing the application subnets means the database route table, network ACL, and address space can be reasoned about separately. It also makes the blast radius of a permissive application-tier change smaller: widening a security group in the application subnets does not automatically widen anything in the data tier.

Before production

Operational checks

Verify route tables independently for each public and private subnet, and confirm no private subnet has a 0.0.0.0/0 route to an internet gateway.

Check that no subnet relies on the VPC main route table by default. Associate every subnet explicitly so a change to the main table cannot alter exposure.

Restrict security-group rules to reference the next required tier by security group ID rather than by CIDR range.

Confirm that automatic public IP assignment is disabled on every private subnet.

Review NAT data-processing cost and add VPC gateway endpoints for Amazon S3 and DynamoDB, which are free and remove that traffic from the NAT path entirely.

Verify that each private application subnet routes through its same-zone NAT gateway, and test loss of either Availability Zone.

Enable VPC Flow Logs on the VPC so rejected connections are visible during an incident.

Confirm the RDS instance has Publicly Accessible set to false and sits in a DB subnet group containing only private database subnets.

Scope and tradeoffs

What this diagram does not solve

Two zones still require capacity and failure testing

The diagram includes separate application capacity and zonal NAT egress in two Availability Zones. Configure Auto Scaling, size surviving capacity, and test database reconnection and zonal failure. The aggregate public and data boundaries represent separate subnets, not a complete route-table inventory.

Subnet placement is only one security layer

IAM, encryption at rest and in transit, patching, flow logs, network ACLs, and application-level authorization remain necessary even when every resource is private. Network isolation limits reachability; it does not authenticate or authorize the traffic that is allowed through.

NAT gateways are a recurring cost that scales with traffic

A NAT gateway bills for every hour it exists and for every gigabyte it processes, in each Availability Zone. Workloads that pull large container images or write heavily to S3 through NAT often find it is the largest line item in the VPC. Gateway endpoints for S3 and DynamoDB, and interface endpoints for other services, are the usual remedy.

IPv6 uses a different egress mechanism

Native outbound-only IPv6 uses an egress-only internet gateway without translation. IPv6 workloads reaching IPv4 destinations can instead use a NAT gateway with DNS64 and NAT64. The diagram shows the zonal public NAT pattern for IPv4 egress.

Common questions

Frequently asked questions

What makes an AWS subnet public?

A subnet is public when its route table has a route for 0.0.0.0/0 pointing at an internet gateway attached to the VPC. Nothing else about the subnet matters. A resource inside it additionally needs a public or Elastic IP address and permissive security group rules before it can actually communicate with the internet.

What is the difference between a public and a private subnet?

Only the default route. A public subnet routes 0.0.0.0/0 to an internet gateway, which is bidirectional, so resources with public addresses can both initiate and receive internet connections. A private subnet either has no default route or routes 0.0.0.0/0 to a NAT gateway, which only translates connections initiated from inside the VPC. The subnets are otherwise identical AWS resources.

Why is the database in a separate private subnet?

The separation removes any direct internet path and lets the database accept connections only from the application tier on the required port. It also gives the data tier its own route table and network ACL, so a permissive change in the application subnets does not widen access to the database.

Can private subnets access AWS services without a NAT gateway?

Yes. Gateway endpoints for Amazon S3 and DynamoDB route that traffic privately at no charge, and interface endpoints powered by AWS PrivateLink do the same for most other services for an hourly and per-gigabyte fee. Many private subnets need no NAT gateway at all once endpoints cover their dependencies.

How many subnets does a VPC need?

A production web application typically uses six: public, application, and database subnets in each of two Availability Zones. Two is the practical floor for the public tier because an Application Load Balancer requires subnets in at least two zones, and Amazon RDS requires a DB subnet group spanning at least two zones.

How large should each subnet CIDR be?

Subnets can be between /28 and /16, and AWS reserves five addresses in each, so a /28 provides eleven usable addresses. A subnet CIDR cannot be changed after creation. Private application subnets exhaust addresses fastest because container tasks and network interfaces consume them quickly, so a /20 per private subnet and a /24 per public subnet is a common allocation that leaves room to grow.

Does a NAT gateway go in the public or the private subnet?

The zonal public NAT gateways shown here belong in public subnets with a route to the internet gateway. Their private application subnets route 0.0.0.0/0 to the gateway in the same zone. Regional NAT gateways are a separate availability mode without customer-subnet placement; private NAT gateways serve private connectivity rather than internet egress.

Can I convert a public subnet to a private one?

Yes, by associating it with a route table that has no internet gateway route. Existing resources keep any public IP addresses already assigned, so also disable automatic public IP assignment on the subnet and release or replace the addresses on resources that should no longer be reachable.

Do I still need network ACLs if I use security groups?

Usually not for everyday access control. Security groups are stateful and evaluated per resource, which handles almost all application requirements. Network ACLs are stateless and evaluated per subnet, which makes them a coarse second layer: useful for broad denials such as blocking a range at the subnet edge, and awkward as a primary control because return traffic must be allowed explicitly.

Keep exploring

Explore the library
Three-tier AWS diagram with public and internal load balancers, web and application replicas in AZ A and AZ B, and RDS primary and synchronous standby
Getting Startedintermediate

Highly Available Three-Tier Web Application on AWS

The web, application, and data tiers each have a clear role and an explicit availability mechanism. Load balancers select healthy compute replicas, each compute fleet can scale independently, and RDS maintains a standby in another zone. This is a practical starting point for discussing what keeps serving when an instance or an Availability Zone fails.

Explore the architecture
AWS Availability Zone failure architecture diagram with a cross-zone load balancer, application capacity in two AZs, and RDS Multi-AZ failover
Getting Startedbasic

An AWS Application That Survives an Availability Zone Failure

This architecture focuses on one failure question: what happens when an entire Availability Zone becomes unavailable? Healthy application capacity remains in the other zone, the load balancer removes failed targets, and RDS can promote its synchronous standby.

Explore the architecture
Amazon ECS Fargate web architecture diagram with CloudFront, WAF, a multi-AZ ALB, private Fargate tasks, RDS, and ElastiCache
Containersadvanced

Containerized Web Service with Amazon ECS and Fargate

This architecture shows the running service: a protected global edge, a Multi-AZ load balancer, private Fargate tasks, and managed data services. It is a useful starting point for teams outgrowing a single server or a function-based API; deployment, credential delivery, and monitoring can be added around that request path.

Explore the architecture

Ready-made AWS diagram

Explore this AWS architecture

Open the diagram from this guide and explore how it works. Create and edit manually or with AI on a computer.

Explore diagram