SkillSprout
Chapter 4 · Lesson 2
Intermediate
8 min read

Subnets

Overview

A subnet is a slice of your VPC's IP address range that lives inside one Availability Zone. Every resource that has a network interface — an EC2 instance, an RDS database, a load balancer node, a Lambda function attached to your VPC — is placed in a subnet and receives a private IP address from that subnet's range.

Subnets are how you organise and secure a VPC. You typically create groups of subnets by tier (web, application, data) and by Availability Zone, then control what each group can reach using route tables, security groups and network ACLs. A subnet is called public if its route table sends internet-bound traffic to an Internet Gateway and private if it does not.

On the exam, subnet questions are really about three things: sizing the CIDR correctly (remember the 5 reserved IPs), spreading subnets across AZs for high availability, and choosing public vs. private placement for each component.

Key Concepts

  • A subnet is bound to exactly one AZ and can never span AZs; a VPC spans all AZs of the Region.
  • A subnet CIDR must be a subset of the VPC CIDR, with a prefix between /16 and /28, and subnets in a VPC cannot overlap.
  • AWS reserves the first four and last one IP address in every subnet — usable IPs = 2^(32-prefix) - 5.
  • Public vs. private is decided by the route table (route to an IGW), not by a subnet setting.
  • Auto-assign public IPv4 is a per-subnet attribute; it only matters when the subnet is public.
  • A subnet's CIDR cannot be changed after creation — resize by creating a new subnet and migrating.
  • Each subnet is associated with one route table and one NACL at a time (both default to the VPC's main/default ones).
  • Subnet sharing with AWS RAM lets multiple accounts in an Organization deploy into subnets owned by one VPC owner account.
  • Some services consume many IPs: Lambda in a VPC, EKS pods, and large ALBs use ENIs from your subnets, so leave headroom.

Detailed Notes

Subnet sizing maths

A subnet's size comes from its prefix length. Total addresses = 2^(32 - prefix). AWS then removes five addresses, so usable = total - 5.

PrefixTotal IPsUsableTypical use
/281611Smallest allowed; tiny management subnets
/266459Small utility tiers
/24256251Standard web/app/data subnet
/221,0241,019Container or Lambda-heavy workloads
/204,0964,091Large EKS node/pod subnets
/1665,53665,531Largest subnet (equals a /16 VPC)

The five reserved addresses (example 10.0.1.0/24)

  • 10.0.1.0 – network address
  • 10.0.1.1 – VPC router
  • 10.0.1.2 – Amazon-provided DNS (VPC base + 2)
  • 10.0.1.3 – reserved for future use
  • 10.0.1.255 – broadcast (not supported, but still reserved)

Worked planning example

You need 3 tiers across 3 AZs in a 10.0.0.0/16 VPC. Using /24 subnets gives 9 subnets that consume only 9 of the 256 possible /24 blocks, leaving ample room to grow. A common scheme keeps the third octet meaningful:

text
10.0.0.0/24   public  AZ-a      10.0.10.0/24  app  AZ-a      10.0.20.0/24  data AZ-a
10.0.1.0/24   public  AZ-b      10.0.11.0/24  app  AZ-b      10.0.21.0/24  data AZ-b
10.0.2.0/24   public  AZ-c      10.0.12.0/24  app  AZ-c      10.0.22.0/24  data AZ-c

Subnet types

TypeRoute to IGWRoute to NATTypical residents
PublicYes (0.0.0.0/0)n/aALB, NAT Gateway, bastion
Private (with egress)NoYesApp servers needing patches/APIs
IsolatedNoNoDatabases, regulated workloads
VPN-onlyNo (route to VGW)NoHybrid-only resources

Availability Zone planning

  • Create at least two subnets per tier in different AZs; three is common for quorum-based systems.
  • AZ names (us-east-1a) are mapped differently per account. Use the AZ ID (use1-az1) when you must align AZs across accounts, for example with RAM-shared subnets or a shared service.
  • Local Zones, Wavelength Zones and Outposts extend a VPC with subnets in those locations; they are also per-location subnets.

Subnet attributes

  • Auto-assign public IPv4 address – new ENIs get a public IP (taken from AWS's pool, not an Elastic IP). The default VPC's subnets enable it; custom subnets do not.
  • Auto-assign IPv6 – assign a /128 from the subnet's /64 IPv6 block.
  • Resource-based name (RBN) DNS hostname options and IPv6-only subnets are available for newer designs.
  • Instances launched with an explicit network interface can override the subnet defaults.

Adding and changing CIDR ranges

You can associate secondary CIDR blocks with a VPC (up to 5 IPv4 by default, adjustable) and then create subnets from them. You can never change or delete the primary VPC CIDR, and you cannot resize an existing subnet. Plan for growth early or be ready to build a replacement subnet.

Subnet sharing (AWS RAM)

A central networking account owns the VPC and subnets, then shares subnets with member accounts in the Organization. Participants can create resources in the subnet but cannot modify the subnet, route table or NACL, and security groups remain owned by each account. This avoids a "VPC per account" sprawl and the need for peering.

CLI example

bash
# Create a subnet in a specific AZ and enable public IP assignment
aws ec2 create-subnet --vpc-id vpc-0abc123 --cidr-block 10.0.0.0/24 \
  --availability-zone us-east-1a \
  --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=public-a}]'

aws ec2 modify-subnet-attribute --subnet-id subnet-0abc123 --map-public-ip-on-launch

Troubleshooting checklist

  • Launch fails with InsufficientFreeAddressesInSubnet -> subnet is exhausted; add a larger subnet or reduce ENI usage.
  • Instance has a public IP but is unreachable -> check the route table has an IGW route and the security group/NACL allow the traffic.
  • Cross-AZ traffic between subnets is charged per GB; keep chatty tiers in the same AZ where practical.

Real World Example

Scenario — a media company runs EKS for video transcoding.

The first release used /24 subnets for the EKS worker nodes. Because the VPC CNI assigns a VPC IP address to every pod, the three /24 subnets (251 usable IPs each) were exhausted when the cluster scaled to a few hundred pods, and new pods stayed in Pending.

The network team added a secondary CIDR (100.64.0.0/16) to the VPC and created three /19 subnets (8,187 usable IPs each), one per AZ, dedicated to pods. Nodes stayed in the original /24 subnets. Load balancers and NAT Gateways remained in small public /24 subnets.

They also moved the shared-services VPC into a central networking account and used AWS RAM subnet sharing so five product accounts could deploy into approved subnets without peering connections. The result was a cluster with room for tens of thousands of pods, simpler network governance, and no IP conflicts with the on-premises ranges routed over Direct Connect.

Architecture Diagram

Subnet layout across two Availability Zones
Architecture
VPC 10.0.0.0/16
Internet Gateway
AZ us-east-1a
Public 10.0.0.0/24
ALB node251 usable IPs
App 10.0.10.0/24
EC2 App
Data 10.0.20.0/24
RDS
AZ us-east-1b
Public 10.0.1.0/24
ALB node251 usable IPs
App 10.0.11.0/24
EC2 App
Data 10.0.21.0/24
RDS standby

One public, one app and one data subnet per AZ; each subnet is bound to a single AZ.

  1. 1The VPC CIDR 10.0.0.0/16 is divided into non-overlapping subnet CIDRs.
  2. 2Each subnet is created in exactly one AZ; the same tier is repeated in a second AZ for resilience.
  3. 3Public subnets route 0.0.0.0/0 to the Internet Gateway; app and data subnets have no direct internet route.
  4. 4Traffic between tiers stays on the implicit local route within the VPC CIDR.

Best Practices

  • ✓Use one subnet per tier per AZ and at least two AZs for every production workload.
  • ✓Size generously: /24 is a sensible default; use /22 or larger for container, Lambda or large Auto Scaling tiers.
  • ✓Keep IP ranges contiguous and documented (or managed with VPC IPAM) so you can summarise routes for VPN and Direct Connect.
  • ✓Put only internet-facing components (ALB, NAT Gateway) in public subnets; keep application and database tiers private.
  • ✓Use secondary CIDR blocks to extend the VPC rather than recreating it when you run out of addresses.
  • ✓Use AZ IDs, not AZ names, when coordinating placement across accounts.
  • ✓Share subnets with AWS RAM in multi-account landing zones instead of creating many small VPCs and peering them.
  • ✓Tag subnets with tier and environment and enable VPC Flow Logs at subnet level for visibility.

Common Interview Questions

Exam Tips

SAA-C03 focus

  • Usable IPs = 2^(32-prefix) - 5. A /28 gives 11, a /24 gives 251. Memorise this.
  • One subnet = one AZ. If a question says "highly available", the answer includes subnets in multiple AZs.
  • Public/private is defined by the route table (IGW route), not by naming or a checkbox.
  • Subnet CIDRs cannot overlap and cannot be modified; extend with a secondary VPC CIDR.
  • Subnet limit: 200 subnets per VPC by default (adjustable).
  • To put databases where nothing can reach the internet, use private subnets with no NAT route (isolated).
  • Multi-account sharing of the same network -> AWS RAM subnet sharing, not peering.
  • Placing ENIs for Lambda in a VPC requires subnets in multiple AZs and enough free IPs.

Finished this lesson?

0 of 64 lessons done · 0% of the course