Skip to main content
This guide demonstrates how to create subnets inside a VPC, how those subnets determine an EC2 instance’s Availability Zone (AZ) and private IPv4 address, and how to clean up demo resources when finished.

Overview

  • A VPC defines the overall IP address space for your network in AWS.
  • Subnets carve out CIDR blocks inside that VPC and are tied to specific Availability Zones.
  • When you launch an EC2 instance into a subnet, the instance receives a private IP from the subnet’s CIDR and is placed in that subnet’s AZ.
For more background, see the AWS VPC documentation: https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html

Step 1 — Create the VPC

In the VPC console choose Create VPC (VPC only). For this demo use:
  • Name: Demo VPC
  • IPv4 CIDR block: 10.0.0.0/16
  • (Optional) Amazon-provided IPv6 CIDR block
Create the VPC so you have a parent CIDR to place subnets into.

Step 2 — Create subnets in the VPC

Go to Subnets → Create subnet. Select the Demo VPC, provide a name (e.g., Subnet 1) and pick an Availability Zone. In the N. Virginia region you may see AZ identifiers such as us-east-1a, us-east-1d, etc. If you choose “No preference,” AWS will assign an AZ for you. Important constraints:
  • A subnet’s CIDR must be a block contained within the parent VPC CIDR. For example, 192.168.1.0/24 is invalid in a 10.0.0.0/16 VPC. A valid example is 10.0.1.0/24.
  • Optionally assign an IPv6 CIDR when creating the subnet if your VPC has an IPv6 pool.
A subnet’s IPv4 CIDR must be a block within the parent VPC’s CIDR range. Always plan your VPC and subnet ranges to avoid overlaps.
For this demo create two subnets: Create Subnet 1 with CIDR 10.0.1.0/24 in us-east-1d, then create Subnet 2 with CIDR 10.0.5.0/24 in us-east-1a. You can filter the Subnets list by VPC to show only subnets that belong to Demo VPC.
A screenshot of the AWS VPC Management Console on the Subnets page showing two available subnets (IPv4 CIDRs 10.0.5.0/24 and 10.0.1.0/24) with details and available IPv4 addresses. The left sidebar shows VPC navigation items and a green banner at the top confirms a subnet was successfully created.

Step 3 — Launch an EC2 instance into a subnet

When you launch an EC2 instance, selecting a subnet determines:
  • The Availability Zone the instance will be placed in.
  • The private IP address range from which the instance’s private IPv4 will be allocated.
Example steps:
  1. Go to EC2 → Launch Instance.
  2. Choose an AMI and instance type (e.g., Amazon Linux 2023, t2.micro).
  3. Select or create a key pair.
  4. Under Networking, select Demo VPC and pick the subnet (for example, choose Subnet 2 to place the instance in us-east-1a).
  5. Configure public IP assignment and other options as needed, then click Launch.
Note: whether an instance receives a public IPv4 address depends on the subnet’s auto-assign public IP setting or subsequent assignment via an Elastic IP.
A screenshot of the AWS EC2 "Launch an instance" console showing VPC/subnet and security group configuration on the left and a Summary panel on the right listing the AMI (Amazon Linux 2023), instance type (t2.micro) and a "Launch instance" button. The page also shows inbound SSH rule details and free tier information.
After the instance launches (even while booting), the console will show the private IP assigned from the subnet’s CIDR. In this demo the instance received 10.0.5.113, which is inside 10.0.5.0/24 (Subnet 2) and the instance is placed in us-east-1a.
Screenshot of the AWS EC2 Management Console showing a single t2.micro instance named "instance1" (i-0c683936f4bf18119) in a Running state. The details pane shows its private IP 10.0.5.113 and instance summary.

Cleanup — terminate instances and delete the VPC

When finished with the demo, terminate the instance and then delete the VPC. Deleting a VPC removes its subnets and other dependent resources automatically, but only if there are no remaining dependent resources attached.
You must terminate or detach any dependent resources (instances, ENIs, NAT gateways, etc.) before deleting a VPC. The console will block deletion until those resources are removed.
To delete the VPC:
  1. Confirm all instances, network interfaces, NAT gateways, and other resources are terminated or detached from the VPC.
  2. In the VPC console, select the VPC → Actions → Delete VPC.
  3. The console will display resources that will be removed and request confirmation. Type delete to confirm before the VPC is deleted.
A screenshot of the AWS VPC Management Console showing a "Delete VPC" confirmation dialog for a VPC named "demovpc," listing associated resources (subnets and a security group) that will also be deleted. The dialog includes a text field where you must type "delete" to confirm.

Summary

  • Plan your VPC CIDR and subnet CIDRs to avoid overlap.
  • Each subnet is tied to a single Availability Zone; launching into that subnet places the instance in the corresponding AZ.
  • The instance’s private IPv4 is allocated from the subnet’s CIDR block.
  • Always clean up dependent resources before deleting a VPC.

Watch Video