Setting Up a VPC on AWS: Cloud Networking Fundamentals

Khimananda Oli 7 min read Database
Setting Up a VPC on AWS: Cloud Networking Fundamentals

By Khimananda Oli | Last reviewed: August 2026

Misconfigured networking is the most common cause of production outages and security breaches I see during cloud audits. Setting up a VPC on AWS: Cloud Networking Fundamentals requires understanding isolation boundaries, not just clicking through the console wizard. This guide walks you through building a resilient, secure network foundation that supports scaling applications and compliance requirements from day one.

AWS VPC Architecture OverviewPublic Subnet (AZ-a)BastionNAT GWPrivate Subnet (AZ-a)App ServerDatabaseIGWRoute Table directs 0.0.0.0/0 → IGW (Public) or NAT GW (Private)
Core components when setting up a VPC on AWS: Internet Gateway for public ingress, NAT Gateway for private egress, and isolated subnets.

How do you plan IP addressing when setting up a VPC on AWS?

IP planning is irreversible once peering or transit gateway connections are established. When setting up a VPC on AWS, choose a CIDR block that accommodates future growth without overlapping your on-premises networks or other cloud environments. A /16 block (65,536 addresses) provides ample room for most application VPCs, while a /20 is often sufficient for microservice-specific networks.

Subnet Sizing Strategy

Avoid the common mistake of creating oversized public subnets. Public subnets should only host load balancers, bastions, and NAT gateways. Allocate smaller CIDRs (/24 or /26) for public tiers and larger blocks (/22 or /23) for private application and database subnets where your actual workloads reside.

  • Public Subnets: /24 per AZ (251 usable IPs) — sufficient for ELBs and jump hosts.
  • Application Subnets: /22 per AZ (1,019 usable IPs) — allows horizontal auto-scaling.
  • Data Subnets: /24 per AZ — databases rarely require massive IP density but need isolation.
  • Reserved: Always leave unallocated space within your VPC CIDR for future subnet creation.

If you are migrating existing infrastructure, review our guide on migrating a website from shared hosting to the cloud to understand how legacy IP schemes map to modern VPC designs.

What is the correct subnet and gateway configuration for AWS VPC?

The distinction between public and private subnets in AWS is purely determined by routing, not by any inherent subnet property. A subnet becomes "public" only when its route table contains a default route (0.0.0.0/0) pointing to an Internet Gateway (IGW). Without this explicit route, even a subnet with public IP-enabled instances remains effectively private.

Configuring Gateways via Terraform

Infrastructure as Code prevents drift and documents intent. When setting up a VPC on AWS using Terraform, define your gateways explicitly rather than relying on module defaults that may change. See our practical guide to Infrastructure as Code with Terraform for foundational patterns.

<!-- Terraform: Internet and NAT Gateway Configuration -->
resource "aws_internet_gateway" "main" {
  vpc_id = aws_vpc.main.id
  tags   = { Name = "${var.project}-igw" }
}

resource "aws_eip" "nat" {
  domain = "vpc"
  tags   = { Name = "${var.project}-nat-eip" }
}

resource "aws_nat_gateway" "main" {
  allocation_id = aws_eip.nat.id
  subnet_id     = aws_subnet.public_a.id
  tags          = { Name = "${var.project}-nat-gw" }
  
  # Ensure IGW exists before NAT GW creation
  depends_on = [aws_internet_gateway.main]
}

A critical operational detail: NAT Gateways must reside in public subnets but serve private subnets. For high availability, deploy one NAT Gateway per Availability Zone. While a single NAT GW reduces cost, it creates a single point of failure; if that AZ goes down, all private subnet egress traffic stops regardless of your multi-AZ application deployment.

How do you secure traffic when setting up a VPC on AWS?

Security in AWS networking operates at two distinct layers: Security Groups (stateful firewalls at the ENI level) and Network ACLs (stateless filters at the subnet boundary). In practice, Security Groups handle 95% of access control logic because they support connection tracking and reference-based rules.

Inbound Traffic Evaluation FlowInternetNetwork ACL(Stateless)Security Group(Stateful)EC2 InstanceALLOW rule requiredImplicit DENY + Stateful ReturnResponse traffic bypasses NACL inbound rules due to stateful SG tracking
Traffic evaluation order when setting up a VPC on AWS: Network ACLs filter first, then Security Groups apply stateful inspection at the instance.

Principle of Least Privilege in Practice

Never use 0.0.0.0/0 in Security Group ingress rules except for public-facing load balancers on ports 80/443. For backend communication, reference Security Group IDs as sources instead of CIDR blocks. This allows dynamic IP assignment while maintaining strict access control.

  1. Create tier-specific Security Groups: Separate SGs for web, app, and data layers.
  2. Reference SG IDs, not IPs: Use source_security_group_id to allow inter-tier traffic.
  3. Restrict SSH/RDP: Limit management port access to bastion or SSM Session Manager only.
  4. Audit quarterly: Remove unused rules; stale permissions accumulate silently.

For teams managing sensitive data, align your VPC security model with compliance frameworks. My experience with SOC 2 and ISO 27001 audits shows that documented, automated security group management satisfies auditors far better than manual console changes. If you're deploying applications that require hardened baselines, start with our secure Ubuntu server setup guide to complement network-layer controls.

When should you use NAT Gateway versus VPC Endpoints?

NAT Gateways enable outbound internet access for private subnets but incur hourly charges plus data processing fees. VPC Endpoints (Gateway and Interface types) provide private connectivity to AWS services without traversing the public internet, often at lower cost and higher security.

FeatureNAT GatewayVPC Endpoint (Interface)VPC Endpoint (Gateway)
Use CaseGeneral internet egressPrivate access to AWS APIs (S3, DynamoDB excluded)S3 and DynamoDB only
Cost Model$0.045/hr + $0.045/GB processed$0.01/hr/AZ + $0.01/GB processedFree (data transfer rates apply)
High AvailabilityPer-AZ deployment requiredCross-AZ DNS resolution built-inRegional, fully managed
SecurityEgress filtering via SG/NACLPrivateLink, no internet exposureRoute table controlled, no internet
DNS IntegrationN/AOptional private hosted zoneAutomatic route table update

In production environments, I recommend Gateway Endpoints for S3/DynamoDB (they're free and reduce NAT costs significantly) and Interface Endpoints for services like Secrets Manager, ECR, and CloudWatch Logs. Reserve NAT Gateways strictly for legitimate external dependencies: package repositories, third-party APIs, or license servers. This approach typically reduces monthly networking spend by 30–40% for data-intensive workloads.

Egress Cost Optimization PathBefore: All Traffic via NATS3 + DynamoDB + APIs → NAT GW$$ High Data Processing FeesAfter: Optimized RoutingS3/DDB → GW Endpoint (Free)$ Only External APIs via NATOptimizeTypical Savings: 30–40% Monthly Networking CostGateway Endpoints eliminate NAT charges for AWS-native data transfers
Cost impact when setting up a VPC on AWS: replacing NAT Gateway traffic with VPC Endpoints for AWS services significantly reduces egress expenses.

How do you validate VPC connectivity and troubleshoot routing issues?

After setting up a VPC on AWS, validation prevents silent failures. Never assume connectivity works because configuration looks correct. Use VPC Reachability Analyzer to verify paths between ENIs before deploying applications. This tool evaluates route tables, security groups, NACLs, and gateway configurations to confirm whether traffic can actually flow.

Essential Validation Checklist

  • Route Table Association: Confirm each subnet is associated with the intended route table (not the main table).
  • NAT Gateway Health: Check CloudWatch metrics for packets dropped; unhealthy NAT GWs fail silently.
  • DNS Resolution: Test nslookup against VPC DNS (169.254.169.253) to verify private hosted zones.
  • Flow Logs: Enable VPC Flow Logs early; retroactive debugging without them is nearly impossible.

A frequent issue in Nepal-based deployments connecting to global AWS regions is MTU mismatch when traversing VPN or Direct Connect. Standard VPC MTU is 9001 bytes for intra-VPC traffic but drops to 1500 for internet-bound or peered traffic. If you experience intermittent connection failures or slow transfers, verify MTU settings on both ends and adjust TCP MSS accordingly.

Building Production-Ready AWS Networks

Setting up a VPC on AWS: Cloud Networking Fundamentals extends beyond initial provisioning. Sustainable cloud networking requires codified infrastructure, continuous validation, and cost-aware architecture decisions. Start with proper IP planning, enforce least-privilege security groups, optimize egress with VPC Endpoints, and validate every path before going live. These practices form the foundation for compliant, scalable systems that survive audits and traffic spikes alike.

If your team needs hands-on guidance designing or auditing AWS networking for production workloads, reach out to discuss your specific requirements. Whether you're preparing for SOC 2 certification, optimizing multi-region connectivity, or troubleshooting persistent networking issues, experienced architectural review prevents costly rework downstream.

Frequently Asked Questions

The smallest allowed IPv4 CIDR block is /28, providing 16 IP addresses. AWS reserves five addresses per subnet for internal networking services, leaving only eleven usable IPs for your resources in a /28 subnet.

Create at least two public and two private subnets across different Availability Zones for high availability. This ensures redundancy if one zone fails and allows proper load balancing for production workloads deployed within the VPC.

No, VPC creation itself is free. You pay only for provisioned resources like NAT Gateways, VPN connections, and data transfer. NAT Gateways typically incur hourly charges plus per-gigabyte processing fees depending on traffic volume.

Public subnets have a route to an Internet Gateway, allowing direct internet access. Private subnets lack this route and require a NAT Gateway or VPC endpoint for outbound connectivity while remaining inaccessible from the public internet.

Deploy a NAT Gateway in a public subnet and add a default route pointing to it in each private subnet's route table. This allows outbound internet traffic while keeping private instances shielded from inbound public connections.

You cannot modify the primary CIDR block after creation. However, you can associate secondary IPv4 or IPv6 CIDR blocks to expand address space without recreating the VPC or migrating existing resources and configurations.

AWS creates a default security group that allows all inbound traffic from members of the same group and permits all outbound traffic. Always restrict these rules before deploying production workloads to enforce least-privilege network access controls.

VPC endpoints provide private connectivity to AWS services like S3 and DynamoDB without traversing the internet or NAT Gateways. Interface endpoints use PrivateLink, while gateway endpoints for S3 and DynamoDB are free and eliminate NAT processing charges.

The default soft limit is five VPCs per region. You can request an increase through the Service Quotas console. Most organizations consolidate workloads using multiple subnets rather than separate VPCs to simplify management and peering complexity.

VPC peering connects exactly two VPCs with non-overlapping CIDRs in a full-mesh topology. Transit Gateway acts as a central hub connecting thousands of VPCs and on-premises networks, simplifying routing at scale beyond simple point-to-point connections.

Verify the subnet has an Internet Gateway route, the security group allows outbound traffic, and network ACLs permit ports 80 and 443. Missing any of these three components blocks egress even when a public IP is assigned.

Yes, enable IPv6 alongside IPv4 for future-proofing. AWS assigns a /56 prefix per VPC automatically. Many modern applications and compliance frameworks now expect dual-stack support, and IPv6 eliminates NAT costs for outbound traffic entirely.

Use VPC Flow Logs to inspect accepted and rejected traffic. Check route tables, security groups, and network ACLs systematically. The Reachability Analyzer tool validates path configuration and identifies specific misconfigurations blocking communication between source and destination resources.

Tag every VPC component with Environment, Team, Application, and CostCenter keys. Consistent tagging enables automated governance, accurate cost allocation, and simplified resource discovery across accounts when managing multiple VPCs in production environments.

Yes, use AWS Site-to-Site VPN for encrypted IPsec tunnels or Direct Connect for dedicated private connectivity. Both options extend your network into the VPC, enabling hybrid architectures with seamless routing between on-premises and cloud resources.