Billing surprises: find what costs money

Azure unexpected charges hardly ever come from one big mistake. They come from small things that keep billing quietly in the background, like a VM that was stopped but never deallocated, disks and public IPs left behind, a gateway someone forgot after a test, or snapshots nobody remembers taking. Each one costs a little every hour, and the hours add up.

In Lesson 44 you set up budgets and alerts and had a first look at costs. This time it’s the troubleshooting side: the bill is higher than you expected, so where’s the money going, and what should you switch off?

You’ll query costs by service and by resource, save a waste finder script that you’ll use again in the final project, and then fix the two “I thought I turned it off” charges that catch out almost everyone.

TimeYou needCostBy the end you can
About 45 minutesA free account, the CLI and PowerShellAbout 2 US cents: one small VM for a short timeFind what is costing money by service and resource, and remove the common silent charges

What it is, in one line

You trace unexpected Azure charges by asking Cost Management which service and resource cost money, and then finding the resources that bill while doing nothing.

In Simple Words

The electricity bill that doubled

Say your electricity bill suddenly doubles. You wouldn’t start by throwing out the fridge. You’d read the bill to see which meter and which month, and then walk through the house, where you find the geyser left on in the guest bathroom, a TV on standby and an old freezer humming away in the garage. None of them is big on its own, but running 24 hours a day together they double the bill. Cost Management is that bill broken down by meter, and the waste finder script is your walk through the house.

Engineer's View

Where silent charges hide

  • Stopped vs deallocated: a VM shut down from inside the OS, or with az vm stop, ends up Stopped and is still billed for compute. Only Stopped (deallocated) ends the compute charges.
  • Deallocated VMs still cost money: their disks (in state Reserved) and Standard public IPs keep billing, and Premium disks on parked VMs are the classic surprise.
  • Leftovers: unattached disks, unused public IPs, NICs (these are free) and snapshots from old changes.
  • Hourly services: VPN gateways, Azure Firewall, Application Gateway, NAT gateways and Bastion (apart from the Developer SKU) bill for every hour they exist, whether or not any traffic goes through them.
  • Data-based charges: Log Analytics ingestion, egress and backup storage all grow with use, so check them by meter.
  • Cost data delay: Cost Management usually runs several hours to a day behind, so pair it with a live inventory of what exists right now.

How it works, step by step

This order finds the money fastest:

Azure unexpected charges: tracing a higher bill step by step
  1. Which service? Group month-to-date cost by service name, and you’ll usually find one or two services explain most of the increase.
  2. Which resources? Group by resource ID, or filter down to that service, to get the names.
  3. What exists right now? Since cost data lags, run an inventory query for the known waste patterns.
  4. Who created it and why? Before you delete anything, check the Activity log and the tags (Lesson 59).
  5. Stop it, then prevent it: deallocate, delete or downgrade it, and then add a budget alert, auto-shutdown or a policy so it doesn’t come back.

Don’t delete anything straight from a cost report. Find the owner first, because that disk might be the only copy of something important.

Silent Azure charges: VMs, leftovers and hourly services

Before you run any command, double-check it

Read every command twice before you press Enter. Check the target: the system or account, the IDs, the names and the sizes. These commands are for learning and were tested in our lab, not on your system. At work, run the read-only list commands first, follow your change process, make sure a backup exists, and ask a second person to check anything that changes or deletes data. You run them at your own risk.

Keep cost per hour in your head. A gateway at USD 0.20 per hour comes to USD 146 a month, and on a free account’s credit that’s a big share.

When the surprise is Log Analytics

Monitoring is a common reason for a growing bill, because ingestion creeps up quietly as you add machines and raise log levels. The Usage table in each workspace shows which data types bring in the most data, so run this in law-saat or any other workspace:

Usage
| where TimeGenerated > ago(7d) and IsBillable == true
| summarize GB = round(sum(Quantity) / 1000, 3) by DataType
| top 5 by GB desc

Quantity is in megabytes. If one table takes up most of it, look at the data collection rule feeding it (Lesson 70), lower the level or add a transformation, and think about a daily cap for non-production workspaces like the one law-saat has.

Trace costs and find what bills while idle

1Cost by service, month to date

Ask Cost Management for this month’s cost, grouped by service:

New-Item -ItemType Directory -Force C:\azure-lab\l73 | Out-Null
$sub = az account show --query id -o tsv
@{ type = 'ActualCost'; timeframe = 'MonthToDate'; dataset = @{ granularity = 'None'; aggregation = @{ totalCost = @{ name = 'Cost'; function = 'Sum' } }; grouping = @(@{ type = 'Dimension'; name = 'ServiceName' }) } } | ConvertTo-Json -Depth 10 | Set-Content C:\azure-lab\l73\cost-by-service.json
$r = az rest --method post --url "https://management.azure.com/subscriptions/$sub/providers/Microsoft.CostManagement/query?api-version=2023-03-01" --body '@C:\azure-lab\l73\cost-by-service.json' | ConvertFrom-Json
$r.properties.rows | Sort-Object { [double]$_[0] } -Descending | Select-Object -First 6 | ForEach-Object { '{0,-40} {1,10:N2} {2}' -f ($_[1] -split '/')[-1], [double]$_[0], $_[2] }

You’ll see your own list, roughly like this:

Virtual Machines                               0.62 USD
Virtual Network                                0.48 USD
Storage                                        0.21 USD
Log Analytics                                  0.09 USD
Bandwidth                                      0.01 USD

2Cost by resource

Now change the grouping to see which resources cost the most:

@{ type = 'ActualCost'; timeframe = 'MonthToDate'; dataset = @{ granularity = 'None'; aggregation = @{ totalCost = @{ name = 'Cost'; function = 'Sum' } }; grouping = @(@{ type = 'Dimension'; name = 'ResourceId' }) } } | ConvertTo-Json -Depth 10 | Set-Content C:\azure-lab\l73\cost-by-resource.json
$r = az rest --method post --url "https://management.azure.com/subscriptions/$sub/providers/Microsoft.CostManagement/query?api-version=2023-03-01" --body '@C:\azure-lab\l73\cost-by-resource.json' | ConvertFrom-Json
$r.properties.rows | Sort-Object { [double]$_[0] } -Descending | Select-Object -First 6 | ForEach-Object { '{0,-40} {1,10:N2} {2}' -f ($_[1] -split '/')[-1], [double]$_[0], $_[2] }

You should see resource names with their cost, for example the disks, public IPs and gateways left from earlier lessons.

3Save the waste finder

Save this as C:\azure-lab\Find-AzureWaste.ps1, because you’ll use it again in Lesson 74:

param([int]$SnapshotAgeDays = 30)
# SaatVedha Azure Lesson 73: list resources that cost money while doing nothing useful
$checks = [ordered]@{
    'VM stopped, not deallocated'   = "resources | where type =~ 'microsoft.compute/virtualmachines' | where tostring(properties.extended.instanceView.powerState.code) == 'PowerState/stopped' | project name, resourceGroup, detail = tostring(properties.hardwareProfile.vmSize)"
    'Disk of a deallocated VM'      = "resources | where type =~ 'microsoft.compute/disks' | where tostring(properties.diskState) == 'Reserved' | project name, resourceGroup, detail = strcat(tostring(sku.name), ' ', tostring(properties.diskSizeGB), ' GiB')"
    'Unattached disk'               = "resources | where type =~ 'microsoft.compute/disks' | where tostring(properties.diskState) == 'Unattached' | project name, resourceGroup, detail = strcat(tostring(sku.name), ' ', tostring(properties.diskSizeGB), ' GiB')"
    'Public IP not in use'          = "resources | where type =~ 'microsoft.network/publicipaddresses' | where isnull(properties.ipConfiguration) and isnull(properties.natGateway) | project name, resourceGroup, detail = tostring(sku.name)"
    'Hourly network service'        = "resources | where type in~ ('microsoft.network/azurefirewalls', 'microsoft.network/applicationgateways', 'microsoft.network/virtualnetworkgateways', 'microsoft.network/natgateways', 'microsoft.network/bastionhosts') | where not(type =~ 'microsoft.network/bastionhosts' and tostring(sku.name) == 'Developer') | project name, resourceGroup, detail = type"
    "Snapshot older than $SnapshotAgeDays days" = "resources | where type =~ 'microsoft.compute/snapshots' | where todatetime(properties.timeCreated) < ago(${SnapshotAgeDays}d) | project name, resourceGroup, detail = strcat(tostring(properties.diskSizeGB), ' GiB')"
}
$found = foreach ($c in $checks.GetEnumerator()) {
    $rows = (az graph query -q $c.Value --first 1000 -o json | ConvertFrom-Json).data
    foreach ($r in $rows) { [pscustomobject]@{ Finding = $c.Key; Name = $r.name; ResourceGroup = $r.resourceGroup; Detail = $r.detail } }
}
if ($found) { $found | Sort-Object Finding, Name | Format-Table -AutoSize } else { 'Nothing found.' }

Run it:

C:\azure-lab\Find-AzureWaste.ps1

You should see something like this:

Finding                   Name            ResourceGroup  Detail
-------                   ----            -------------  ----------------------
Disk of a deallocated VM  web01_OsDisk_1  RG-SAAT-VMS    StandardSSD_LRS 30 GiB
Disk of a deallocated VM  win01_OsDisk_1  RG-SAAT-VMS    StandardSSD_LRS 127 GiB

Your list depends on what you kept from earlier lessons. The disks of the parked web01 and win01 show up because deallocated VMs still pay for their disks.

Find-AzureWaste output showing disks of deallocated VMs
Find-AzureWaste lists what still bills while you are not using it.
Find-AzureWaste script listing disks of deallocated VMs
What exists right now, not yesterday’s cost data.

✅ Checkpoint: You can see this month’s cost by service and by resource, and the waste finder lists what exists right now.

Break It, Then Fix It

Both breaks use the same small test VM.

1Break it: “I stopped the VM”

Create a VM and stop it the way a lot of people do, with stop instead of deallocate:

az group create --name rg-saat-l73 --location centralindia --tags course=saatvedha-azure lesson=73 -o none
az vm create --resource-group rg-saat-l73 --name vm-idle --image Canonical:ubuntu-24_04-lts:server:latest --size Standard_B1s --public-ip-sku Standard --nsg-rule NONE --admin-username azureuser --generate-ssh-keys --tags course=saatvedha-azure lesson=73 -o none
az vm stop --resource-group rg-saat-l73 --name vm-idle
az vm get-instance-view --resource-group rg-saat-l73 --name vm-idle --query "instanceView.statuses[1].displayStatus" -o tsv
C:\azure-lab\Find-AzureWaste.ps1

You should see something like this:

VM stopped
Finding                      Name     ResourceGroup  Detail
-------                      ----     -------------  ------------
VM stopped, not deallocated  vm-idle  rg-saat-l73    Standard_B1s
...

When you use az vm stop, the CLI even prints a warning that the VM is still allocated and still billed for compute, and shutting down from inside the OS does the same thing. Plenty of teams pay for “off” VMs for months without noticing.

To fix it, deallocate the VM and check its state:

az vm deallocate --resource-group rg-saat-l73 --name vm-idle
az vm get-instance-view --resource-group rg-saat-l73 --name vm-idle --query "instanceView.statuses[1].displayStatus" -o tsv

You should see VM deallocated. For VMs that ought to be off at night, use auto-shutdown (which deallocates) or the runbook from Lesson 43.

2Break it: “I deallocated it, why am I still paying?”

vm-idle is deallocated now, but run the finder again and look at its disk and public IP:

C:\azure-lab\Find-AzureWaste.ps1
az disk list --resource-group rg-saat-l73 --query "[].{name:name, sku:sku.name, sizeGiB:diskSizeGB, state:diskState}" -o table
az network public-ip list --resource-group rg-saat-l73 --query "[].{name:name, sku:sku.name, ip:ipAddress}" -o table

You should see something like this:

Name                       Sku          SizeGiB  State
-------------------------  -----------  -------  --------
vm-idle_OsDisk_1_8f3c...   Premium_LRS  30       Reserved
Name             Sku       Ip
---------------  --------  ------------
vm-idlePublicIP  Standard  20.x.x.x

Deallocating stopped the compute charges, but the Premium SSD and the Standard public IP are still billing every hour. For a VM that’s parked for weeks, that’s money for nothing.

To fix it, move the disk of a parked VM to Standard HDD while it’s deallocated, and release the public IP if nothing needs it (remember to switch the disk back before you start the VM for real work):

$disk = az disk list --resource-group rg-saat-l73 --query "[0].name" -o tsv
az disk update --resource-group rg-saat-l73 --name $disk --sku Standard_LRS --query sku.name -o tsv
az network nic ip-config update --resource-group rg-saat-l73 --nic-name vm-idleVMNic --name ipconfigvm-idle --remove publicIpAddress -o none
az network public-ip delete --resource-group rg-saat-l73 --name vm-idlePublicIP

The disk now shows Standard_LRS and the public IP has gone. If a VM is truly finished with, take a snapshot or backup if you need one and then delete it along with its disks.

A VM stopped but not deallocated, still billed for compute
Stopped still pays for compute.

3Clean up

Delete the test group, but keep Find-AzureWaste.ps1:

az group delete --name rg-saat-l73 --yes

✅ Checkpoint: You traced costs by service and resource, and removed a stopped-but-billed VM and the leftovers of a parked one.

This happened at work

The student project that cost more than the course fee

A college ran an Azure lab for 60 students, and each student built a small environment with a VM, a VPN gateway for a networking exercise and a few disks. At the end of the module they were all told to “stop everything”, and the following month’s bill came in higher than the module’s whole budget. When the instructors went through it, most students had shut their VMs down from inside Windows, which left them Stopped and not deallocated. Every VPN gateway was still running too, since a gateway has no “stop” and bills until it’s deleted, and Premium disks on the parked VMs made up the rest.

What they changed: every student group now gets a budget with alerts at 50 and 90 percent, and an Automation runbook deallocates all the VMs every night. Gateways can only be created through a template that also sets up a deletion reminder, and a waste finder script runs weekly and goes to the instructors.

Common mistakes and troubleshooting

MistakeWhat you seeWhat to do
Stopping instead of deallocatingCompute still billedDeallocate, or use auto-shutdown.
Parking VMs on Premium disksDisk charges with no useSwitch to Standard HDD while parked, or snapshot and delete.
Forgetting hourly gatewaysSteady hourly chargesDelete gateways, firewalls and App Gateways after labs.
Deleting from a cost reportLost data or broken servicesFind the owner and check the Activity log first.
Relying only on cost dataRecent waste not visible yetRun a live inventory too.
No budget alertsSurprise at month endBudgets with alerts on every subscription.

Interview questions

Click a question to open it. Each one is phrased the way an interviewer would ask it, and under it you’ll find why they ask and one way you could answer in your own words.

Fresher level

1. What’s the difference between Stopped and Stopped (deallocated)?

Why they ask this: The basic concept.

How you might answer: Stopped keeps the VM allocated, so you’re still billed for compute. Deallocated releases the hardware and the compute charges stop.

2. What keeps billing after a VM is deallocated?

Why they ask this: A common surprise.

How you might answer: The managed disks, Standard public IPs, snapshots and backup storage.

3. Where do you see what costs money?

Why they ask this: Tool knowledge.

How you might answer: In Cost Management, using cost analysis by service, resource group and resource, plus budgets and anomaly alerts.

2–5 years experience

4. The bill doubled this month. How do you investigate?

Why they ask this: A real troubleshooting path.

How you might answer: I’d group cost by service and then by resource and compare it with last month. Then I’d run an inventory for hourly services and leftovers, check the Activity log to see who created them, and stop or remove them together with the owner.

5. How do you find unattached disks and unused public IPs at scale?

Why they ask this: Practical skill.

How you might answer: With Resource Graph queries across all subscriptions, looking for disks in state Unattached and public IPs that have no ip configuration.

6. How do you save money on dev and test VMs?

Why they ask this: Cost habits.

How you might answer: Auto-shutdown or runbooks that deallocate, B-series where it fits, Standard disks for parked VMs, dev/test pricing where you’re eligible, and deleting environments once you’re done with them.

Senior level

7. How would you build cost governance for a company?

Why they ask this: They want a program.

How you might answer: I’d start with a tagging policy for owner and cost centre, then budgets per subscription and per team, anomaly alerts and weekly waste reports. Add reservations and savings plans for steady use, and show each team what it spends.

8. When do reservations or savings plans make sense?

Why they ask this: FinOps judgement.

How you might answer: For steady, predictable workloads once they’ve been right-sized. Reservations suit specific sizes and regions, and savings plans suit compute that moves around.

9. How do you stop expensive resources being created in labs?

Why they ask this: Guardrails.

How you might answer: Azure Policy to deny certain SKUs or resource types in lab subscriptions, budgets with action groups, and templates that create resources with expiry tags and automated clean-up.

Quick quiz

Q1. A VM shut down from inside Windows is billed for?

  1. Nothing
  2. Compute and disks
  3. Only disks
  4. Only IPs
Show answer

B — It’s Stopped, not deallocated.

Q2. Disk state of a deallocated VM’s disk?

  1. Attached
  2. Reserved
  3. Unattached
  4. Deleted
Show answer

B — Reserved disks still bill.

Q3. Which keeps billing hourly with no traffic?

  1. NIC
  2. VPN gateway
  3. Route table
  4. NSG
Show answer

B — Gateways bill until deleted.

Q4. Why run a live inventory as well as cost reports?

  1. Cost data lags by hours
  2. It’s cheaper
  3. Required by law
  4. Faster login
Show answer

A — Cost Management isn’t real time.

Q5. Before deleting an expensive unknown resource, you should?

  1. Delete it now
  2. Find the owner and check the Activity log
  3. Restart it
  4. Resize it
Show answer

B — It might be needed.

Quick recap

That’s the end of Phase 4. You now have a troubleshooting method and scripts for the problems Azure engineers run into at work, and Phase 5 brings it all together.

  • Trace cost by service, then by resource.
  • Stopped is billed; deallocated is not, but disks and IPs are.
  • Hourly network services bill until deleted.
  • Find-AzureWaste.ps1 shows what exists right now.
  • Find the owner before deleting anything.

Next lesson

Lesson 74: Final project: build it, break it, fix it → You’ll build a small company on Azure from scratch and then fix 10 broken scenarios using everything from this course.

Further reading: Azure unexpected charges

Want to go deeper into Azure unexpected charges? See Microsoft’s Common cost analysis uses and States and billing status of Azure VMs. You can also see the full plan for this course on the Azure Cloud Administration course page.

Scroll to Top

This website uses cookies

We use a few cookies to keep this site working. If you allow it, we also use Google Analytics to count visits so we can improve our lessons. You can accept all, deny the optional ones, or choose what to allow.