keepcalculator

06 Numbers and Powers

AWS EC2 Explained: What It Is, How It Works, Costs

Card No. 06·53623 · Updated · Standard formula, shown below

AWS EC2 (Elastic Compute Cloud) is a web service that provides resizable virtual servers, called instances, in the cloud. You rent these instances by the second, choosing the operating system, CPU, memory, storage, and network capacity you need, and you pay only for what you use. This article explains how EC2 instances work, how to choose one, and what they actually cost.

What Is EC2?

EC2 is part of Amazon Web Services, launched in 2006. It lets you launch virtual machines (VMs) on AWS’s physical hardware without buying or maintaining servers yourself. Each VM runs on a host server managed by AWS, but you control the guest operating system, software, and security settings. The name “Elastic” refers to the ability to scale your capacity up or down quickly—launching more instances when demand rises and terminating them when it falls.

EC2 is one of the most widely used cloud computing services because it offers flexibility: you can run a small web server, a large database, or a GPU-powered machine learning training job, all with the same API. You interact with EC2 through the AWS Management Console, the AWS CLI, or SDKs.

How EC2 Instances Work

An instance is a virtual server with a defined amount of vCPUs, memory, storage, and network bandwidth. When you launch an instance, you choose an Amazon Machine Image (AMI)—a template that includes the operating system, application server, and applications. AWS provides many AMIs, including Amazon Linux, Ubuntu, Windows Server, and Red Hat Enterprise Linux.

Each instance runs on a physical host managed by AWS. The hypervisor (a type of virtualization software) allocates resources to your instance. You connect to it via SSH (for Linux) or Remote Desktop (for Windows) using a key pair you create. You can stop, start, reboot, and terminate instances at any time. When you stop an instance, it retains its EBS (Elastic Block Store) volumes but loses any data stored on instance store (ephemeral storage). When you terminate, all associated resources are released.

Instances also have a security group—a virtual firewall that controls inbound and outbound traffic. You define rules for allowed ports, IP addresses, and protocols. By default, all inbound traffic is blocked unless you explicitly allow it.

Instance Types and Families

AWS categorizes instances into families based on their workload. Each family has multiple sizes (e.g., t3.micro, t3.small, t3.large). The first letter(s) indicate the family, and the number indicates the generation and size. Common families include:

  • General purpose (t3, m5) – Balanced CPU, memory, and network. Good for web servers, small databases, and development environments.
  • Compute optimized (c5, c6g) – High CPU performance for batch processing, scientific modeling, and gaming servers.
  • Memory optimized (r5, x1) – High memory-to-CPU ratio for in-memory databases, caching, and real-time big data analytics.
  • Storage optimized (i3, h1) – High, sequential read/write access to large datasets on local storage. Good for data warehousing and log processing.
  • Accelerated computing (p3, g4) – Include GPUs or FPGAs for machine learning, graphics rendering, and video encoding.

Within each family, sizes range from nano (1 vCPU, 0.5 GiB RAM) to 24xlarge (96 vCPUs, 192 GiB RAM). Choosing the right size depends on your workload’s requirements.

How to Choose an EC2 Instance

Selecting an instance type involves balancing cost and performance. Start with a general-purpose instance for typical applications, then use monitoring tools (like CloudWatch) to see CPU, memory, and network utilization. If your CPU is consistently high, consider a compute-optimized type; if memory is the bottleneck, switch to memory-optimized.

Also consider the purchase model:

  • On-Demand – Pay per second with no commitment. Best for short, unpredictable workloads.
  • Reserved Instances – Commit to 1 or 3 years for a significant discount (up to 72%) compared to On-Demand. Best for steady-state workloads.
  • Savings Plans – Similar to Reserved but more flexible; you commit to a dollar amount per hour for 1 or 3 years.
  • Spot Instances – Bid on unused EC2 capacity at up to 90% discount. Instances can be terminated by AWS with a 2-minute warning if capacity is needed elsewhere. Best for fault-tolerant, flexible workloads like batch jobs.
  • Dedicated Hosts – Physical servers dedicated to you, for compliance or licensing needs. Most expensive.

What Does EC2 Cost?

EC2 pricing is complex because it depends on instance type, region, operating system, and purchase model. On-Demand prices for a t3.micro (2 vCPU, 1 GiB RAM) in the US East (N. Virginia) region are around $0.0104 per hour (Linux) and $0.0168 per hour (Windows). That works out to roughly $7.50 per month for Linux. Larger instances cost more: a m5.large (2 vCPU, 8 GiB RAM) costs about $0.096 per hour, or $70 per month on-demand.

However, you also pay for other resources:

  • EBS volumes – Storage attached to your instance. Costs range from $0.08/GB-month for standard SSD (gp2) to $0.125/GB-month for provisioned IOPS (io1).
  • Data transfer – Outbound data transfer is charged per GB (first 100 GB free, then about $0.09/GB). Inbound is free.
  • Elastic IP addresses – Free while attached to a running instance, but you pay $0.005/hour if unused.
  • Snapshots – Backups of EBS volumes, charged per GB-month.

Reserved Instances can cut costs dramatically. For example, a 3-year all-upfront Reserved t3.micro might cost around $150 total, versus over $270 for On-Demand over the same period. Spot prices fluctuate; a t3.micro spot instance can be as low as $0.003 per hour.

Common Problems and Misconceptions

“My instance is slow” – Often due to insufficient instance size or burstable CPU credits. T-series instances (like t3.micro) have a baseline CPU performance and accumulate credits when idle. When credits run out, performance drops. Switching to a non-burstable type (like m5) or a larger size can help.

“I got a huge bill” – Usually from leaving instances running or forgetting to delete EBS volumes after terminating an instance. Always check the AWS Cost Explorer and set billing alerts.

“I can’t connect to my instance” – Check your security group rules (allow SSH on port 22 from your IP), your key pair permissions (must be chmod 400), and that the instance is running.

Misconception: “EC2 is the same as a physical server” – It’s not. The underlying hardware is shared (unless you use Dedicated Hosts), and performance can vary. Also, you don’t have access to the hypervisor.

Alternatives to EC2

EC2 is not the only compute option on AWS. For containerized applications, Amazon ECS and EKS (Kubernetes) are often easier to manage. For serverless applications, AWS Lambda lets you run code without provisioning servers—you pay only per request and compute time. For a fully managed environment, AWS Elastic Beanstalk automatically handles deployment and scaling. Outside AWS, competitors like Google Compute Engine and Azure Virtual Machines offer similar services.

Frequently Asked Questions

How much does EC2 cost per month?

It depends entirely on the instance type, region, and purchase model. A t3.micro running 24/7 on-demand costs about $7.50/month. A larger instance like m5.large costs around $70/month. Add EBS storage and data transfer, and the cost increases.

What is the difference between stopping and terminating an instance?

Stopping an instance shuts it down but keeps the EBS volumes and instance ID, so you can start it again later. You still pay for EBS storage while stopped. Terminating permanently deletes the instance and its associated EBS volumes (unless you’ve enabled termination protection).

Can I change the instance type after launching?

Yes, for most instances. You can stop the instance, change its type, and start it again. The new type must be compatible with the instance’s configuration (e.g., same virtualization type). This process is called resizing.

What is a key pair and why do I need it?

A key pair consists of a public key (stored by AWS) and a private key (you keep). When you launch an instance, you specify a key pair, and the public key is injected into the instance. You use the private key to SSH into the instance. Without it, you cannot access your instance (unless you use Systems Manager Session Manager).

Are EC2 instances secure?

Security is a shared responsibility. AWS secures the physical infrastructure, but you must configure security groups, manage OS patches, and protect your key pairs. Using IAM roles instead of access keys for applications running on EC2 is a recommended practice.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →