
The cost of running virtualized resources such as servers, applications, and data in the cloud can exceed the expected budget set by an organization if proper checks are not put in place to help control or check excessive spending. It is worth knowing that the possibility of significant cost reductions is one of the primary drivers for businesses switching to the cloud. While it is possible to save money by moving to the cloud rather than staying on-premise, it is also simple to end up spending more than you intended because of cloud sprawl, unclear governance, and general unforeseen/unbudgeted utilization of Azure resources. In this article, you will learn how to Control Cloud Cost Using Azure VM.
Microsoft Azure is the go-to cloud computing service for small, and large companies. There are many ways you can save cost using Virtual Machines on your Azure subscription. In this post, I discuss the various ways you can control running cloud costs using Azure VMs by carrying out some specific tasks ranging from shutting down your unused VMs, resizing the OS disk, and disassociating the NIC Public IP (PIP) Address attached to your VM to using reserved VM Instances (RI’s) as being one of the programmatic ways of controlling the overhead cost of powering your workloads on Azure.
Prerequisites for Controlling Cloud Cost Using Azure VM
To get along with this post, you should have the following:
- Active Azure subscription with admin access. If you don’t already have one you can sign up here for the free tier pricing option.
- If you have an active subscription to Azure, you must have a Virtual Machine created already. If you don’t have a virtual machine in place, follow this post to learn how to create one.
The good news is that you can recover control of Azure cloud costs and achieve meaningful cost optimization with some simple analysis and careful planning. You may also be interested in learning about the following: Remove Azure VM: How to delete a Virtual Machine via the Azure Portal, Virtual Machine Scale Set: Demonstrating High Availability in Azure, how to Manage Azure Virtual Machines with Windows Admin Center and Serial Console, how to create and attach an extra Disk to Azure Virtual Machine, and Cost Management in Azure using cost analysis tool: How to query a log that can analyze cost in Azure.
Controlling Cloud Cost with Azure Virtual Machines (Pre-VM Creation)
If you have the above requirements in place, let’s get started. Below are various to reduce running costs with Azure VMs:
Step 1: Control cost through VM Configuration during the creation process
In this step, I take you through some steps you can apply to reduce or control costs during the VM creation process. You can create a VM in 4 ways; that’s using the Portal, Azure CLI, PowerShell and Azure SDK.
Here we will use the Azure portal so you can see the various steps you can apply while creating the VM to reduce cost. To get started, log in to the Azure portal

When the portal opens up as shown above, search for Virtual Machines in the horizontal search bar if it has not already been pinned on your dashboard.
When you’re on the VM console, click on create to get started with the VM creation task.

Next, supply all the details required to get your VM up. Such details are subscription, resource group, VM name, region, availability options (optional on most occasions depending on your workloads requirements), security type and the VM image and many more

Take advantage of Azure Hybrid Benefits
Azure Hybrid Benefits (AHB) and Reserved VM Instances can be combined together to help you can save up to 70% over the Pay-As-You-Go approach. AHB can result in significant savings on the Operating System (Windows Server OS) and SQL Server sides, while RIs help achieve reductions on the compute side of Virtual Machine expenditures.
Anyone with a Software Assurance license for Windows Server or SQL Server is qualified to run Azure VMs at the best prices. As a result, the hourly cost of the OS/SQL Server license is eliminated, leaving you to pay only the virtual machine's compute rate. Customers can still benefit from AHB's cost savings even if they don't currently own qualifying licenses by purchasing new licenses with software assurance or in a 1-year or 3-year subscription model.
You will see Licensing on the same screen where you’re creating your VM, endeavor to check that you would like to use an existing Windows Server license and confirm that you have an eligible Windows Server license with Software Assurance or Windows Server Subscription to apply for the Azure Hybrid Benefits. see the screenshot below for more information.

Configuring the OS Disk options for Azure VM
When you’re creating Azure VM, it is important to carry out some configuration within the disk tab.

As shown in the above screenshot, the default OS disk option is usually the premium SSD option. It is necessary for you to change this to something that best fits the demands of your workload and at the same time helps reduce cost.
Here you have to ensure that the Delete with VM option is checked.If it's not checked, when you delete your VM, the disk will remain on your account and you will be charged for it. Only retain the disk if your organization's policy allows it.
Configuring the Networking options for Azure VM
You need to reduce costs by configuring the network settings for your VM properly

When you first create your Virtual Machines on Azure, Azure automatically attached the network to it. As shown in the screenshot above for non-production workloads, it is advisable to select the Basic option for the NIC network security group.
If you select the advanced option, endeavour to check the Delete public IP and NIC when VM is deleted. If you choose to enable an accelerated network to ensure low latency for your VM, go ahead and check since it is free of charge.
Accelerated Networking is a feature that significantly enhances the performance you get out of a virtual machine. The feature is free but is only available in selective VM sizes.
For the Azure Load Balancer, only the Basic option is free of charge but is not provided along with the basic Virtual Machine.
On the other hand, Application Gateway has neither an upfront nor a termination cost. Just the resources that were pre-provisioned and used based on actual hourly consumption will be charged to you.
Application Gateway costs are divided into two categories: fixed costs and variable costs. The SKU being used will determine the actual costs for each component.
You can decide whether to enable either the Azure Load Balancer or Application Gateway depending on your requirements. The best practice for saving cost is that you should enable anyone if you DON’T need it.
Configuring the Management options for Azure VM
Now head to the management tab to configure the auto-shutdown for your VM. The auto-shutdown can be configured to work with different time zones depending on your time zone. Here, we choose the (UTC+01:00) West Central Africa time zone. Choosing the time zone that’s peculiar to your location will help you keep track of it.

Configuring the Monitoring options for Azure VM
It is a good idea to configure the monitoring option for your VM. This is will enable you to stay up to date with what is happening to your VMs. Although it comes with a monthly cost of $0.70 per VM if select all the 7 options available by default.
The best practice for reducing running costs is to select the options considered to be critical to be most critical for your VM's life. Each option cost about $0.10.
If the options are okay with you, go ahead and configure them based on your requirements.

Configuring the Tags option for Azure VM
Utilizing the tag option is one of the ways to check excess costs incurred by your VM. If you have multiple VMs for different departments, applying tags to them can help you retrieve information on the cost of those VMs. This makes it easy for you to understand which of the VM belonging to a particular department is costing you more and you can shut down or resize them as necessary.

Tags are metadata elements that you apply to your Azure resources. They're key-value pairs that help you identify resources based on settings that are relevant to your organization.
Controlling Cost with Azure VM (Post-VM Creation)
In this section of the post, we take a look at some of the things you should do to control the running cost for your VM after it has been created.
The Virtual Machine we created in the previous steps has been created successfully and we’re right in the VM dashboard.
From the menus above the VM metadata, the specific actions you can carry out are connecting to the VM, restarting, stopping, capturing, deleting and lots more options.

Options that are specific to this discussion are stopping and deleting the VM. You can run a CLI or PowerShell command to stop your VM. This will prevent you from using the OS and stop all processes but will maintain the allocated hardware (including the Public IP addresses and OS disk currently assigned). If you find the VM in the Azure console, you’ll see the status listed as “stopped/deallocated” and the stop and restart menus greyed out.
One most important things to know about this state is that you are still being charged by the hour for this instance.
Stopping or De-allocating VMs using Azure CLI
To stop your Azure VM, run the below command using either the built-in Windows Command Prompt, PowerShell or Azure Cloud Shell directly on the Azure Portal.
# Stop Azure VM
az vm stop --name {vm name} --resource-group {resource group name}
We are using the built-in Windows Command Prompt. Note, you have to install and configure the Azure-CLI on your local system before this can work. You can download and install the .msi setup for Azure CLI for Windows here.

Now that we have stopped the VM if you check the portal the status will indicate, stopped/deallocated and the stop and restart menus will be greyed out.

Deallocating VM Using Azure CLI
Another way to stop your virtual machine is through deallocation, whether it’s done using the console, Powershell, or the Azure CLI it is still the same result you will get. When you deallocate a VM, rather than just stopping the OS from running, it goes into a “Stopped (deallocated)” state. This means that any non-static public IPs will be released, and you will stop paying for the VM’s compute costs.
To deallocate a VM using Azure CLI, run the command below:
# De-allocate Azure VM
az vm deallocate --name {vm name} --resource-group {resource group name}

Running the above command to deallocate the VM won’t give you any prompt after it has successfully deallocated your VM. To know if it takes effect go to the Portal and refresh the VM console to see the effect.
Controlling Cloud Cost by Resizing the VM OS Disk
Resizing your OS disk is one of the ways to reduce the running cost using Azure VM. We are to do this through the portal.
Let’s go to the portal.
Our current disk storage type is premium SSD as shown below:

From the VM blade click on Size->Disk Size ->Click Resize

We chose the general-purpose option with the least pricing option.


You will receive a notification after the disk has been resized.
Save Cloud Cost by Disassociating NIC Public IPv4 Address from VM
The final point in this write-up is to learn how to disassociate the Network Interface Card’s public IP that’s attached to the Virtual Machine.
To do this, head to the portal and locate the VM of your choice that you want to disassociate the Network interface card from.
From the VM blade, locate Networking under the “Settings” tab and then click on NIC Public IP: 4.168.193.XXX

When the NIC Public IP address console opens, click on “Disassociate” and then click on Yes.

After disassociating the NIC Public IP, you will release that the Disassciate tab is greyed out leaving you with a few other options such as Associate, Move, Delete and Refresh.

You can reassociate back to the Network interface as shown below:

You can also move it to another resource group, subscription or region as the case may be or delete the Public Ip you have disassociated.

Clean-up Resources
The ultimate cost-saving strategy is to clean up unused resources such as Virtual Machines, Storage Accounts and many more if you are no longer in need of them.
There are about 6 resources that work together to power the virtual machine as shown in the screenshot below. So deleting the resource group will get rid of all the resources at the same time.

To delete the resource group, run the below command and press “y” when prompted to do so:
$az group delete --name {resource-group-name}

I hope you found this blog post helpful. In this guide, you have learned how to Control Cloud Cost Using Azure Virtual Machines. If you have any questions, please let me know in the comment session