← Back to Questions
AWS

Difference between Public vs Private Subnet?

Learn Difference between Public vs Private Subnet? with simple explanations, real-time examples, interview tips and practical use cases.

In AWS VPC architecture, subnets are logical divisions of a VPC network.

The two most important subnet types are:

  • Public Subnet
  • Private Subnet
Simple Definition: A Public Subnet allows resources to communicate directly with the internet, while a Private Subnet restricts direct internet access for better security.

High-Level Architecture

                    AWS VPC
---------------------------------------------------
|                                                 |
|   Public Subnet         Private Subnet          |
|                                                 |
|   Web Servers           Application Servers     |
|   Load Balancers        Databases               |
|                                                 |
---------------------------------------------------
            |
     Internet Gateway
            |
         Internet
    

Main Difference

Feature Public Subnet Private Subnet
Internet Access Direct access allowed No direct access
Route to Internet Gateway Yes No
Public IP Support Yes Usually No
Security Level Lower Higher
Common Resources Load Balancers, Web Servers Databases, Internal APIs

What is a Public Subnet?

A Public Subnet is a subnet that has a route to an Internet Gateway (IGW).

Public Subnet Architecture

Internet
    |
Internet Gateway
    |
Public Route Table
    |
Public Subnet
    |
EC2 Web Server
    

Characteristics of Public Subnet

  • Connected to Internet Gateway
  • Can assign public IP addresses
  • Internet-accessible resources
  • Used for external traffic

Typical Resources in Public Subnet

  • Web servers
  • Application Load Balancers
  • Bastion Hosts
  • NAT Gateways

Example Route Table for Public Subnet

Destination Target
10.0.0.0/16 Local
0.0.0.0/0 Internet Gateway

Real-World Example

Users
   |
Internet
   |
Load Balancer
   |
Web Server (Public Subnet)
    

Advantages of Public Subnet

  • Internet accessibility
  • Easy external communication
  • Suitable for frontend applications

Disadvantages of Public Subnet

  • Higher security exposure
  • Public attack surface
  • Requires strict firewall rules

What is a Private Subnet?

A Private Subnet does not have a direct route to the Internet Gateway.

Private Subnet Architecture

Private Subnet
      |
Application Servers
      |
Databases
      |
No Direct Internet Access
    

Characteristics of Private Subnet

  • No direct internet access
  • Higher security
  • Internal communication only
  • Protected backend infrastructure

Typical Resources in Private Subnet

  • Application servers
  • Microservices
  • Databases
  • Redis cache servers

Example Route Table for Private Subnet

Destination Target
10.0.0.0/16 Local

Private Subnet with NAT Gateway

Private subnet resources may still require outbound internet access for software updates or API calls.

Architecture

Private EC2
      |
NAT Gateway
      |
Internet Gateway
      |
Internet
    

Advantages of Private Subnet

  • Better security
  • Reduced attack surface
  • Suitable for sensitive systems

Disadvantages of Private Subnet

  • No direct public access
  • More complex networking setup

Public vs Private Subnet Architecture

                    Internet
                        |
                Internet Gateway
                        |
-------------------------------------------------
|               Public Subnet                   |
|                                               |
|   Load Balancer                               |
|   Web Server                                  |
-------------------------------------------------
                        |
-------------------------------------------------
|               Private Subnet                  |
|                                               |
|   Application Server                          |
|   Database                                    |
-------------------------------------------------
    

Security Comparison

Security Aspect Public Subnet Private Subnet
Direct Internet Exposure Yes No
Risk Level Higher Lower
Attack Surface Large Small
Firewall Importance Critical Important

Production Architecture Example

Users
   |
CloudFront CDN
   |
Application Load Balancer
   |
Public Web Servers
   |
Private Application Servers
   |
Private Database Servers
    

Why Databases Should be in Private Subnets

Databases contain sensitive data and should never be exposed directly to the internet.

Secure Database Architecture

Internet
   |
Web Layer
   |
Application Layer
   |
Private Database
    

Common Interview Scenario

Question:

Why do we place Load Balancers in Public Subnets and Databases in Private Subnets?

Answer:

Load Balancers need internet access to receive user traffic, while databases should remain isolated for security reasons.

Best Practices

  • Keep databases in private subnets
  • Use NAT Gateway for outbound internet access
  • Restrict public subnet exposure
  • Use Security Groups and NACLs properly
  • Deploy across multiple Availability Zones

Common Mistakes

  • Placing databases in public subnets
  • Opening unnecessary ports
  • Using public IPs for internal services
  • Improper route table configuration

Enterprise-Level Architecture

Availability Zone 1
-------------------------
Public Subnet
Private App Subnet
Private DB Subnet
-------------------------

Availability Zone 2
-------------------------
Public Subnet
Private App Subnet
Private DB Subnet
-------------------------
    

Interview Answer

A Public Subnet is a subnet that has a route to an Internet Gateway, allowing resources to communicate directly with the internet.

A Private Subnet does not have direct internet access and is used for internal resources such as databases and backend applications.

Public Subnets are commonly used for web servers and load balancers, while Private Subnets are used for application servers and databases to improve security.

Quick Summary Table

Feature Public Subnet Private Subnet
Internet Access Direct Indirect or None
Public IP Supported Usually Not Used
Security Less Secure More Secure
Examples Web Servers Databases

Useful Internal Links

Final Conclusion

Public and Private Subnets are fundamental building blocks of AWS VPC architecture.

Public Subnets allow internet-facing services, while Private Subnets provide secure internal networking for backend systems.

Proper subnet design is critical for building secure, scalable, and enterprise-grade cloud applications.

Why this AWS question is important?

This interview question helps candidates understand real-time backend development concepts, practical problem solving, coding fundamentals, system design basics and production-ready application behavior.

Practice this question carefully for Java backend roles, Spring Boot developer interviews, microservices interviews, company interviews and full-stack developer preparation.

About the Author

Naresh Kumar is a Senior Java Backend Engineer with experience building enterprise applications using Java, Spring Boot, Microservices, Docker, Kubernetes and Cloud technologies.