Skip to main content
FinOps

How to Auto-Shutdown Idle Azure VMs Without Breaking Work

A practical guide to shutting down idle Azure VMs: choose a schedule or idle rule, verify deallocation, plan startup, and calculate what you actually save.

8 min read
Microsoft Azure logo

A test VM gets used for a few hours on Friday. It keeps running all weekend because nobody remembers to turn it off. By Monday, you have paid for two days of compute that nobody needed.

Azure VM auto-shutdown can remove that waste. The important part is deciding when a machine is safe to stop, then making sure it is available when someone needs it again.

For predictable working hours, use a schedule. For irregular work, use an idle rule with checks for application activity. In both cases, verify that the VM reaches Stopped (deallocated). A guest operating system shutdown alone can leave compute charges running.

First, check what “stopped” means on your bill

Azure distinguishes between a VM that is stopped but still allocated to a host and one that has released its compute allocation. The first is still billed for compute. The second is deallocated and is not billed for VM instance usage. Disks and some networking resources can continue to cost money. Microsoft documents the billing states here.

That distinction changes how you automate shutdown. Running shutdown inside Linux or Windows is not enough to prove that you have stopped compute charges. Check the Azure power state after the operation.

Deallocation also needs a little preparation. Persistent managed disks remain, but temporary disk data can be lost. Do not keep anything you need only on a VM's temporary disk. See Microsoft's disk guidance.

Choose between a schedule and an idle rule

These solve different problems:

ApproachWhat triggers itWhere it fits
Scheduled shutdownA fixed timeDevelopment and test environments with agreed working hours
Idle-based shutdownLow activity over a defined periodIrregular test machines and other workloads that can stop between jobs
Scheduled start and stopSeparate start and stop schedulesEnvironments that must be ready before the team arrives

A schedule is like turning off the office lights at closing time. An idle rule tries to work out whether anyone is still working. The second needs more information.

A VM can have low CPU while it waits for a database, serves a small but important number of requests, or holds a remote desktop session. A disaster recovery server may be quiet by design. None of those facts gives you permission to stop it.

Ask the owner what the machine does, when it is needed, and what depends on it. If nobody knows, investigate before enabling shutdown.

Set up Azure's built-in auto-shutdown

For a single development VM, the built-in setting is a useful place to start:

  1. Open the VM in the Azure portal.
  2. Under Operations, select Auto-shutdown.
  3. Turn it on and choose the shutdown time.
  4. Check the time zone. Do not assume the displayed time is your local time.
  5. Add a notification email address or webhook if the team needs advance notice.
  6. Save, then check the VM's power state after the first scheduled shutdown.

The portal configuration guide covers those settings. This is a time-based shutdown; it does not inspect whether a build or test is still running. Arrange startup separately if the VM must come back on automatically.

For example, a team in Pune might agree to stop its test environment at 8 p.m. India time and have it ready by 9 a.m. the next working day. Record both times, including the time zone, rather than relying on whoever set up the schedule to remember them.

Automate startup as well as shutdown

If you need a VM each morning, a shutdown rule is only half the job.

Azure offers automation task templates for Start Virtual Machine, Power off Virtual Machine, and Deallocate Virtual Machine. For compute cost reduction, choose deallocation rather than power-off. These tasks run on Logic Apps; they are different from Azure Automation runbooks, and their executions can incur charges.

For broader scheduling, Start/Stop VMs v2 supports schedules, sequences, and CPU-based AutoStop across selected scopes. It uses Azure Functions and Logic Apps, with costs for the services it consumes.

Allow enough startup time for the application, not just the operating system. A database may need recovery time. A test environment may need caches to warm up. Check an application health endpoint before announcing that the environment is ready.

If several VMs form one application, write down the order. You might start the database before the application servers, then check readiness between stages. Reverse the order when shutting down if that is what the application requires.

How to auto-shutdown an Azure VM when it is idle

Start/Stop VMs v2 includes an AutoStop workflow based on CPU utilization. Microsoft's deployment guide exposes the threshold, evaluation window, frequency, and target scope.

To try it on a non-production VM:

  1. Deploy the solution into a dedicated resource group, following Microsoft's prerequisites.
  2. Open its ststv2_vms_AutoStop Logic App.
  3. Set the recurrence and restrict the request scope to the test VM you intend to manage.
  4. Choose the CPU threshold and time window for that workload.
  5. Test the action, check the run history, and confirm the final VM power state.

The built-in CPU rule does not know whether an application has pending work. If that matters, build a workflow that checks the application before deallocating the VM.

For example, you could start with this policy for an opt-in test environment:

  • CPU remains below 5% for 60 minutes.
  • Network and disk activity stay below limits agreed for that workload.
  • The job queue is empty and no build or test is running.
  • The owner has enabled shutdown for this VM, and no temporary exception is active.
  • Monitoring data is present and recent.

Those are example policy choices, not Azure defaults. A quiet database and a build worker will need different rules. If a required signal is missing, skip the shutdown and report why.

Run the policy in report-only mode first. Let it record “would stop” decisions without taking action, then have the owner review them. This often finds the overnight jobs that a CPU chart alone cannot explain.

Test deallocation and startup before enabling the rule

These Azure CLI commands let you test the basic operations on one approved VM. They do not implement idle detection or scheduling. Use an account with access to that VM, and replace the example values.

Shell
subscription_id="REPLACE_WITH_SUBSCRIPTION_ID"
resource_group="rg-dev"
vm_name="dev-vm-01"

az account set --subscription "$subscription_id"

az vm deallocate   --resource-group "$resource_group"   --name "$vm_name"

az vm get-instance-view   --resource-group "$resource_group"   --name "$vm_name"   --query "instanceView.statuses[?starts_with(code, 'PowerState/')].displayStatus"   --output tsv

Check that the result is VM deallocated before treating the test as successful. When you are ready to bring it back:

Shell
az vm start   --resource-group "$resource_group"   --name "$vm_name"

Then test the application and any scheduled jobs. The commands are documented in the Azure CLI VM reference. Check any dependencies on changing IP addresses before using the same process routinely.

Calculate savings from the hours you actually remove

Consider a VM that needs to run for 10 hours each weekday. Over four full weeks, that is 200 running hours instead of 672.

Using an illustrative compute rate of $0.20 an hour, with no reservation or savings plan:

Cost over 28 daysAlways runningWeekday schedule
Compute hours672200
Compute cost$134.40$40.00
Assumed unchanged disk cost$20.00$20.00
Total for these items$154.40$60.00

That removes $94.40 of compute cost: about 70% of compute, or 61% of the combined compute and disk cost shown here. It does not reduce every part of the VM's bill by 70%.

Use your actual rates and calendar, then subtract automation costs and account for startup time and exceptions.

Existing commitments need a separate check. Deallocating a VM does not cancel a reservation. The discount may move to another matching VM; otherwise, reserved hours can go unused. Microsoft's reservation billing guide explains this. Lower usage and a lower cash bill are not always the same thing.

Keep the rule useful after the first week

Give each shutdown policy an owner, a restart method, and a way to request a temporary exception. Make exceptions expire so one late-night test does not disable shutdown forever.

Record why the rule acted, whether deallocation succeeded, and whether startup restored the application. Review failures as well as the hours saved.

CloudYali's Cost Savings view helps teams track savings opportunities and their progress. Use that alongside resource inventory to keep the resource context visible when deciding what to change.

Start with one development environment whose owner can explain its working hours. Once shutdown, startup, and exceptions work reliably there, expand to the next environment.

Common questions

Does Azure VM auto-shutdown detect idle time?

The built-in Auto-shutdown setting follows a schedule. For CPU-based stopping, use a solution such as Start/Stop VMs v2. Add application checks if CPU alone cannot show whether work is still running.

Will my bill become zero after deallocation?

No. Persistent disks and other retained resources can still incur charges. Existing commitments also continue under their own terms.

Should I shut down a production VM with low CPU?

Only after the application owner confirms it can stop and you have checked dependencies, availability needs, and recovery. Low CPU is a reason to investigate, not an approval to shut down.

  • #Azure
  • #Virtual Machines
  • #Cost Optimization

Related reading

More on FinOps