Virtual Machine Cost Optimisation in Azure

Virtual Machines are the largest single cost driver in most Azure environments. Optimising VM costs is therefore the highest-leverage place to start. This page covers every available technique — from simple scheduling to multi-layer discount stacking — with real pricing numbers.

Understanding VM Cost Components

Azure VM costs have several components, each with its own optimisation levers:

  • Compute: the vCPU and RAM reservation. This is the dominant cost and the target for RI, Spot, and right-sizing.
  • OS licence: Windows Server adds a licence charge on top of compute. Linux VMs have no licence charge.
  • Managed disks: OS and data disks charge per GB per month. Disks continue to charge when VMs are deallocated.
  • Public IP addresses: static IPs cost approximately $0.005/hour (~$3.65/month) per address.
  • Bandwidth: outbound data transfer to the internet costs $0.087/GB for the first 10 TB/month.

Example: full cost breakdown of a Standard_D4s_v5 (Windows, East US, PAYG)

Cost ComponentRateMonthly (730 hrs)Optimisation Lever
Compute (D4s_v5 Windows)$0.384/hr$280.32RI, Spot, right-size, schedule
Windows licence portion~$0.192/hr~$140.16Azure Hybrid Benefit
OS disk (128 GB Premium SSD)$19.71/month$19.71Downgrade to Standard SSD
Data disk (512 GB Premium SSD)$70.40/month$70.40Downgrade tier or right-size
Static public IP$0.005/hr$3.65Use dynamic IP or remove
Total (PAYG)~$374/month

Layer 1: Reserved Instances

For any VM that runs predictably more than 8 hours per day, a Reserved Instance is the most straightforward and impactful optimisation. Purchasing a 1-year or 3-year reservation reduces the compute portion of the bill by 39–61%.

The Windows D4s_v5 example above has a compute charge of $280.32/month on PAYG. A 1-year RI reduces this to approximately $170/month. A 3-year RI reduces it to approximately $110/month.

# View RI recommendations in Azure Advisor
az advisor recommendation list \
  --category Cost \
  --query "[?contains(shortDescription.solution, 'Reserved')].{Title:shortDescription.solution, Savings:extendedProperties.savingsAmount, Resource:resourceMetadata.resourceId}" \
  --output table

# List existing reservations in your subscription
az reservations reservation list \
  --reservations-order-id $(az reservations reservation-order list --query "[0].name" -o tsv) \
  --query "[].{Name:displayName, SKU:sku.name, Scope:properties.appliedScopeType, Expires:properties.expiryDate}" \
  --output table

Layer 2: Azure Hybrid Benefit

If your organisation has Windows Server licences with Software Assurance, Azure Hybrid Benefit eliminates the Windows licensing portion of the VM cost. For the D4s_v5 example, this saves approximately $140/month on the licence portion alone.

# Enable Azure Hybrid Benefit on an existing VM
az vm update \
  --resource-group my-rg \
  --name my-vm \
  --license-type Windows_Server

# Enable on all Windows VMs in a resource group
az vm list \
  --resource-group my-rg \
  --query "[?storageProfile.osDisk.osType=='Windows'].name" \
  --output tsv | xargs -I {} az vm update \
    --resource-group my-rg \
    --name {} \
    --license-type Windows_Server

Combining RI + Hybrid Benefit

A Windows D4s_v5 on PAYG without Hybrid Benefit: ~$280/month compute. With a 3-year RI: ~$170/month. Adding Hybrid Benefit removes the licence charge entirely, reducing the compute+licence total from $280 to approximately $110–120/month. Combined saving: ~57% from PAYG with both layers applied.

Tip

Azure Hybrid Benefit also applies to SQL Server licences on Azure SQL Managed Instance and SQL Database. If you have SQL Server Enterprise licences with SA, the savings on a Business Critical tier database can exceed $2,000/month.

Layer 3: Spot VMs for Fault-Tolerant Workloads

Spot VMs offer the deepest discounts — 60–90% off PAYG — in exchange for the possibility of eviction with 30 seconds notice. They are appropriate for:

  • Batch processing and data transformation jobs
  • CI/CD pipeline agents and build servers
  • Machine learning training workloads
  • Development and test environments with auto-save behaviour
  • Stateless web application backends with multiple instances
# Create a Spot VM
az vm create \
  --resource-group my-rg \
  --name spot-batch-worker \
  --image UbuntuLTS \
  --size Standard_D4s_v5 \
  --priority Spot \
  --eviction-policy Deallocate \
  --max-price 0.05 \
  --admin-username azureuser \
  --generate-ssh-keys

# The --max-price flag sets the maximum you will pay per hour.
# Set it to -1 to pay up to the PAYG price (never evict for price reasons,
# only for capacity reasons). Setting a specific max price provides
# price stability but increases eviction risk if Spot prices rise.

Layer 4: Scheduling and Auto-Shutdown

Development, test, and staging VMs rarely need to run 24/7. A VM that runs 10 hours/day on weekdays uses 217 hours/month instead of 730 — a 70% reduction in compute charges with zero architectural changes.

Auto-shutdown via portal

Each VM in the Azure portal has an Auto-shutdown option in its left menu. You can set a daily shutdown time and timezone. The VM deallocates at that time, stopping compute billing.

Scheduled start and stop with Azure Automation

# Create an Automation Account
az automation account create \
  --resource-group cost-management-rg \
  --automation-account-name vm-scheduler \
  --location eastus \
  --sku Basic

# Tag VMs with their schedule
az tag update \
  --resource-id "/subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Compute/virtualMachines/dev-vm-01" \
  --operation Merge \
  --tags auto-shutdown="19:00" auto-start="08:00" schedule-timezone="UTC"

# The Automation runbook queries VMs by tag and starts/stops accordingly
# Typical saving: a D4s_v5 running 10hrs/day weekdays vs 24/7:
# PAYG: 217 hrs * $0.192 = $42/month vs 730 hrs * $0.192 = $140/month
# Saving: ~$98/month per VM, just from scheduling

Layer 5: Right-Sizing

Oversized VMs are extremely common. Teams often provision a D8s_v5 (8 vCPUs, 32 GiB) because it seems comfortably large, when a D4s_v5 (4 vCPUs, 16 GiB) would handle the actual workload with headroom to spare. Halving the VM size roughly halves the compute cost.

# Check average CPU for all VMs over the last 30 days
az monitor metrics list \
  --resource "/subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Compute/virtualMachines/{vm-name}" \
  --metric "Percentage CPU" \
  --aggregation Average \
  --start-time $(date -d '30 days ago' -u +%Y-%m-%dT%H:%M:%SZ) \
  --end-time $(date -u +%Y-%m-%dT%H:%M:%SZ) \
  --interval P1D \
  --query "value[0].timeseries[0].data[].average" \
  --output tsv

# A consistent average CPU below 15% is a strong signal for downsizing.
# Below 5% suggests the VM may not be needed at all.

See the dedicated Rightsizing Virtual Machines page for a full methodology.

Disk Tier Optimisation

Managed disks contribute a significant portion of VM costs, especially when provisioned as Premium SSD by default. For disks that do not require low latency (backups, archives, log volumes), switching tiers can reduce disk costs by 40–75%:

  • Premium SSD: ~$0.135/GB/month (e.g., 512 GB = $70/month)
  • Standard SSD: ~$0.08/GB/month (e.g., 512 GB = $41/month)
  • Standard HDD: ~$0.04/GB/month (e.g., 512 GB = $20/month)
# Change an existing disk tier (disk must be detached or VM deallocated)
az disk update \
  --resource-group my-rg \
  --name my-data-disk \
  --sku Standard_LRS

# Check all Premium disks in a resource group
az disk list \
  --resource-group my-rg \
  --query "[?sku.name=='Premium_LRS'].{Name:name, SizeGB:diskSizeGb, MonthlyCost:diskSizeGb}" \
  --output table

Common Mistakes

  1. Buying Reserved Instances for VMs that will be right-sized or replaced. Purchase RIs only after you have confirmed the VM size is correct. An RI purchased for a D8s_v5 that you later downsize to a D4s_v5 will not apply automatically (though it can be exchanged).
  2. Using auto-shutdown without auto-start. VMs that shut down automatically but require manual start create friction and are often simply left running to avoid the hassle. Pair auto-shutdown with a scheduled start.
  3. Forgetting disk costs when VMs are deallocated. Managed disks and static IPs continue billing when a VM is deallocated. If a VM is decommissioned but not deleted, its disks silently accumulate charges.
  4. Optimising PAYG VMs that should be terminated. Not every VM deserves optimisation. Some belong to abandoned projects. Before investing in RI purchases or right-sizing analysis, confirm the VM is genuinely needed.

Frequently asked questions

What is the single biggest saving I can make on Azure VMs?

For predictable workloads running more than 8 hours per day, purchasing a 3-year Reserved Instance is typically the largest single saving — up to 61% compared to pay-as-you-go. For Windows VMs with existing licences, combining Azure Hybrid Benefit with an RI can save 70–75%.

Can I use Reserved Instances with auto-scaling VM Scale Sets?

Yes. Reserved Instance discounts apply automatically to any VM matching the committed size and region, including Scale Set instances. During scale-out events, instances beyond the RI quantity are billed at PAYG rates (or covered by Savings Plans).

How do I automatically shut down development VMs at night?

Use the Auto-shutdown feature in each VM's settings (available directly in the VM blade in the portal), or use Azure DevTest Labs policies for bulk management. You can also use Azure Automation schedules or Azure Monitor action rules to trigger deallocations.

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