Create Virtual Machines and Manage VM Sizes
30-second answer
You create a VM in the portal (Virtual machines › + Create), with az vm create or with New-AzVM, choosing the region, availability options, image, size, admin account and inbound ports. The size sets vCPUs, memory, maximum data disks and price; the name tells you the family, such as D for general purpose, E for memory optimised and F for compute optimised. Resizing restarts the VM. If the new size isn't available on the hardware cluster hosting the VM, deallocate it first and every size in the region becomes available.
Simulate it » No Azure account neededExam objective: 3.2.1 Create a virtual machine. 3.2.4 Manage virtual machine sizes. (Skills measured as of April 17, 2026)
Simulations
Feel it before you read it. No account needed, nothing leaves this page.
Let's build Contoso's app server. Open the <strong>search</strong> bar.
👆 Click the glowing item in the portal to continue
Read the steps as text
- Let's build Contoso's app server. Open the search bar.
- Type virtual machines in the search bar and pick Virtual machines under Services.
- Select + Create › Azure virtual machine.
- On Basics pick the region, availability, security type, image and size. The size name tells you a lot: D family (general purpose), 2 vCPUs, s (premium storage capable), v5 (generation).
- On Disks choose the OS disk type. Data disks can be added now or later.
- Review and Create. CLI: az vm create -g rg-contoso-prod -n vm-app-01 --image Ubuntu2404 --size Standard_D2s_v5 --zone 1 --generate-ssh-keys.
- The VM, its OS disk, NIC, public IP and NSG were created.
- Under Availability + scale › Size, pick D4s_v5 and select Resize. The VM restarts. If the size you want is greyed out, Stop (deallocate) the VM first. CLI: az vm resize --size Standard_D4s_v5.
🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.
🖱️ Drag to rotate · scroll or pinch to zoom
A VM, its host and its size
A VM runs on a physical host in a hardware cluster. Its size (Standard_D2s_v5: D family, 2 vCPUs, premium storage, v5) sets CPU, memory, disk count and price. A resize restarts the VM; a size that isn't on the current cluster needs the VM deallocated first.
🤔 What happens if…
Read this tour as text
- A Bicep file becomes resources. A template has four parts: parameters (inputs such as
storageNameandskuName), variables (values worked out once), resources (what gets built) and outputs (values handed back). The CLI compiles Bicep to ARM JSON and Azure Resource Manager validates it, then builds it. - what-if, Incremental and Complete. what-if previews the changes (
+create,~modify,-delete) without touching anything. Incremental mode, the default, adds and updates. Complete mode also deletes whatever in the resource group isn't in the template. - Export and decompile. Export template (portal, or
az group export) writes what exists now as ARM JSON.az bicep decompileturns JSON into Bicep. Both are starting points: names and values are hard-coded and some properties are missing. - A VM, its host and its size. A VM runs on a physical host in a hardware cluster. Its size (Standard_D2s_v5: D family, 2 vCPUs, premium storage, v5) sets CPU, memory, disk count and price. A resize restarts the VM; a size that isn't on the current cluster needs the VM deallocated first.
- Disks and encryption at host. OS and data disks are managed disks in Azure Storage, encrypted at rest by default. The temp disk and the disk caches live on the host. Encryption at host encrypts those too, end to end; it needs the feature registered and the VM deallocated.
- Move to another resource group or subscription. A move keeps the region and the VM keeps running, but every resource ID changes. The VM must travel with its disks and network interface; across subscriptions the virtual network goes too.
- Move to another region. Azure Resource Mover copies resources to another region: add them, validate dependencies, prepare, initiate move, then commit (or discard) and delete the source.
- Availability sets vs zones. An availability set spreads VMs over fault domains (racks with their own power and network) and update domains in one datacenter: 99.95%. Availability zones spread VMs over separate datacenters: 99.99%. A VM uses one or the other, chosen at creation.
- Scale sets grow on a rule. A Virtual Machine Scale Set (Flexible orchestration recommended) runs identical VMs across zones. Autoscale rules add instances when average CPU is high and remove them when it's low, always between the minimum and maximum.
Build Contoso's app server, then do the jobs an admin gets every week: a bigger size, a data disk, encryption at host and a cheaper disk tier. Some of these need the VM deallocated, and the shell will tell you when you forget.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 THE PROBLEM
The reporting VM runs out of memory every month-end.
😊 THE SOLUTION
Resize it to a memory-optimised size in a short maintenance window.
- Undersized VM✓ Resize to the E family
- Size greyed out✓ Deallocate, then resize
- Oversized VM✓ Resize down and save
Start with a question
What if your laptop could get more memory just by restarting it?
Your laptop’s memory is soldered in. To get more, you buy a new laptop and copy everything across.
An Azure VM doesn’t work like that. Its size is a setting. Pick a bigger one, the VM restarts, and it comes back with more CPU and memory, same disks, same name. The catch: sometimes the size you want isn’t on the hardware your VM sits on, and then you have to deallocate it first so Azure can start it somewhere else.
Explain it like I’m 10
The technical explanation
Creating a VM
Virtual machines › + Create › Azure virtual machine opens a wizard with tabs Basics, Disks, Networking, Management, Monitoring, Advanced, Tags, Review + create. The Basics tab is where most exam questions live:
| Field | What to choose |
|---|---|
| Subscription, Resource group | Where it’s billed and managed |
| Virtual machine name, Region | Name (15 characters max for Windows), region close to users |
| Availability options | No infrastructure redundancy, Availability zone, Virtual machine scale set or Availability set |
| Security type | Trusted launch (default), Standard or Confidential |
| Image | Ubuntu, Windows Server, RHEL and so on |
| Size | Family, vCPUs, memory and price |
| Administrator account | SSH public key or password |
| Inbound port rules | None, or selected ports such as SSH (22), RDP (3389), HTTP (80) |
Creating the VM also creates an OS disk, a network interface, usually a public IP and an NSG, and a virtual network if you don’t pick one.
az vm create -g rg-contoso-prod -n vm-app-01 --image Ubuntu2404 \
--size Standard_D2s_v5 --zone 1 --admin-username azureuser --generate-ssh-keys
New-AzVM -ResourceGroupName rg-contoso-prod -Name vm-app-01 -Location eastus `
-Image Ubuntu2204 -Size Standard_D2s_v5 -Zone 1 -Credential (Get-Credential)
Reading a size name
Standard_D4ds_v5 breaks down as family D, 4 vCPUs, d (local temp disk), s (Premium SSD capable), version v5. Common families:
| Family | Built for | Example |
|---|---|---|
| B | Burstable, mostly idle with short spikes | Standard_B2s |
| D | General purpose | Standard_D4s_v5 |
| E | Memory optimised (databases, caches) | Standard_E8s_v5 |
| F | Compute optimised (batch, gaming servers) | Standard_F8s_v2 |
| L | Storage optimised (high local disk throughput) | Standard_L8s_v3 |
| N | GPU | Standard_NC6s_v3 |
The size also caps the number of data disks and the disk IOPS a VM can push, so a bigger disk on a small VM can still be slow.
Resizing
Portal: VM › Availability + scale › Size, pick a size, Resize. CLI and PowerShell:
az vm list-vm-resize-options -g rg-contoso-prod -n vm-app-01 -o table
az vm resize -g rg-contoso-prod -n vm-app-01 --size Standard_D4s_v5
$vm = Get-AzVM -ResourceGroupName rg-contoso-prod -Name vm-app-01
$vm.HardwareProfile.VmSize = 'Standard_D4s_v5'
Update-AzVM -VM $vm -ResourceGroupName rg-contoso-prod
The rules to remember:
- A resize on a running VM restarts it.
- If the size isn’t offered on the VM’s current hardware cluster, it’s greyed out (or the command fails). Deallocate the VM and every size in the region becomes available.
- In an availability set, a size that isn’t on the cluster means deallocating all VMs in the set before resizing any of them.
- The new size must support what the VM uses: enough data disk slots, Premium storage if its disks are Premium, and the same VM generation.
Architect level Sizes, quotas and policy
Every subscription has vCPU quotas per region and per family. A resize or a create that would go over fails with a quota error; request more under Subscriptions › Usage + quotas. Azure Policy’s Allowed virtual machine size SKUs definition can deny sizes your company doesn’t want, and it applies to resizes too. Azure Advisor flags VMs with low CPU use and suggests a smaller size, which is often the easiest saving on an AZ-104 cost question.
Real-world business scenario
Northwind Traders (fictional)
- The problem
- The SQL reporting VM on Standard_D4s_v5 ran out of memory during month-end close, and the E-series size the team wanted was greyed out in the portal.
- What they used
- They scheduled a 15-minute window, stopped the VM from the portal (deallocated), resized it to Standard_E8s_v5 and started it again. A policy now limits the subscription to approved D and E sizes.
- Why that choice
- Deallocating released the VM from its cluster, so the memory-optimised size became available, and the disks and IP configuration stayed the same.
- The result
- Month-end reports finish overnight again, and the cost went up only for the one VM that needed it.
When to use it and when not to
✓ Use it when…
- You need full control of the OS, such as legacy apps, agents or custom software.
- A workload outgrows its VM and a short restart is acceptable.
- You want to cut cost by moving an underused VM to a smaller size.
✕ Think twice when…
- A web app or API that App Service or Container Apps could run with less admin work.
- Load that changes hour to hour. Scale out with a scale set instead of resizing up and down.
↔ Alternatives to consider
- Virtual Machine Scale Sets to add VMs instead of making one bigger.
- App Service for web apps without OS management.
- Azure Advisor to find VMs that are bigger than they need to be.
Test yourself with exercises
5 original practice questions in the AZ-104 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.
Interview preparation
Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.
Beginner What does Standard_D4s_v5 tell you?
Model answer
D is the general-purpose family, 4 is the number of vCPUs, the s means it can use Premium SSD disks, and v5 is the generation. Other letters you'll see are a for AMD, d for a local temp disk, and p for Arm.
Intermediate A size you want is greyed out on a running VM. Why, and what do you do?
Model answer
The VM's current hardware cluster doesn't offer that size. I'd plan a short window, stop the VM from the portal so it's deallocated, then resize. Once it's deallocated every size in the region is available, and it starts on a host that has it.
Experienced developer What's the difference between stopping a VM from inside Windows and stopping it in the portal?
Model answer
Shutting down inside the OS, or az vm stop, leaves the VM Stopped but still allocated, so we keep paying for compute. Stop in the portal, or az vm deallocate, releases the host and compute billing stops. Disks are billed either way, and a dynamic public IP can change after a deallocation.
Scenario A reporting VM runs out of memory every month-end but is idle the rest of the time. What would you suggest?
Model answer
Resize it to a memory-optimised E-series size for the busy days, or move it to a larger size permanently if the window is short anyway. If the workload is really bursty, a B-series burstable size or a scheduled resize with automation could save money. Either way, it's a restart, so I'd schedule it.
Quick revision
Key points
- Create with the portal wizard, az vm create or New-AzVM. Basics holds region, availability, image, size and admin account.
- Size names show family, vCPUs, features and generation (Standard_D4s_v5).
- Resizing restarts the VM. Sizes not on the current cluster need the VM deallocated first.
- In an availability set, a size not on the cluster can mean deallocating every VM in the set.
- Deallocated VMs aren't billed for compute; stopped-but-allocated VMs are.
Important terminology
- VM size
- The hardware profile of a VM, such as Standard_D2s_v5, setting vCPUs, memory, temp storage, data disk limits and price.
- VM family
- A group of sizes for one kind of work, such as B (burstable), D (general purpose), E (memory optimised), F (compute optimised), L (storage) and N (GPU).
- Deallocate
- Stopping a VM so it's released from its host. Compute billing stops and the VM can restart on different hardware.
- Stopped (allocated)
- The state after shutting down from inside the OS or az vm stop. The VM keeps its host and is still billed for compute.
- Hardware cluster
- The group of hosts a running VM is placed on. Only sizes that cluster supports can be chosen without deallocating.
- Trusted launch
- The default security type for new Gen2 VMs, adding Secure Boot and a virtual TPM.
Common mistakes
- Shutting down from inside the OS and expecting billing to stop.
- Expecting a resize to happen with no restart.
Exam tips
- "Size is greyed out / not available" = deallocate the VM, then resize.
- "More memory for a database server" = E-series; "CPU-heavy batch" = F-series; "GPU" = N-series.
- "Stop paying for compute" = Stop (deallocate), not shutdown from the OS.
Five quick revision questions
-
1.Which command lists the sizes a VM can be resized to?Show
az vm list-vm-resize-options.
-
2.Which command resizes a VM?Show
az vm resize --size <size>.
-
3.What happens to a running VM when it's resized?Show
It restarts.
-
4.Which VM family is memory optimised?Show
E-series.
-
5.Which power state stops compute billing?Show
Stopped (deallocated).
Official references
Finished this lesson? Tick it off. Your progress is saved in this browser.
Next up: VM Disks and Encryption at Host
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.