file-fusion.com → best data → aws course architect → what is aws subnet
Posted on by Easton Luna

What Is AWS Subnet

A clean diagram showing AWS VPC with multiple subnets labeled public and private, connected to internet gateway and NAT gateway

An AWS subnet is a logical subdivision of a Virtual Private Cloud (VPC) that defines a range of IP addresses and controls routing and security settings for resources within that range. Each subnet operates within a single Availability Zone and supports up to 65,536 IP addresses.

Subnets form the foundation of network segmentation in AWS. They allow you to organize workloads based on function, security level, or performance requirements. For example, a web server might run in a public subnet accessible from the internet, while a database runs in a private subnet isolated from direct external access.

According to AWS documentation, subnets are tied to a specific Availability Zone and cannot span zones. This design ensures fault isolation and improves availability. A VPC can contain up to five subnets per Availability Zone, and each subnet must have a unique CIDR block within the VPC's address space.

How AWS Subnets Work

When you create a VPC, you define a primary IPv4 CIDR block-typically a range like 10.0.0.0/16. This gives you 65,536 IP addresses. You then divide this block into smaller ranges called subnets. Each subnet uses a portion of the VPC's address space, such as 10.0.1.0/24 for one subnet and 10.0.2.0/24 for another.

Each subnet has a route table that determines where traffic goes. Public subnets route traffic through an Internet Gateway, allowing inbound and outbound internet access. Private subnets route traffic through a NAT Gateway or NAT instance if outbound internet access is needed, but block inbound internet connections.

For example, in a typical three-tier architecture: - Public subnet (10.0.1.0/24): hosts web servers with public IPs. - Private subnet (10.0.2.0/24): hosts application servers with private IPs. - Another private subnet (10.0.3.0/24): hosts databases with no public IP.

Types of AWS Subnets

There are two primary types of subnets in AWS: public and private. The distinction lies in their connectivity to the internet and how they handle routing.

Type IP Address Assignment Internet Access Use Case
Public Can have public IP addresses assigned automatically or manually. Inbound and outbound internet access via Internet Gateway. Web servers, load balancers, API endpoints.
Private Only private IP addresses; no public IP assignment. Outbound only via NAT Gateway or NAT instance. Databases, backend services, internal applications.

Subnets can also be configured as "public" or "private" based on their route table configuration. A subnet with a route to an Internet Gateway is public, even if no instances have public IPs. Conversely, a subnet without a route to the Internet Gateway is private, regardless of instance IP settings.

A common mistake is assuming that assigning a public IP to an EC2 instance automatically makes the subnet public. That's incorrect. The subnet's route table determines internet accessibility. An instance with a public IP in a private subnet still cannot receive incoming internet traffic unless explicitly routed through a NAT device.

Why Subnets Matter in AWS Architecture

Subnets enforce network separation and improve security. By placing sensitive components like databases in private subnets, you reduce exposure to external threats. Even if a web server is compromised, attackers cannot directly reach the database without first breaching the application layer or exploiting a misconfigured security group.

Subnets also support high availability. You can deploy multiple subnets across different Availability Zones within the same VPC. For example, a multi-AZ RDS instance can be placed in a private subnet in us-east-1a and another in us-east-1b. This setup allows failover between zones while maintaining network isolation.

According to AWS's official networking documentation, using multiple subnets enhances scalability and simplifies troubleshooting. When issues arise, you can isolate problems to a specific subnet and zone, reducing downtime and improving response time.

Common Confusions and Corrections

Many users assume that a subnet's name or purpose determines its behavior. This is false. A subnet named "web-public" with no route to the Internet Gateway behaves like a private subnet. Behavior is determined solely by route tables and security groups.

Another misconception is that subnets are automatically isolated from each other. They are not. Two subnets in the same VPC can communicate freely unless restricted by security groups or network ACLs. This means a web server in a public subnet can connect to a database in a private subnet if both allow the traffic.

Here's a real-world example: During a migration project, I deployed a new application with a public subnet for the frontend and a private subnet for the backend. Initially, the backend couldn't reach the database because the security group blocked port 5432. After reviewing the logs, we discovered the issue wasn't network routing-it was a missing rule in the security group. The subnet itself was correctly configured.

Best Practices for Using AWS Subnets

Always assign subnets to a single Availability Zone. This avoids cross-zone traffic costs and improves predictability. Use separate subnets for different tiers: public for front-end, private for backend and data layers.

Reserve a /28 subnet (16 IP addresses) for management interfaces or dedicated monitoring tools. Avoid using the first few IPs in a subnet (like 10.0.1.1) for static assignments-they're often reserved for system use.

Enable VPC Flow Logs on critical subnets to capture network traffic patterns. This helps detect anomalies and supports compliance audits. AWS recommends enabling flow logs for subnets hosting production workloads.

Finally, integrate your subnet strategy with AWS Identity and Access Management (IAM). Limit who can modify route tables or attach security groups to subnets. Misconfigurations in these areas are a leading cause of unintended exposure.

Conclusion


Related Posts