Google Compute Engine Explained: What It Is and When to Use It

Google Compute Engine is GCP’s virtual machine service. You choose the CPU, memory, OS, and network settings; Google manages the physical hardware. It bills by the second and gives you complete OS-level control — making it the right tool when serverless platforms cannot meet your requirements.

Compute Engine in simple terms

Compute Engine lets you rent a server in Google’s data centre. You decide what kind of server (CPU count, memory size), what operating system runs on it, what disks are attached, and how it connects to the network. Google owns and maintains the physical machine. You own and manage everything that runs inside the VM.

When you create a VM, you get a private Linux or Windows server that you can connect to over SSH or RDP, install any software on, and configure however you need. It behaves exactly like a physical server — because from your perspective, it is one.

How Compute Engine works

Creating and running a VM follows a straightforward sequence:

  1. Choose a machine type — this sets the vCPU count and memory. See Machine Types Explained for guidance on picking the right size.
  2. Choose an OS image — Debian, Ubuntu, RHEL, Windows Server, or a custom image you have built. See VM Images for how images work.
  3. Choose a region and zone — the physical location where the VM runs. See Regions and Zones to understand the difference.
  4. Attach storage — a boot disk is required; additional data disks are optional. See Persistent Disks for disk types and sizing.
  5. Connect to a VPC and subnet — the VM joins your private network and gets an internal IP address. See VPC Networks Explained for networking basics.
  6. Assign a service account — the identity the VM uses to call GCP APIs. See Service Accounts for how to set one up with the right permissions.
  7. Start the VM and pay while it runs — billing is per second with a 1-minute minimum. Stopping the VM stops compute billing.

You can connect over SSH within 30 to 60 seconds of the VM booting. From that point it behaves like any Linux server: install packages, configure services, and manage files using standard tools.

When to use Compute Engine

Compute Engine is the right choice when you need OS-level control or when your workload genuinely does not fit a serverless model.

  • Lift-and-shift migrations — moving an existing on-premises workload to GCP without rewriting it. If it runs on a Linux or Windows server today, it runs on a Compute Engine VM.
  • Legacy applications — software that depends on specific OS versions, kernel modules, or system libraries that a container cannot satisfy.
  • Windows Server workloads — Windows-based apps, .NET Framework services, and anything that needs a full Windows environment with RDP access.
  • Self-managed databases — running Postgres, MySQL, MongoDB, or Redis directly on a VM when you need control over configuration, tuning, or storage layout that a managed database does not expose.
  • Long-running background services — daemons, queue workers, or batch jobs that run indefinitely and do not fit Cloud Run’s HTTP request model or Cloud Functions’ execution time limits.
  • Custom networking or low-level access — workloads that need to bind to specific ports, use non-HTTP protocols, or configure network interfaces in ways that serverless platforms do not support.
  • GPU workloads — machine learning training, video processing, and simulation jobs that need NVIDIA GPUs attached directly to the VM.
Quick rule of thumb

If someone handed you a server and said “install whatever you need,” your workload belongs on Compute Engine. If your app just needs to respond to HTTP requests, there is probably a simpler option.

When Compute Engine is not the best choice

Compute Engine requires you to manage the VM: OS updates, security patches, disk resizing, and monitoring. For many workloads, a managed service removes that overhead entirely.

  • Stateless HTTP services and APIs — if your app handles HTTP requests and holds no local state between requests, Cloud Run scales to zero, removes all VM management, and is almost always cheaper at variable traffic levels.
  • Event-driven functions — short tasks triggered by a Pub/Sub message, HTTP event, or Cloud Storage upload are a better fit for Cloud Functions.
  • Container orchestration at scale — if you need Kubernetes features like custom scheduling, stateful sets, or advanced networking across many containers, GKE provides a managed control plane without requiring you to manage individual VMs.
  • Managed databases — Cloud SQL, Cloud Spanner, and Firestore remove the operational burden of database administration. Only run a database on Compute Engine when a managed option genuinely cannot meet your requirements.
Worth checking first

Before spinning up a VM, ask: does this app handle HTTP requests and hold no local state? If yes, Cloud Run will be cheaper to run, require zero OS management, and scale automatically. Most new web services and APIs do not need a VM at all.

Compute Engine vs Cloud Run vs GKE

These three options cover most GCP compute workloads. Here is how they compare in plain terms:

Compute EngineCloud RunGKE
Control levelFull OS access, any softwareApp code only, no OS accessContainer and Kubernetes config
Operational overheadHigh — you manage OS, patches, scalingVery low — fully managedMedium — managed control plane; you manage node pools
Scaling modelManual or MIG-based autoscalingAutomatic, scales to zeroPod autoscaling within node pools
Best workload typeStateful apps, legacy software, databases, long-running servicesStateless HTTP services, APIs, short-lived jobsContainerised microservices, complex multi-service apps
Pricing patternPer second while running, even at idlePer request; free when idleNode VM costs plus cluster management fee

Quick guidance for beginners: start with Cloud Run for new web services and APIs. Use Compute Engine when the workload needs OS control, persistent local state, or cannot be containerised. See the full decision guide at Cloud Run vs Compute Engine or the three-way breakdown at Choosing Between Cloud Run, GKE, and Compute Engine.

What you choose when creating a VM

Every Compute Engine VM requires five core settings at creation time:

SettingWhat it controlsDeep dive
Machine typevCPU count and memory sizeMachine Types Explained
Boot disk / OS imageThe operating system and base configurationVM Images
ZonePhysical location; affects latency and availabilityRegions and Zones
Network and subnetPrivate IP range, firewall rules, internet accessVPC Networks Explained
Service accountThe GCP identity the VM uses to call APIsService Accounts

Firewall rules are defined at the VPC level and control which ports are reachable on the VM’s IP. By default, inbound traffic is blocked unless you explicitly open a port. For most beginner setups, you open port 22 for SSH and the port your application listens on.

Compute Engine pricing and billing basics

Pay as you go

The default pricing model. You are billed per second with a 1-minute minimum per VM start. No commitment is required. Use this for short-lived experiments, development VMs, and workloads where runtime is unpredictable.

Sustained use discounts

Applied automatically with no action required. If a VM runs for more than 25% of a calendar month, GCP applies incremental discounts to the hours beyond that threshold. A VM running continuously for a full month saves roughly 30% compared to the base hourly rate. No sign-up or configuration is needed — it happens automatically.

Committed use discounts

You commit to a specific vCPU and memory allocation for 1 or 3 years in exchange for a significant discount — up to 57% for general-purpose machine types. Commitments apply to resource capacity across matching VMs in a region, not to specific VM instances. Best for stable production workloads with predictable resource needs.

For additional savings on fault-tolerant batch workloads, see Preemptible and Spot VMs, which offer up to 91% off the on-demand price in exchange for the VM being reclaimed by GCP with 30 seconds notice.

Stopped VM costs

Easy to miss

Stopping a VM halts compute billing but does not stop storage billing. Persistent disks attached to a stopped VM continue to incur charges. Reserved static IP addresses also bill when not attached to a running VM. To eliminate storage costs, delete the disk or take a snapshot first and then delete it.

Pricing modelBest forTradeoff
Pay-as-you-goShort-lived or experimental workloadsHighest per-hour price
Sustained useLong-running steady-state VMsDiscount grows automatically with runtime
Committed usePredictable production baselineCapacity commitment for 1 or 3 years
Spot / PreemptibleFault-tolerant batch jobsVM can be reclaimed by GCP with 30 seconds notice

For a deeper look at reducing costs, see Compute Engine Cost Optimisation.

What a typical beginner workflow looks like

Most beginners follow the same sequence when using Compute Engine for the first time:

  1. Create a VM — pick a small machine type like e2-micro or e2-small, choose Debian or Ubuntu, and leave other settings at defaults to start.
  2. Connect over SSH — run gcloud compute ssh or use the SSH button in the Cloud Console. No key management is needed if OS Login is enabled.
  3. Install software — run apt install, configure your application, or set up a web server. The VM behaves exactly like a normal Linux server.
  4. Test the application — open the relevant port in firewall rules and access the app via the VM’s external IP address.
  5. Stop the VM when finished — compute billing stops immediately. The disk and its data remain.
  6. Snapshot or delete when no longer needed — take a snapshot to preserve the disk state cheaply before deleting, or delete the VM and disk entirely if you are done.

For a step-by-step walkthrough of this entire flow, see Creating Your First VM.

Creating and managing VMs with gcloud

The following commands cover the full lifecycle of a basic VM. Each flag is written explicitly so you can see exactly what is being configured.

# Create a basic VM
gcloud compute instances create my-first-vm \
  --zone=europe-west2-a \
  --machine-type=e2-medium \
  --image-family=debian-12 \
  --image-project=debian-cloud \
  --boot-disk-size=20GB

# List running VMs
gcloud compute instances list

# SSH into the VM
gcloud compute ssh my-first-vm --zone=europe-west2-a

# Stop the VM (compute billing stops; disk billing continues)
gcloud compute instances stop my-first-vm --zone=europe-west2-a

# Delete the VM and its boot disk
gcloud compute instances delete my-first-vm --zone=europe-west2-a

The —image-family flag selects the latest image from that family automatically. Using a family name rather than a specific image version means you always get the most recently patched OS build without having to track individual image names.

Lifecycle taskCommandReference page
Create VMgcloud compute instances createCreating Your First VM
Access VMgcloud compute sshSSH Access in Compute Engine
Snapshot diskgcloud compute disks snapshotSnapshots Explained
Scale with groupsgcloud compute instance-groups managed createManaged Instance Groups

Cutting dev VM costs with instance schedules

A development VM that runs around the clock costs roughly three times more than one that runs only during business hours. Instance schedules start and stop VMs automatically on a cron-based pattern — no manual action required.

# Create a schedule: start at 08:00, stop at 19:00, Monday to Friday
gcloud compute resource-policies create instance-schedule dev-hours \
  --region=europe-west2 \
  --vm-start-schedule="0 8 * * 1-5" \
  --vm-stop-schedule="0 19 * * 1-5" \
  --timezone="Europe/London"

# Attach the schedule to a VM
gcloud compute instances add-resource-policies my-dev-vm \
  --zone=europe-west2-a \
  --resource-policies=dev-hours
Analogy

Instance schedules work like a smart thermostat timer. You set the hours you want heat, it handles the rest — no one has to remember to turn it off every night. The building still exists while the heat is off; it just costs less to maintain.

An 11-hour weekday window runs approximately 220 hours per month versus 720 hours for a VM running 24/7 — roughly a 70% reduction in compute cost. Disk storage continues to bill during off-hours, but disk costs are a small fraction of compute costs for most VM sizes.

The instance metadata server

Every Compute Engine VM has access to a built-in metadata server at http://metadata.google.internal. This endpoint exposes configuration about the VM itself: its project ID, zone, service account credentials, and any custom key-value pairs you attached at creation time. Applications query this endpoint instead of hardcoding environment-specific values into config files.

This is how your application knows which project it is running in, how it gets a short-lived access token to call GCP APIs without storing a key file, and how startup scripts can read custom variables you passed in at launch time.

# Get the project ID from inside the VM
curl -s -H "Metadata-Flavor: Google" \
  "http://metadata.google.internal/computeMetadata/v1/project/project-id"

# Get the current zone
curl -s -H "Metadata-Flavor: Google" \
  "http://metadata.google.internal/computeMetadata/v1/instance/zone"

# Get a short-lived access token for the attached service account
curl -s -H "Metadata-Flavor: Google" \
  "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token"
Always include the header

The Metadata-Flavor: Google header is required on every request. Without it, the server returns a 403 error. This header exists to prevent server-side request forgery (SSRF) attacks, where a malicious page tricks a browser or server into fetching VM credentials on its behalf. Never skip it, even in scripts where it feels like extra noise.

Compute Engine best practices for beginners

Start here

For your first VM: use e2-micro, pick Debian, create a dedicated service account, enable OS Login, and set a budget alert. Those five steps cover most beginner mistakes before they happen.

  1. Start with the smallest viable machine type. Use e2-micro or e2-small for learning and testing. Resize later based on actual usage. Oversized VMs waste money every hour they run. See Machine Types Explained for guidance on right-sizing.

  2. Use a dedicated service account with least-privilege roles. The default Compute Engine service account has the Editor role on the whole project — far more permission than any application needs. Create a dedicated account with only the roles your workload actually requires. See Service Accounts.

  3. Use OS Login for SSH access. OS Login ties SSH access to IAM instead of requiring you to manage SSH key files manually. It is simpler, more auditable, and easier to revoke when team members leave. See OS Login Explained.

  4. Schedule snapshots for stateful disks. Persistent disks are durable but they are not a backup. A snapshot policy automatically captures disk state on a schedule so you can recover from data corruption or accidental deletion. See Persistent Disks.

  5. Avoid single-VM production designs. A single VM is a single point of failure. For production workloads, use a Managed Instance Group across multiple zones so that a zone outage is handled automatically without manual intervention.

  6. Monitor idle instances and set budget alerts. VMs that are running but not handling load still bill at full rate. Set up a budget alert and use the recommendations in the cost optimisation guide to identify and clean up idle resources.

Common beginner mistakes with Compute Engine

  1. Leaving VMs running when not needed. Compute Engine bills for uptime whether or not the VM is doing anything. A development VM left running overnight or over weekends accumulates costs quickly. Use instance schedules or stop VMs manually when they are not in use.

  2. Assuming stopped means free. Stopping halts compute billing, but persistent disks and reserved static IPs continue to bill. If you are done with a VM, decide whether to delete the disk or snapshot it first.

  3. Using the default Compute Engine service account. The default service account has the Editor role on the project, which grants far more access than any application should have. Create a dedicated service account with only the roles your workload needs.

  4. Running production on a single VM. Hardware failures, zone outages, and OS-level issues can take a single VM offline with no automatic recovery. Use a Managed Instance Group with at least two zones for any workload that needs to stay up.

  5. Picking oversized machine types. Provisioning a large VM to avoid future performance problems wastes money every hour the VM runs. Start small and resize based on actual utilisation metrics from Cloud Monitoring.

  6. Exposing services publicly without understanding firewall rules. Opening all ports (0–65535) to 0.0.0.0/0 to fix a connectivity problem exposes the entire VM to the internet. Open only the specific ports your service needs and restrict source IP ranges where possible.

Frequently asked questions

What is Google Compute Engine?

Google Compute Engine is GCP's virtual machine service. You rent a server in Google's data centre, choose the CPU, memory, disk, OS, and network settings, and Google manages the physical hardware. Billing is per second with a 1-minute minimum. It is the right choice when you need full OS-level control over your environment.

Is Compute Engine the same as a virtual machine?

Compute Engine is the GCP service that provides virtual machines. A virtual machine (VM) is the individual instance you create inside Compute Engine. Think of Compute Engine as the product and the VM as the thing you actually run. Each VM gets its own OS, disk, IP address, and network interface, even though it shares physical hardware with other GCP customers.

Does stopping a VM stop all charges?

No. Stopping a VM halts compute billing, but persistent disks attached to the VM continue to incur storage charges. Reserved static IP addresses also continue to bill. To stop paying for storage, delete the disk or take a snapshot first and then delete it. Use instance schedules to automatically stop development VMs overnight rather than deleting and recreating them.

When should I use Compute Engine instead of Cloud Run?

Use Compute Engine when you need full OS control, must run software with specific kernel requirements, or have workloads that cannot be containerised. Also choose it for self-managed databases, stateful services, Windows Server applications, and lift-and-shift migrations from on-premises. For stateless HTTP workloads and APIs with variable traffic, Cloud Run is simpler to operate and cheaper at low to medium volumes.

Is Compute Engine good for beginners?

Yes — for learning cloud fundamentals it is an excellent starting point. Creating a VM, connecting over SSH, installing software, and stopping the VM when finished covers the core cloud concepts that carry over to every other GCP service. Start with an e2-micro instance, which is inexpensive and eligible for the GCP free tier. Just remember to stop or delete the VM when you are done experimenting.

Last verified: 22 March 2026 Cloud services change frequently. Verify details against official documentation before making infrastructure decisions.