Properly Shutdown Azure VM To Save Money | Build5Nines (2024)

Properly Shutdown Azure VM To Save Money | Build5Nines (1)

By Chris Pietschmann | March 27, 2020 - 11:00 AM EDT (16:00 UTC)
Category:

Properly Shutdown Azure VM To Save Money | Build5Nines (2)

There are 2 options to “shutdown” a Virtual Machine (VM) running in Microsoft Azure. Each of the two methods have different affects on the cost of your Azure subscription. One way you will still get charged for the compute resources, and the other will free you from paying for the compute resources and help you reduce your overall cost. This article takes a look at these, and explains the difference between them.

Table of Contents

How Azure VM Billing Works

When Microsoft Azure Virtual Machines (VMs) are running they are billed on a “per hour” basis. You will only pay for the number of hours your VM is running after you create it. If you leave the VM running all month long, this means you pay for the entire month. But, if you stop and deallocate the VM, then you will only be billed for the time the VM is actually running.

The reason you are only billed for the time when the VM is running, and not when it’s deallocated, is because when it’s running is the only time actual compute hardware in the datacenter is dedicated to your VM. When the VM is deallocated, then Microsoft Azure releases the hardware reservation for your VM so it can be used by some other Azure resource that needs it.

Beware that when you “Stop” the VM by shutting down the Operating System, then the VM is still running in Microsoft Azure. In order to stop billing for the VM, you need to stop the VM to put it into a “deallocated” state. When the VM is in the “Stopped (deallocated)” state, that’s when billing will be paused. The “Stopped (deallocated)” state is discussed further down below.

Keep in mind that when the VM is deallocated you are still paying for the storage used to store the VMs operating system disk and any other data disks attached to the VM. Storage still takes up resources in the Azure datacenter so you will still be billed for those. Although storage is relatively inexpensive, so leaving a VM in your Azure Subscription that is not running and deallocated wont really cost very much.

Stopped vs Stopped (Deallocated)

The first method to shutdown an Azure VM, that sounds logical in the context of connecting with Remote Desktop, is to Shutdown the Operating System. In this scenario you would be connected with Remote Desktop, and when done with your work you go to the Power options within the Windows operating system and then select the Shutdown option. This will essentially “turn off” or power down the Virtual Machine (VM), and stop it from running. However, with this method, even though the VM is not running you will still be paying for the Azure VM compute resources (aka hardware allocation) in the datacenter. This will cause the Azure Portal to report the status of the VM as “Stopped”.

The second method, and the important one to remember, is to go into the Azure Portal (or use the Azure CLI or Azure PowerShell) and use Azure to Stop the VM. Instead of just shutting down the Operating System, Azure will also deallocate the compute resources allocated for the VM. This releases the compute resources to be used for another customer within Microsoft Azure. This will cause Azure to no longer charge you for the compute resources, and Azure will report the status of the VM as being in a “Stopped (Deallocated)” state.

Properly Shutdown Azure VM To Save Money | Build5Nines (3)

While an Azure VM is in the “Stopped (Deallocated)” state, you will not be chargedfor the VM compute resources. However, you will still need to pay for any OS and data storage disks attached to the VM.

It’s a good idea that when ever you don’t actually need the VM to be running that you Stop it using Azure so that the resources are released.While in the “Stopped (Deallocated” status, you will not bepayingfor the VM resources. This will really help you save money!

Use Azure CLI to Stop (Deallocate) Azure VM

You can also use the Azure CLI, or even PowerShell cmdlets to stop and deallocate Azure Virtual machines (VMs). Using the Azure Portal is convenient, but there are times when automation is a better solution.

Stopping and Deallocating an Azure VM using the Azure CLI can be done with the following commands:

# Stop Azure VMaz vm stop --name {vm name} --g {resource group name}# Deallocate Azure VMaz vm deallocate --name {vm name} -g {resource group name}

I encourage you to check out the Quickly Start / Stop ALL VMs article I’ve previously written, as it includes more description and additional script samples for stopping Azure VMs.

Manually Shutdown VM within Azure Portal

To“properly” Stop a VM in the Azure Portal to release the resources and save money, you can follow these steps:

  1. Within the Azure Portal, navigate to theVirtual Machineblade for the desired VM.
  2. On theOverviewpane, click theStopbutton.
Properly Shutdown Azure VM To Save Money | Build5Nines (4)

There is one caveat to be aware of when shutting down an Azure VM so it gets placed into the Stopped (Deallocated) status. Since this causes Azure to release the server resources associated with the Virtual Machine, it not only releases the CPU and Memory resources but also the Dynamic IP Address allocation. Due to this, when you Start the VM back up again, the IP Address will likely change. If you require the IP Address to never change for your VM, then you’ll need to configure a Static IP Address for the VM.

To start up a Stopped VM, you can follow these steps:

  1. Within the Azure Portal, navigate to theVirtual Machineblade for the desired VM.
  2. On theOverviewpane, click theStartbutton.
Properly Shutdown Azure VM To Save Money | Build5Nines (5)

Another point that’s important to remember when stopping Azure VM’s and placing them into the “Stopped (Deallocated)” state is that you do still pay for the Azure Storage account usage. Remember, the Storage account is where the VM’s .vhd disk image file is stored. Stopping the VM retains all the VM’s settings / configurations, as well as the .vhd image stored in Azure Storage. As a result, you will still incur some cost for the storage, but at least you will save on the VM resources. After all, the Storage will only cost a small amount of money compared to the much higher cost of the Virtual Machine resource allocation if it were left running constantly.

Schedule VM Auto Shutdown

Manually shutting down a VM to put it in theStopped (Deallocated)status is a great way to save cost on Azure VM’s. Although, you do need to remember to Stop the VM. This introduces a certain level of human error in the process of saving you hosting costs on your Azure VMs. As a result, Microsoft has added a scheduled auto-shutdown feature into the platform to assist you in this effort.

With theAuto-shutdownfeature, you are able to configure a specificTime (with Time Zone) when Azure is to automatically shutdown the VM.When configured,the VM will automatically be stopped if it is still running at that time of day.

To configure Auto-shutdown of an Azure VM, you can follow these steps:

  1. Within the Azure Portal, navigate to theVirtual Machineblade for the desired Virtual Machine.
  2. In the list of links on the Virtual Machine blade, click onAuto-shutdown.
  3. On theAuto-shutdownpane, configure the specificTime,Time Zone, and desired notificationWebhook URLsettings, then clickSave.
Properly Shutdown Azure VM To Save Money | Build5Nines (6)

If you forget to Stop your VM at the end of the day, or whenever the Auto-shutdown time is configured it will get Shutdown automatically. When using a Visual Studio development VM, this can become a good thing on Friday afternoons (or any other day when you might be in a hurry) when you’re most likely to forget to shutdown the VM.

About the Author

Properly Shutdown Azure VM To Save Money | Build5Nines (7)Properly Shutdown Azure VM To Save Money | Build5Nines (8)

Chris Pietschmann is a Microsoft MVP, HashiCorp Ambassador, and Microsoft Certified Trainer (MCT) with 20+ years of experience designing and building Cloud & Enterprise systems. He has worked with companies of all sizes from startups to large enterprises. He has a passion for technology and sharing what he learns with others to help enable them to learn faster and be more productive.
Properly Shutdown Azure VM To Save Money | Build5Nines (9)Properly Shutdown Azure VM To Save Money | Build5Nines (10)Properly Shutdown Azure VM To Save Money | Build5Nines (11)

Related

  1. Properly Shutdown Azure VM To Save Money | Build5Nines (12)

    Sunilon June 16, 2017 at 7:58 am

    is this option available for azure gov? we are using the arm portal and don’t see the “scheduling” menu or the “auto-shutdown” option.

    • Properly Shutdown Azure VM To Save Money | Build5Nines (13)

      Chris Pietschmannon June 18, 2017 at 10:58 pm

      If it’s not there then you probably can’t do it. Azure Gov Cloud is always a bit behind the Public Cloud on features, unfortunately.

  2. Properly Shutdown Azure VM To Save Money | Build5Nines (14)

    tonyon June 27, 2017 at 1:10 pm

    Can’t find it in the Azure MSDN Subscription Holders as well. I wonder if there’s a powershell command for this?

  3. Properly Shutdown Azure VM To Save Money | Build5Nines (15)

    Brianon July 6, 2017 at 7:08 am

    Hi Chris, is there a powershell command to create the schedule? I’d like to include it on my powershell script that provisions my test servers.

    Thanks, Brian

  4. Properly Shutdown Azure VM To Save Money | Build5Nines (16)

    gjohnson71on July 13, 2017 at 5:04 pm

    Does the autoshutdown act like someone pulling the plug on a physical server? I have an Azure VM with SQL Server installed and I don’t want any data to get corrupted.

  5. Properly Shutdown Azure VM To Save Money | Build5Nines (18)

    Chestere baringon August 7, 2017 at 4:51 am

    Hello chris, thank you for sharing this. I would also like to ask, if vm is stopped(deallocated), what we are paying will be the storage, like SSD? Or the whole related storage? Thank you

    • Properly Shutdown Azure VM To Save Money | Build5Nines (19)

      Chris Pietschmannon September 20, 2017 at 8:30 am

      When a VM is Stopped and Deallocated then all you are paying for is the Storage. If a VM is just Stopped, then you are still paying for the VM allocation and Storage.

  6. Properly Shutdown Azure VM To Save Money | Build5Nines (20)

    Abhishek Kulkarnion August 8, 2017 at 12:07 am

    Hi,

    I am facing the error, “Couldn’t configure the Auto-shutdown feature. Close the virtual machine blade and try again. Error: [object Object]” while I’m using the Auto-Shutdown. How do I solve it? Do I need to have some specific role for my subscription?

    Thank you,
    Abhishek

  7. Properly Shutdown Azure VM To Save Money | Build5Nines (22)

    Stefanon August 8, 2017 at 8:05 am

    Until MS might find it necessary to allow Auto-Dealloc of a stopped VM, it is possible to use Azure Automation for this. To deallocate a stopped VM, create a powershell runbook that issues a Stop-AzureRmVM when a VM in stopped-state is detected.

    The script looks essentially like this (add login and subscription selection, then run it via an hourly schedule):

    $powerstateMask = ‘PowerState/*’
    $powerstateStopped = ‘PowerState/stopped’
    $powerstateDealloc = ‘PowerState/deallocated’

    $VM = (Get-AzureRmVM -Name $vmName -ResourceGroupName $resourceGroupName -Status)

    if(!$VM) { Write-Error “VM ‘$resourceGroupName’ does not exist.” }
    else
    {
    $vmState = ($VM.Statuses | Where Code -Like $powerstateMask)[0]
    Write-Output (“Current PowerState of VM is ‘{0}'” -f $vmState.DisplayStatus)
    if($vmState.Code -eq $powerstateStopped)
    {
    # Note: Deallocation via Stop-AzureRmVM is blocking (might take 1-2 minutes)
    Write-Verbose “Going to deallocate the VM (this might take a minute)…”
    Stop-AzureRmVM -Name $vmName -ResourceGroupName $resourceGroupName -Force
    Write-Verbose “Done!”
    }
    else { Write-Verbose “All is fine!” }
    }

  8. Properly Shutdown Azure VM To Save Money | Build5Nines (23)

    Simon Weaveron March 19, 2018 at 8:24 pm

    Is there such a thing as ‘hibernate’ or ‘sleep’? So applications will still be open but the hardware will be deallocated? I’m setting up an ’emergency’ dev machine and I’d like to leave things open.

    • Properly Shutdown Azure VM To Save Money | Build5Nines (24)

      Chris Pietschmannon March 19, 2018 at 9:01 pm

      Nothing supported in Azure did directly. You may be able to do it; I have not tried to hibernate an Azure VM before reallocating…

  9. Properly Shutdown Azure VM To Save Money | Build5Nines (25)

    Phanindra Pokalaon March 23, 2018 at 3:22 am

    Hi Chris,

    Will there be any change in IP address if i STOP and START the VM from the portal?

    Also will there be any impact on the applications installed on that server?

    Thanks in advance.

    • Properly Shutdown Azure VM To Save Money | Build5Nines (26)

      Chris Pietschmannon March 23, 2018 at 7:43 am

      By default, Azure VMs will have a Dynamic IP Address assigned to them so when they are Deallocated then the IP Address can/will change. However, you could configure your VMs to have Static IP Addresses, then they would not change when deallocated.

      As far as applications installed on the server, these would have no effect from deallocation itself. When stopping and deallocating a VM you are essentially doing the same as turning off the VM or machine, so you should expect normal behavior as you would expect here.

  10. Properly Shutdown Azure VM To Save Money | Build5Nines (27)

    rohiton March 30, 2018 at 1:03 am

    Auto-Shutdown doesn’t have a time of auto-boot
    Is there a way I can set the start time as well?

  11. Properly Shutdown Azure VM To Save Money | Build5Nines (30)

    Peter Felberon June 7, 2018 at 10:38 am

    Is it possible to somehow execute a Stop(deallocate) from within the vm without extra permissions?
    eg: shutdown –deallocate

  12. Properly Shutdown Azure VM To Save Money | Build5Nines (33)

    Rahul Sarkaron January 28, 2019 at 1:47 am

    Hi Chris
    Thanks for this life saver article. I am getting upto speed on Azure using my company provided MSDN VS professional subscription.
    This is a tip which every beginner Azure Developer should familiarize themselves with! Thanks a bunch mate.

    • Properly Shutdown Azure VM To Save Money | Build5Nines (34)

      Chris Pietschmannon March 25, 2019 at 11:00 pm

      Thanks Rahul! I’m really glad my article has helped you. Please subscribe to the Build Azure Weekly newsletter if you haven’t already to get weekly status updates on Microsoft Azure in your email every week. 🙂

  13. Properly Shutdown Azure VM To Save Money | Build5Nines (35)

    Sunilon June 21, 2019 at 12:18 pm

    Hi Chris,

    I have allocated Static IP for my VM.
    Now my question is if I write a script to Start and Stop the VM on a schedule, will I lose the Static IP ?

    Thanks for you article, I thought if we stop the VM, we are not paying anything, but came to know we do pay for Storage 🙂

    Sunil Nokku

    • Properly Shutdown Azure VM To Save Money | Build5Nines (36)

      Chris Pietschmannon July 15, 2019 at 10:21 pm

      If you have a static IP configured, then deallocating your VM will not affect the IP address. With the IP set as Static, it’s reserved for your use regardless of the state of the VM.

      Always glad to help. Thanks!

  14. Properly Shutdown Azure VM To Save Money | Build5Nines (37)

    Mark Bellon April 1, 2020 at 1:38 pm

    Hi. You mentioned that deallocated resources will allow other azure users to utilise the resources while you are not. Does this mean that there could be a risk of not been able to restart the VM due to limited resource availability for some VM Sizes, for example, the N-Series GPU based VMs. Thanks

    • Properly Shutdown Azure VM To Save Money | Build5Nines (38)

      Chris Pietschmannon April 3, 2020 at 1:25 pm

      The only way you wouldn’t be able to restart the VM would be if the Azure Region ran out of available resources for your chosen instance size / pricing tier. While possibly, not very likely, but it could happen.

      • Properly Shutdown Azure VM To Save Money | Build5Nines (39)

        Markon April 3, 2020 at 1:35 pm

        Chris, Thanks for your response. Given the current global pandemic, I would imagine that many companies are moving some services/workloads to the cloud which I think will increase the risk of my previous comment. I’m personnel costing VMs in European data centres and have a fear of not been able to restart some critical devices at present which are a necessity to some of our users working from home. Do you thing there is is a way to find out what percentage Microsoft oversell their available resources or a particular region?

      • Properly Shutdown Azure VM To Save Money | Build5Nines (40)

        Chris Pietschmannon April 3, 2020 at 8:47 pm

        When you say you have VMs that are critical to your users, then you wont be shutting those down. Production resources are generally left running so you can maintain availability. If you are looking to use VM Scale Sets to have flexible scalability, then you will still set a minimum number of instances to have running. Once a VM is running, you wont lose the ability to keep that VM running. When starting up VMs, it’s very rare for there to be issues provisioning the resources in Azure, and even at that it’s only for a very short period of time. Also, “Overselling” of resources in the cloud is not something that I’ve ever even heard about, from any cloud provider. This really isn’t something that you need to worry about.

  15. Properly Shutdown Azure VM To Save Money | Build5Nines (41)

    thomas wrobelon May 29, 2020 at 10:45 am

    Chris: after stopping a VM server will the servers public IP change upon restart? Thank You

    • Properly Shutdown Azure VM To Save Money | Build5Nines (42)

      Chris Pietschmannon May 29, 2020 at 11:27 am

      By default the VM will have a dynamic IP, so yes it will change. If you configure a static IP then your IP will remain the same after deallocation and reallocation of the VM.

  16. Properly Shutdown Azure VM To Save Money | Build5Nines (43)

    VIVEK JAINon June 21, 2020 at 3:12 am

    Hi Chris: Does Auto Shut down also deallocated the VM?

    • Properly Shutdown Azure VM To Save Money | Build5Nines (44)

      Chris Pietschmannon June 22, 2020 at 4:52 pm

      Yes it deallocates the VM.

  17. Properly Shutdown Azure VM To Save Money | Build5Nines (45)

    Kapil Nakeron July 22, 2020 at 6:56 am

    Hello Chris,
    As you mentioned that “Stopping the VM retains all the VM’s settings / configurations, as well as the .vhd image stored in Azure Storage”. I could not find my de-allocated vm’s disk file in the Azure storage. However, I can still see the Disk export option for the VM disk and can download the VHD file . So my question is, when the VM is deallocated, does Azure internally manage the storage part of disk and other configuration or is it stored in Azure storage from where we can check using storage explorer.

    • Properly Shutdown Azure VM To Save Money | Build5Nines (46)

      Chris Pietschmannon July 22, 2020 at 9:50 am

      The old method of storing a .VHD file for VMs in Azure was to use an Azure Storage Account (which still can be done today), but the new way is to use Managed Disks. As a result, most Virtual Machines created today in Azure will have a “Disk” resource where the .VHD file is stored. This is what you are referring to. You will still pay for the storage of that .VHD file when the VM is “Stopped (deallocated)” just the same whether your VM is using Azure Disks or Storage Account for it.

  18. Properly Shutdown Azure VM To Save Money | Build5Nines (47)

    Aleksandron July 27, 2020 at 5:37 pm

    Hi Chris,

    I will be creating VMs in Azure that will not be frequently used, these will have Managed SSDs for about 512Gb. As these VMs will spend significant time in the de-allocated state, I would like to estimate my costs that will be incurred for the storage of the .VHD files. Please suggest any resource that I can use to estimate these costs or provide a realistic case so I can have ballpark figure for such. Thank you.

    • Properly Shutdown Azure VM To Save Money | Build5Nines (48)

      Chris Pietschmannon July 28, 2020 at 1:02 pm

      You can use the Azure Pricing Calculator at https://azure.com/pricing to estimate cost. For the VM… The Disk storage will be billed all month, and the compute for the VM Size will be only billed for the time you have the VM running by the hour. Any time spent in a “Stopped (deallocated)” state wont accrue towards the VM Size billing, but will still count towards the Disk storage.

  19. Properly Shutdown Azure VM To Save Money | Build5Nines (49)

    learnerson September 25, 2020 at 1:34 am

    Is VM backup process will run even if VM in shutdown state?

    • Properly Shutdown Azure VM To Save Money | Build5Nines (50)

      Chris Pietschmannon September 27, 2020 at 7:44 pm

      Yes, as long as your back up process isn’t something running directly on the VM.

  20. Properly Shutdown Azure VM To Save Money | Build5Nines (51)

    allan santiago oshimaon October 22, 2020 at 12:10 pm

    Hi Chris, how could I auto-start the VM again?

    • Properly Shutdown Azure VM To Save Money | Build5Nines (52)

      Chris Pietschmannon October 23, 2020 at 9:19 am

      You would have to instrument some other kind of automation using Azure Automation, Azure Function, or something else that could use the Azure CLI or other method to automatically start the VM again at a desired time.

  21. Properly Shutdown Azure VM To Save Money | Build5Nines (53)

    Andreaon December 9, 2020 at 11:56 am

    If I auto shut down my vm, my data in sql server won’t get updated?

    • Properly Shutdown Azure VM To Save Money | Build5Nines (54)

      Chris Pietschmannon December 9, 2020 at 9:06 pm

      Correct, if you shutdown the VM then anything running on it will be stopped.

  22. Properly Shutdown Azure VM To Save Money | Build5Nines (55)

    Yuga Prasadon December 20, 2020 at 11:19 pm

    Hi Chris,

    May i know the exact cost difference when the VM is in the Deallocated and stop state

Properly Shutdown Azure VM To Save Money | Build5Nines (2024)
Top Articles
Latest Posts
Article information

Author: Pres. Carey Rath

Last Updated:

Views: 6098

Rating: 4 / 5 (41 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Pres. Carey Rath

Birthday: 1997-03-06

Address: 14955 Ledner Trail, East Rodrickfort, NE 85127-8369

Phone: +18682428114917

Job: National Technology Representative

Hobby: Sand art, Drama, Web surfing, Cycling, Brazilian jiu-jitsu, Leather crafting, Creative writing

Introduction: My name is Pres. Carey Rath, I am a faithful, funny, vast, joyous, lively, brave, glamorous person who loves writing and wants to share my knowledge and understanding with you.