A Compute Engine VM is defined by its machine type: vCPUs and memory, from a machine family that targets a kind of workload.
flowchart LR W["Your workload"] --> GP["General purpose<br/>E2, N2, N4, C4A"] W --> CO["Compute optimized<br/>C3, C4, H3"] W --> MO["Memory optimized<br/>M3, X4"] W --> AO["Accelerator optimized<br/>A3, G2 with GPUs"] GP --> P["Pricing: on-demand, Spot, CUD"] %% step W: Start from the workload: web, batch, database, ML training or inference. %% step GP: General purpose covers most web and app servers; E2 is the cheapest, N-series and C4A balance price and speed. %% step CO: Compute optimized gives the highest per-core performance for CPU-bound jobs. %% step MO: Memory optimized offers terabytes of RAM for SAP HANA and in-memory databases. %% step AO: Accelerator optimized families attach NVIDIA GPUs for ML and graphics. %% step P: Then choose how to pay: on-demand, Spot or a commitment.
Machine type names
e2-standard-4 = family E2, shape standard (4 GB RAM per vCPU), 4 vCPUs. Other shapes: highcpu (1 GB/vCPU), highmem (8 GB/vCPU). Shared-core types (e2-micro, e2-small, e2-medium) share a physical core and suit tiny workloads. Custom machine types let you pick exact vCPU and memory on families such as E2 and N2. Arm-based families (C4A on Google Axion, T2A) cost less per vCPU if your software runs on Arm.
Pricing models
| Model | Discount | Notes |
|---|---|---|
| On-demand | – | Per-second billing after the first minute |
| Sustained use discounts | Automatic, up to ~20–30% | For some families (N1, N2, N2D, C2…) that run a large part of the month; not E2 |
| Committed use discounts | Up to ~55% (more for memory-optimized) | 1 or 3 years; resource-based (vCPU/RAM in a region) or flexible spend-based |
| Spot VMs | 60–91% | Google can stop them at any time with ~30 seconds notice; no SLA |
Spot VMs fit batch jobs, CI runners, rendering and stateless workers that can retry. Set what happens on preemption: STOP or DELETE.
Right-sizing
- Start small and watch CPU and memory in Cloud Monitoring (memory needs the Ops Agent).
- Follow machine type recommendations from the Recommender: it suggests smaller types for idle VMs.
- Stopped VMs do not pay for vCPU and memory, but still pay for disks and reserved static IPs.
gcloud compute machine-types list --zones=asia-southeast1-a --filter="name~^e2-standard"
gcloud compute instances create batch-1 --zone=asia-southeast1-a --machine-type=e2-standard-4 --provisioning-model=SPOT --instance-termination-action=DELETE
| Command | Meaning |
|---|---|
gcloud compute machine-types describe e2-standard-4 --zone=… |
vCPUs, memory, limits |
gcloud compute instances set-machine-type web-1 --machine-type=e2-standard-2 --zone=… |
Resize a stopped VM |
gcloud compute commitments list |
Your commitments |
Traps: you must stop a VM to change its machine type; a 3-year commitment is paid even if you stop using it; Spot VMs do not suit a single production database.