Your profile

One profile for every MSDEVBUILD site. Only you can see it, and the site owner if you write in.

Lesson 22 of 47
❮Prev Next❯

Create Virtual Machines and Manage VM Sizes

Module 3: Compute ⏱ 11 min read Updated

Your note

My notes for this lesson

Select any text in the lesson to highlight it or add a note. Saved in this browser.

    No highlights yet. Select a sentence in the lesson, then pick a colour or add a note.

    All my bookmarks and notes

    Reading settings

    For every lesson, saved in this browser.

    Text size
    Line spacing
    Font

    With IaaS you rent the virtual machine. Microsoft looks after the building, power and hardware; you patch the operating system.

    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 needed

    Exam 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.

    Azure portal: Create a virtual machine and change its size Create a VM, then resize it from the Size blade.
    </> Embed

    Embed this simulation

    Free for trainers, teachers and bloggers. Paste this into your page:

    Loading the portal…

    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
    1. Let's build Contoso's app server. Open the search bar.
    2. Type virtual machines in the search bar and pick Virtual machines under Services.
    3. Select + Create › Azure virtual machine.
    4. 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).
    5. On Disks choose the OS disk type. Data disks can be added now or later.
    6. 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.
    7. The VM, its OS disk, NIC, public IP and NSG were created.
    8. 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.

    😟 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
    🛠️ Solved with: VM sizes and resizing

    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:

    FieldWhat to choose
    Subscription, Resource groupWhere it’s billed and managed
    Virtual machine name, RegionName (15 characters max for Windows), region close to users
    Availability optionsNo infrastructure redundancy, Availability zone, Virtual machine scale set or Availability set
    Security typeTrusted launch (default), Standard or Confidential
    ImageUbuntu, Windows Server, RHEL and so on
    SizeFamily, vCPUs, memory and price
    Administrator accountSSH public key or password
    Inbound port rulesNone, 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:

    FamilyBuilt forExample
    BBurstable, mostly idle with short spikesStandard_B2s
    DGeneral purposeStandard_D4s_v5
    EMemory optimised (databases, caches)Standard_E8s_v5
    FCompute optimised (batch, gaming servers)Standard_F8s_v2
    LStorage optimised (high local disk throughput)Standard_L8s_v3
    NGPUStandard_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:

    1. A resize on a running VM restarts it.
    2. 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.
    3. In an availability set, a size that isn’t on the cluster means deallocating all VMs in the set before resizing any of them.
    4. 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

    Wholesale

    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.
    Ready for more?The full lesson adds the technical explanation, when to use it, interview questions and revision notes.

    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.

    Question 1

    Question 1 of 5

    VM1 runs Windows Server and is currently running. In the Size blade, the size Standard_E8s_v5 is unavailable for selection.

    What should you do first so that you can resize VM1 to Standard_E8s_v5?

    Question 2

    Question 2 of 5

    You resize a running virtual machine from Standard_D2s_v5 to Standard_D4s_v5. The new size is available on the current hardware cluster. What is the effect on the virtual machine?

    Question 3

    Question 3 of 5

    A line-of-business application runs an in-memory database that needs a high memory-to-vCPU ratio. You need to choose a VM size family.

    Which family should you choose?

    Question 4

    Question 4 of 5

    You need to create a Linux virtual machine in availability zone 2 by using the Azure CLI. Which command should you run?

    Question 5

    Question 5 of 5

    VM1 is not used outside business hours. Compute charges for VM1 must stop overnight while its disks and configuration are kept.

    What should you do each evening?

    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. 1.Which command lists the sizes a VM can be resized to?Show

      az vm list-vm-resize-options.

    2. 2.Which command resizes a VM?Show

      az vm resize --size <size>.

    3. 3.What happens to a running VM when it's resized?Show

      It restarts.

    4. 4.Which VM family is memory optimised?Show

      E-series.

    5. 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

    Studying with a friend? Send them this lesson

    It's free and needs no sign-up. Their progress saves in their own browser.

    Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges. Play ❯

    Install MSDEVBUILD Azure

    Free · no account · works offline

    Save the whole course for offline ›

    Hi, I’m your Nimbus

    Your study buddy. Pick what we do next.

    MSDEVBUILD · Multi-Stack Dev Build

    Sign in to MSDEVBUILD

    One account for Azure certifications and the blog: sign in here and you are signed in on both. Your XP, streak, practice deck and certificate stay in sync on every device. Optional: everything works without an account.