Skip to content
Tutorials Center
My learning

Topics

Lesson 45 of 57 ยท Security, Monitoring and Cost

Pricing, Cost Management and Budgets

Learn how Azure pricing works: cost factors, the pricing calculator, reservations, savings plans, spot VMs, budgets and alerts, tagging and surprise bills, with an estimator.

The cloud's promise is paying only for what you use. Its trap is the same sentence: you pay for everything you use, including what you forgot you started. A VM left running over a holiday, a database sized for a demo that became production, a storage account collecting logs nobody reads: each is cheap by the hour and expensive by the month. Cost is an engineering property, like performance, and you manage it deliberately.

This lesson covers what drives an Azure bill, how to estimate it before you build, three ways to pay less (reservations, savings plans and spot), how budgets and alerts work, how tags make costs attributable, and the surprise bills that catch beginners. The commands are read-only. The runnable examples are JavaScript stand-ins that use made-up round prices, not real Azure prices. They show how the arithmetic behaves, so use the official calculator for real numbers.

What drives the bill

Almost every Azure service is billed on a few meters. Learn to ask, for each service, "what is the meter?"

Factor Examples
Compute time VM hours (running, or allocated), App Service plan hours, Function executions and GB-seconds
Size or tier VM series and size, database vCores or DTUs, App Service tier
Storage volume GB stored per month, by access tier (hot, cool, cold, archive) and redundancy
Operations Storage transactions, Cosmos DB request units, API calls
Data transfer Egress (data leaving Azure to the internet or another region); data coming in is free
Region The same service costs different amounts in different regions
Extras Public IPs, load balancers, firewalls, backups, log ingestion, support plans

Two details cause many surprises. First, a stopped VM still pays for its disks and public IPs, and a VM that is "stopped" inside the operating system but not deallocated keeps its compute charge. Second, some resources are billed simply for existing: an App Service plan, a Premium Redis cache or an Azure Firewall costs money every hour even with zero traffic.

Estimating before you build

The Azure Pricing Calculator is a web tool where you add services, choose region, size, redundancy and expected usage, and get a monthly estimate you can export or share. Do this before committing to a design: compare two architectures, see whether egress or storage dominates, and keep the estimate as a baseline to compare with the real bill.

Once resources exist, Azure Advisor reviews them and recommends savings: shut down idle VMs, resize underused ones, buy reservations.

Pricing facts change, so always read the current price list. What stays stable is the method: list the meters, estimate quantities, multiply, add a margin.

An estimator you can run

The stand-in below is a monthly estimator with made-up prices: $0.20 per VM hour, $0.02 per GB of storage, $0.08 per GB of egress after 100 free GB, and $150 for a database. It prices the same workload three ways: always-on pay-as-you-go, always-on with a 3-year reservation (modeled as 40 percent of the pay-as-you-go rate), and a dev/test environment that is switched off outside working hours (about 220 hours a month).

JS A monthly cost estimator

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice what the totals say. The VMs are 72 percent of the pay-as-you-go bill, so discounting the VMs moves the total the most. Once they are cheaper, the fixed items (database, storage, egress) become the larger share, and that is where the next savings must come from. Change vmPricing to "spot" and vmHoursPerMonth to a batch-job figure to see what interruptible capacity could do.

Paying less: reservations, savings plans, spot and more

Pay-as-you-go has the highest hourly rate and no commitment. If a workload will run for a year or more, you have better options:

  • Reservations. You commit to a specific resource (for example a VM size in a region, or database capacity) for 1 or 3 years and get a large discount, often tens of percent. You can usually pay upfront or monthly. A reservation is a billing discount applied automatically to matching usage, not a physical resource. You pay whether you use it or not, so reserve only your steady baseline.
  • Savings plans for compute. You commit to spend a fixed amount per hour for 1 or 3 years, and the discount applies flexibly across VM sizes, regions and also some other compute services. The discount is a little smaller than a reservation, in exchange for flexibility.
  • Spot VMs. Unused Azure capacity at a deep discount, but Azure can evict your VM with short notice when it needs the capacity back. Good for interruptible work: batch jobs, rendering, CI agents, stateless workers behind a queue. Never for a lone production database.
  • Azure Hybrid Benefit. Bring your existing Windows Server or SQL Server licenses (with Software Assurance) and stop paying for the license portion again.
  • Dev/test pricing and shutdown schedules. Non-production environments rarely need to run at night. Auto-shutdown or a schedule can remove two-thirds of their compute cost (see the third scenario above).
  • Right-sizing and tier choice. Many VMs run at 5 percent CPU. Smaller sizes, serverless databases that pause, and the cool or archive tiers for old data are all savings (see Storage Accounts and Blob Storage and Azure SQL Database).
  • Scale to what you need. Autoscale adds capacity for peaks and removes it afterwards (see Scaling and Autoscale).

The usual order: delete what you do not use, right-size what remains, then commit to what is stable. Committing before cleaning up locks in waste.

A free account gives a credit for the first 30 days, a set of services free for 12 months, and some services always free within monthly limits (see Accounts, Tenants and Subscriptions). Read the limits; going past them is billed normally.

Seeing your costs: Cost Management

Microsoft Cost Management is built into the portal and works at the scope you choose (management group, subscription, resource group). Its main tools:

  • Cost analysis charts spend by service, resource group, location, tag or resource, over any period, so you can answer "what changed since last month?"
  • Budgets set a spending limit for a scope and period.
  • Alerts notify you when thresholds are crossed.
  • Exports send detailed cost data to storage on a schedule for your own analysis.
  • Advisor recommendations list savings.
  • Anomaly detection highlights unexpected jumps.
Terminal
# Read-only examples
az consumption usage list --top 5 -o table                       # recent usage records

az consumption budget create \
  --budget-name monthly-dev --amount 1000 --category cost \
  --time-grain monthly --start-date 2026-11-01 --end-date 2027-10-31 \
  --resource-group rg-dev

Cost data is not instant; it usually arrives several hours after usage, and some items take a day or more to appear. So cost control is a daily habit, not a real-time brake.

Budgets and alerts

A budget has an amount, a reset period (monthly, quarterly or yearly), a scope, and a list of alert conditions. Each condition is a percentage of the budget, on either actual cost or forecasted cost, and tells Azure whom to notify (emails and action groups, the same ones as in Azure Monitor, Log Analytics and Application Insights).

The important fact: a budget does not stop spending. By default it only sends notifications. To act, connect the alert to an action group that runs automation, such as a Logic App or Function that deallocates VMs or scales something down. Do this deliberately and only for non-production, because automatic shutdown can also stop something important.

Forecast alerts are the valuable ones. An alert at 100 percent of actual cost tells you after the money is spent; a forecast alert tells you while you can still change the outcome. The second stand-in models a $1,000 monthly budget and a runaway resource that starts growing on day 12. Alerts fire at 50 percent actual, 80 percent actual, 100 percent forecast and 100 percent actual. The forecast here is a naive straight line (spend so far divided by days elapsed, times 30); Azure uses its own model.

JS Budget alerts on actual and forecast spend

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The forecast alert fires on day 20, four days before the actual spend crosses $1,000. In a real month that is time to find the runaway resource. Even so, the month ends at $1,740: an alert only helps if somebody reads it and acts. Send budget alerts to a shared mailbox or channel, not to one person's inbox.

Tags and chargeback

Costs are only useful if you can say who they belong to. Apply tags (see Resource Groups and Azure Resource Manager and Azure Policy, Locks and Tags) such as costCenter, owner, environment and application, and then group cost analysis by tag. Two approaches build on this:

  • Showback: report each team's cost, with no internal billing.
  • Chargeback: actually bill each team's budget.

Two practical points. Tags are not inherited from the resource group to its resources by default, so use an Azure Policy with the modify effect to add or copy required tags. And not every cost can be tagged: shared services such as a firewall or a hub network need an agreed way of splitting the cost.

Common surprise bills

  1. Forgotten resources. Test VMs, unattached disks, unused public IPs, old snapshots. Review the resource list monthly (see Common Azure Mistakes and How to Avoid Them).
  2. Egress. Serving large files straight from storage or moving data between regions adds up. Use a CDN or keep services in one region where possible.
  3. Log ingestion. Verbose debug logging into Log Analytics can cost more than the app. Set a daily cap and sample.
  4. Premium services running idle. A dedicated firewall, a gateway, a Premium cache or a large Kubernetes node pool bills 24 hours a day.
  5. Autoscale without a maximum, or a loop that creates resources (see Scaling and Autoscale).
  6. Expired free credit. When the free trial ends, resources may keep running and be billed to your payment method, or be disabled, depending on the offer.
  7. A leaked credential. Attackers who find a key start crypto-mining VMs in minutes. Budgets with alerts and good secret handling (see Key Vault) are the defense.
  8. Reservations bought for the wrong thing, or for workloads that were later removed.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. A VM is shut down from inside its operating system but not deallocated in Azure. What happens to billing?

    Only a deallocated VM stops compute billing. Disks and public IPs are billed even then.
  2. 2. Which workload is the best fit for Spot VMs?

    Spot capacity is cheap but can be taken back with little notice, so it suits interruptible, restartable work.
  3. 3. What is the difference between a reservation and a savings plan?

    Reservations usually give a slightly bigger discount but are tied to a specific resource type and region. Savings plans trade a little discount for flexibility.
  4. 4. What does an Azure budget do by default when its threshold is crossed?

    Budgets alert; they do not enforce. To act automatically you attach an action group that runs your own automation.
  5. 5. Why use a forecast alert as well as an actual-cost alert?

    An actual-cost alert reports money that is already spent. A forecast alert predicts the overrun earlier.

Summary

  • Bills come from meters: compute time, size, storage, operations, egress, region and always-on extras. Learn the meters of each service you use.
  • Estimate with the Pricing Calculator, check reality with Cost analysis, and let Advisor point out savings.
  • Order of savings: delete unused resources, right-size, schedule non-production, then commit with reservations or savings plans; use Spot only for interruptible work.
  • Budgets alert on actual and forecast cost; they do not stop spending without your automation.
  • Tags make costs attributable for showback and chargeback; enforce them with policy.
  • The usual surprise bills are forgotten resources, egress, log volume, idle premium services and leaked credentials.

Next: The Azure Well-Architected Framework.