AWS VPC and Subnet: A Practical Guide to Network Design

AWS VPC and Subnets: A Practical Guide

Amazon Virtual Private Cloud (VPC) lets you create a logically isolated network for resources in Amazon Web Services (AWS). Within a VPC, you choose IP address ranges, create subnets, configure routing, and control traffic. Understanding how VPCs and subnets work is essential for designing secure, reliable AWS environments.

What Is an AWS VPC?

A VPC is a virtual network dedicated to your AWS account. It operates within a single AWS Region and can span multiple Availability Zones in that Region. You can place resources such as Amazon EC2 instances, load balancers, and databases in the VPC, subject to each service’s networking options.

When creating a VPC, you assign it an IP address range using Classless Inter-Domain Routing (CIDR) notation. For example, 10.0.0.0/16 provides a large private IPv4 address range. You can also add secondary IPv4 CIDR blocks or an IPv6 range when needed.

Each VPC includes a route table entry for local traffic, allowing resources in the VPC to communicate with one another when other network controls permit it. A VPC does not automatically provide internet access; that requires additional routing and connectivity configuration.

What Is a Subnet?

A subnet is a segment of a VPC’s IP address range. Subnets help organize resources and determine how their network traffic is routed. Each subnet belongs to one Availability Zone, so a subnet cannot span multiple Availability Zones.

For example, a VPC with the CIDR block 10.0.0.0/16 might contain these subnets:

  • 10.0.1.0/24 in one Availability Zone
  • 10.0.2.0/24 in another Availability Zone
  • 10.0.3.0/24 in a third Availability Zone

Subnets must use address ranges contained within the VPC’s CIDR blocks, and subnet ranges within the same VPC cannot overlap. For an IPv4 subnet, AWS reserves five addresses in each range, so those addresses cannot be assigned to resources. For example, a /24 IPv4 subnet has 256 addresses, of which 251 are available for use.

Public and Private Subnets

A subnet is commonly described as public or private based on its routing configuration:

  • Public subnet: Its associated route table has a route to an internet gateway for internet-bound traffic.
  • Private subnet: It does not have a direct route to an internet gateway. It may still have outbound internet access through a NAT gateway or another network path.

A route to an internet gateway alone does not make an EC2 instance reachable from the internet. The instance also needs a public IPv4 address or Elastic IP address, and its security group and network access control list (network ACL) must allow the relevant traffic. For IPv6, an instance with a globally routable IPv6 address may communicate through an internet gateway when routing and security rules permit it.

A NAT gateway is commonly placed in a public subnet to allow resources in private subnets to initiate connections to the internet without accepting unsolicited inbound connections through that NAT gateway. NAT gateways are generally deployed per Availability Zone for resilience and to reduce cross-zone traffic. They incur charges, so cost and availability should be considered during planning.

Route Tables and Traffic Flow

Each subnet is associated with a route table. The route table determines where traffic is sent based on its destination IP address. A VPC’s main route table is used by subnets that have not been explicitly associated with another route table.

A typical public subnet route table might include:

  • A local route for communication within the VPC
  • A default route, such as 0.0.0.0/0, pointing to an internet gateway

A typical private subnet route table might include a local route and, if outbound internet access is needed, a default route pointing to a NAT gateway. Private subnets can also route traffic to other destinations, such as a corporate network through a VPN or AWS Direct Connect, or to AWS services through VPC endpoints.

Security Groups and Network ACLs

Routing determines where traffic can go, while security controls determine what traffic is allowed.

  • Security groups act as stateful virtual firewalls for supported resources, such as EC2 network interfaces. They allow rules for inbound and outbound traffic.
  • Network ACLs act as stateless filters at the subnet level. They can allow or deny traffic, and return traffic must be permitted by the rules as well.

Security groups are often the primary control for resource-level access. Network ACLs can provide an additional subnet-level layer, but overly restrictive rules can unintentionally block legitimate traffic.

Planning a VPC and Subnet Layout

Thoughtful address planning can prevent difficult network changes later. Before creating a VPC, consider the following:

  1. Choose CIDR ranges carefully. Avoid overlap with networks that may connect to the VPC, including office networks, other VPCs, and partner environments.
  2. Plan for growth. Leave enough address space for additional subnets, applications, and Availability Zones.
  3. Use multiple Availability Zones. For production workloads, distribute appropriate resources across Availability Zones to improve resilience.
  4. Separate workloads by purpose. Common patterns include public subnets for internet-facing load balancers and private subnets for application servers and databases.
  5. Limit public exposure. Keep resources private unless they need direct inbound connectivity, and grant only the access required.
  6. Account for IPv6 and AWS services. Decide whether the environment needs IPv6 and whether VPC endpoints can provide private access to supported AWS services.

Example Architecture

A basic multi-tier application could use one VPC across three Availability Zones. Each zone could contain a public subnet for an internet-facing load balancer and a private subnet for application servers. Database resources could be placed in separate private subnets with stricter security group rules. The public subnets would route internet-bound traffic through an internet gateway, while private application subnets could use NAT gateways for required outbound connections.

This design separates internet-facing components from internal services and provides room to distribute workloads across Availability Zones. The exact architecture should reflect the application’s availability, security, connectivity, and cost requirements.

Key Takeaways

A VPC defines an isolated network in an AWS Region, while subnets divide that network into smaller ranges, each located in a single Availability Zone. Route tables control traffic paths, and internet gateways, NAT gateways, security groups, and network ACLs determine how resources connect and what traffic is allowed. With careful IP planning and a clear subnet design, a VPC can provide a flexible foundation for secure and resilient AWS workloads.

 

AWS VPC and Subnet FAQs: Key Concepts, Setup, IP Addresses, and Routing

  1. What is an AWS VPC, and how does it work?
  2. What is the difference between an AWS VPC and a subnet?
  3. What is the difference between a public subnet and a private subnet?
  4. How do I create a VPC and subnet in AWS?
  5. How many IP addresses are available in an AWS subnet?
  6. How do VPC route tables control traffic between subnets and the internet?

What is an AWS VPC, and how does it work?

An Amazon Virtual Private Cloud (VPC) is a logically isolated network in AWS where you can launch and connect resources such as servers and databases. You choose the VPC’s IP address range, divide it into subnets, and use route tables and gateways to control how traffic moves within the network or reaches the internet and other networks. Security groups and network access control lists help regulate which traffic is allowed, giving you control over connectivity and isolation.

What is the difference between an AWS VPC and a subnet?

An AWS VPC is a logically isolated virtual network in an AWS Region, where you define the overall IP address range and configure network connectivity and routing. A subnet is a smaller section of that VPC’s IP address range, used to organize resources and control their traffic paths. Each subnet belongs to a single Availability Zone and can be configured as public or private based on its route table. In short, the VPC is the overall network, while subnets are the smaller network segments within it.

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

A public subnet has a route in its associated route table to an internet gateway, allowing resources with public IP addresses to communicate directly with the internet when security rules permit. A private subnet has no direct route to an internet gateway, so its resources aren’t directly reachable from the internet. They can still access the internet for outbound connections through a NAT gateway, or connect to other networks through options such as a VPN or VPC endpoint.

How do I create a VPC and subnet in AWS?

To create a VPC and subnet, open the Amazon VPC console, choose Your VPCs, and select Create VPC. Enter a name and an IPv4 CIDR block, such as 10.0.0.0/16, then create the VPC. Next, choose Subnets and Create subnet, select your VPC and an Availability Zone, and enter a non-overlapping CIDR range within the VPC, such as 10.0.1.0/24. To give resources internet connectivity, configure the appropriate route table and gateway; creating a subnet alone does not make it public or provide internet access.

How many IP addresses are available in an AWS subnet?

The number of IP addresses in an AWS subnet depends on its CIDR block. For IPv4 subnets, AWS reserves five addresses in each subnet, so they are unavailable for your resources. For example, a /24 subnet contains 256 total addresses, with 251 available to use; a /28 contains 16 total addresses, with 11 available. IPv6 subnet addresses are handled differently: AWS does not reserve five addresses in each IPv6 subnet, though individual services may have their own address-use requirements.

How do VPC route tables control traffic between subnets and the internet?

Each subnet is associated with a route table that directs traffic based on its destination IP address. A VPC’s local route allows communication between its subnets, while a route such as 0.0.0.0/0 to an internet gateway enables internet routing for a public subnet. Resources in that subnet also need an appropriate public IP address and permissive security rules to communicate directly with the internet. Private subnets typically have no direct internet-gateway route; when outbound internet access is needed, their route table can send traffic to a NAT gateway in a public subnet. Security groups and network ACLs separately determine which traffic is allowed.