What Happens When an EC2 Instance is Stopped and Started Again?

EC2 Instance is Stopped
EC2 Instance is Stopped

When an Amazon EC2 instance is stopped and started again, multiple things happen at the compute level, storage level, networking level, and billing level. Let’s explore each aspect in detail.


1️⃣ Compute Level: Instance is Terminated from the Physical Server

When You Stop an EC2 Instance:

πŸ”Ή The instance is shut down gracefully (like shutting down a computer).
πŸ”Ή The compute resources (CPU, memory, physical host) assigned to the instance are released.
πŸ”Ή The instance no longer runs on the previous physical machine in AWS data centers.
πŸ”Ή The instance remains in the β€œStopped” state in the AWS Management Console.

βœ… What Persists?

  • The instance ID remains the same.
  • The EBS volume (Elastic Block Store) attached as root storage remains intact.
  • All data stored in the EBS volume is preserved.

❌ What Changes?

  • If the instance has a public IP assigned dynamically, AWS releases it, and a new IP is assigned when restarted (unless you use an Elastic IP).

When You Start the EC2 Instance Again:

πŸ”Ή AWS allocates new compute resources to the instance.
πŸ”Ή The instance boots up from the same EBS volume (i.e., all your files, configurations, and applications remain intact).
πŸ”Ή If the instance was previously using a dynamic public IP, it will get a new public IP.

βœ… What Stays the Same?

  • Instance ID remains unchanged.
  • EBS volume and data remain intact.
  • Private IP remains the same.
  • IAM roles, Security Groups, and Key Pair remain attached.

❌ What Changes?

  • Public IP (if not using an Elastic IP) will change.
  • The instance may be assigned to a new physical machine in AWS infrastructure.

2️⃣ Storage Level: EBS Volume Persists, Instance Store Data is Lost

EBS-backed Instances (Default for Most EC2 Instances)

βœ”οΈ Root volume (EBS) persists even after stopping and restarting the instance.
βœ”οΈ Additional EBS volumes (if attached) remain intact.
βœ”οΈ Data stored on EBS volumes is safe unless manually deleted.

Instance Store-backed Instances (Ephemeral Storage)

❌ Data is lost when the instance is stopped.
❌ These instances do not use EBS storage and rely on temporary storage directly attached to the host.
❌ AWS releases the attached ephemeral storage when the instance stops.

πŸ‘‰ Solution: Always use EBS-backed instances for workloads that require persistent storage (e.g., WordPress, databases).


3️⃣ Networking Level: Public IP Change & Private IP Persistence

Public IP Address Behavior

πŸ”Έ If the instance had a dynamically assigned public IP, AWS releases it when the instance stops.
πŸ”Έ When the instance starts again, AWS assigns a new public IP.

βœ… How to Keep the Same Public IP?

  • Allocate an Elastic IP and associate it with your instance.
  • Elastic IP remains unchanged even if the instance is stopped and restarted.

Private IP Address Behavior

βœ”οΈ Private IP remains the same even after the instance restarts.
βœ”οΈ Private IP is used for communication within the VPC (Virtual Private Cloud).
βœ”οΈ Since it doesn’t change, internal services can still communicate without any issues.

πŸ‘‰ Example:

  • Suppose your EC2 instance has Public IP: 34.201.120.55 and Private IP: 10.0.1.5.
  • After stopping the instance:
    • The public IP is released.
    • The private IP remains the same.
  • When restarted:
    • A new public IP (e.g., 52.24.75.10) is assigned.
    • The private IP (10.0.1.5) remains unchanged.

4️⃣ Billing Level: No Compute Costs While Stopped

When an EC2 Instance is Stopped:

βœ… AWS stops charging for compute resources (CPU, RAM).
βœ… AWS still charges for EBS storage attached to the instance.
βœ… If using an Elastic IP that is unassociated, AWS charges for it.

When an EC2 Instance is Started Again:

βœ… AWS starts billing for compute resources again.
βœ… AWS continues billing for EBS storage and any attached resources.

πŸ‘‰ Example Cost Breakdown:

StateCompute ChargesEBS Storage ChargesElastic IP Charges
Runningβœ… Chargedβœ… Chargedβœ… Free if associated
Stopped❌ Not chargedβœ… Chargedβœ… Charged if unused

Example Scenario: Hosting a WordPress Blog on AWS EC2

Case 1: Without Elastic IP

πŸ”Ή You launch an EC2 instance for your WordPress blog.
πŸ”Ή AWS assigns a dynamic public IP (e.g., 54.220.50.100).
πŸ”Ή You map your domain (yourblog.com) to this IP.
πŸ”Ή Later, you stop the instance and restart it.
πŸ”Ή AWS assigns a new public IP (e.g., 34.201.75.200).
πŸ”Ή Now, your website is inaccessible until you update the DNS settings.

Case 2: With Elastic IP

βœ… You allocate an Elastic IP (e.g., 18.220.50.80) and associate it with your EC2 instance.
βœ… Your domain (yourblog.com) always points to the same IP.
βœ… Even if you stop and restart the instance, the Elastic IP remains unchanged.
βœ… Your WordPress blog stays accessible without any DNS updates.


Final Thoughts: What You Need to Remember?

βœ… Stopping an EC2 instance releases compute resources but retains storage (EBS).
βœ… Private IP remains the same, but public IP changes unless you use an Elastic IP.
βœ… You are NOT billed for compute power while stopped, but EBS storage continues to be charged.
βœ… Use Elastic IP if you need a persistent public IP for a web application.
βœ… Always ensure that critical data is stored on EBS-backed instances for persistence.

Would you like help setting up an Elastic IP or automating instance restarts? πŸš€

About Anant 401 Articles
Senior technical writer