Mastering VPC Design: Public and Private Subnets Explained

Roshni Wakodikar
3 min readJan 3, 2025

--

In the ever-evolving world of cloud computing, understanding how to design a robust Virtual Private Cloud (VPC) is essential for any AWS practitioner. Whether you’re an aspiring cloud engineer or a seasoned DevOps pro, mastering VPC design with public and private subnets is a game-changer for building secure, scalable, and efficient infrastructure. Let’s dive into the what, why, and how of VPCs with a human touch.

What is a VPC?

A VPC (Virtual Private Cloud) is like your personal gated community in the cloud. It provides a logically isolated section of AWS where you can launch resources, define rules, and establish secure communication. Within this VPC, you can create subnets, which are like different neighborhoods, each designed for specific purposes. The two primary types of subnets are:

  • Public Subnets: For resources that need internet access (like web servers).
  • Private Subnets: For internal resources that need to stay hidden (like databases).

Why Split into Public and Private Subnets?

Think of public and private subnets as the front office and the back office of a company. Each has its own role:

Public Subnets

  • Accessible from the internet.
  • Typically used for web servers, bastion hosts, or load balancers.

Private Subnets

  • Hidden from direct internet access.
  • Used for sensitive resources like databases, backend services, or application servers.

This separation is critical for security. By isolating sensitive resources in private subnets, you minimize exposure to potential threats while still allowing controlled access via public-facing components.

Designing a VPC: The Blueprint

Let’s walk through the design of a VPC with public and private subnets. Here’s a high-level overview of what we’ll set up:

  1. VPC: A secure network environment with a custom CIDR block (e.g., 10.0.0.0/16).
  2. Public Subnets: Two subnets in different availability zones for high availability (e.g., 10.0.1.0/24 and 10.0.2.0/24).
  3. Private Subnets: Two subnets in different availability zones (e.g., 10.0.3.0/24 and 10.0.4.0/24).
  4. Internet Gateway (IGW): Provides internet access for public subnets.
  5. NAT Gateway: Enables private subnets to access the internet for updates or outbound communication.
  6. Route Tables: Define how traffic flows within the VPC.

Step-by-Step Guide to VPC Design

Step 1: Create Your VPC

Start by creating a VPC with a custom CIDR block:

  • CIDR: 10.0.0.0/16 (this allows for up to 65,536 IP addresses).

Step 2: Define Subnets

Divide the CIDR into smaller blocks:

  • Public Subnet 1: 10.0.1.0/24
  • Public Subnet 2: 10.0.2.0/24
  • Private Subnet 1: 10.0.3.0/24
  • Private Subnet 2: 10.0.4.0/24

Step 3: Attach an Internet Gateway

Attach an Internet Gateway (IGW) to the VPC. This is like installing a front door for public-facing traffic.

Step 4: Configure Route Tables

Create two route tables:

Public Subnets

  • Accessible from the internet.
  • Typically used for web servers, bastion hosts, or load balancers.

Private Subnets

  • Hidden from direct internet access.
  • Used for sensitive resources like databases, backend services, or application servers.

Step 5: Add a NAT Gateway

A NAT Gateway acts like a translator, enabling resources in private subnets to access the internet without exposing them.

  • Place the NAT Gateway in one of the public subnets.
  • Update the private route table to route traffic through the NAT Gateway.

Step 6: Secure Your VPC

  • Use Security Groups to control traffic to/from individual resources.
  • Use Network ACLs (NACLs) for subnet-level security.

The Big Picture: Traffic Flow

Here’s how everything works together:

Inbound Traffic:

  • Users access the application via a public-facing Load Balancer in the public subnet.
  • The Load Balancer forwards requests to application servers in private subnets.

Outbound Traffic:

  • Application servers in private subnets use the NAT Gateway for updates or external APIs.
  • Database servers in private subnets stay completely hidden.

Best Practices for VPC Design

  1. High Availability: Always spread resources across multiple availability zones.
  2. Least Privilege: Grant the minimum required permissions for security groups and NACLs.
  3. Monitoring: Enable VPC Flow Logs for detailed traffic analysis.
  4. Tagging: Tag resources for easier management and billing.

The next time you set up a VPC, remember: it’s not just about connecting resources — it’s about enabling seamless communication while keeping your sensitive data safe. Happy architecting!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response