Start and Stop Azure Virtual Machines
Learn how to start, stop, and deallocate Azure virtual machines to manage costs and resources effectively.
On this page
Why Start and Stop VMs?
Managing the lifecycle of your Azure virtual machines is crucial for cost optimization and efficient resource utilization. Starting and stopping VMs allows you to:
- Save costs: You are only billed for compute resources when your VM is running. Storage costs apply even when the VM is stopped. Deallocating a VM stops billing for compute.
- Perform maintenance: Stop VMs to apply updates, perform hardware maintenance, or migrate data.
- Scale on demand: Start or stop VMs as your application's workload demands.
Methods to Start and Stop VMs
Azure provides several methods to manage the power state of your virtual machines:
Azure portal
The Azure portal offers a user-friendly graphical interface for managing your VMs.
- Navigate to the Virtual machines service in the Azure portal.
- Select the virtual machine you want to manage.
- On the virtual machine's overview page, you will see Start, Stop, and Restart buttons at the top of the blade.
- Click Stop to shut down the VM and deallocate its compute resources.
- Click Start to provision and boot the VM.
Azure CLI
Use the Azure Command-Line Interface (CLI) for scriptable and automated VM management.
# Log in to your Azure account
az login
# Set your subscription context (if you have multiple)
az account set --subscription ""
# Start a virtual machine
az vm start --resource-group "" --name ""
# Stop (deallocate) a virtual machine
az vm deallocate --resource-group "" --name ""
# Restart a virtual machine
az vm restart --resource-group "" --name ""
Azure PowerShell
Leverage Azure PowerShell for powerful command-line management and automation.
# Connect to your Azure account
Connect-AzAccount
# Set your subscription context (if you have multiple)
Set-AzContext -SubscriptionId ""
# Get the VM object
$vm = Get-AzVM -ResourceGroupName "" -Name ""
# Start the virtual machine
Start-AzVM -ResourceGroupName $vm.ResourceGroupName -Name $vm.Name
# Stop (deallocate) the virtual machine
Stop-AzVM -ResourceGroupName $vm.ResourceGroupName -Name $vm.Name -Force
# Restart the virtual machine
Restart-AzVM -ResourceGroupName $vm.ResourceGroupName -Name $vm.Name
REST API
For advanced automation scenarios, you can use the Azure REST API.
To start a VM, send a POST request to the start operation:
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/start?api-version=2020-06-01
Authorization: Bearer
Content-Type: application/json
To stop (deallocate) a VM, send a POST request to the deallocate operation:
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/deallocate?api-version=2020-06-01
Authorization: Bearer
Content-Type: application/json
Managing Costs
Important: Stopping a virtual machine without deallocating it (often referred to as a "soft stop") keeps the underlying compute resources reserved and incurs costs. To stop incurring compute charges, you must deallocate the VM.
Azure's Automanage service or custom automation scripts can be configured to automatically start and stop VMs on a schedule, helping to reduce costs for non-production environments or during off-peak hours.
Important Considerations
- Data Disks: Data disks attached to a VM are not affected when the VM is stopped or deallocated. They remain available and incur storage costs.
- Public IP Addresses: When a VM is deallocated, its public IP address is released and may change upon restart unless it's a static IP address.
- Resource Groups: VMs are typically managed within resource groups. Ensure you know the resource group name when using CLI or PowerShell.
- VM State: Understand the difference between "Stopped" (deallocated) and "Stopped (deallocated)". The latter is the state where compute charges cease.
- Network Configuration: Ensure your network security groups and firewalls allow access if you need to connect to the VM immediately after starting it.