What is ransomware? How it works and how to protect yourself
What is ransomware? It's malware that encrypts your files or locks you out of your computer, then demands money (a ransom) to restore access. Security agencies and Microsoft advise against paying. The UK's National Cyber Security Centre (NCSC) says a recent backup kept away from your computer and network is the most effective way to recover.

The short version
- Ransomware is a type of malware. It encrypts your files or locks your device and demands payment, usually in a cryptocurrency such as Bitcoin.
- Attackers often copy data first and threaten to leak it if you don't pay.
- It commonly arrives through email attachments, malicious links and unsafe websites. Attackers increasingly get into organizations through exposed remote access services.
- The NCSC says paying gives no guarantee you'll get your data back.
- Recent offline backups, prompt updates and security software are the main defenses.
What is ransomware?
Microsoft defines ransomware as malware that encrypts your files or stops you from using your computer until you pay money, a ransom, to restore access. The Cybersecurity and Infrastructure Security Agency (CISA) describes it as malware designed to encrypt files on a device, which makes the files and the systems that rely on them unusable. The attackers then demand a ransom in exchange for decryption.
The NCSC says the ransom is usually demanded in a cryptocurrency such as Bitcoin.
Many attacks carry a second threat. CISA says attackers often threaten to sell or leak stolen data if the ransom isn't paid. The NCSC gives the same warning. A good backup won't stop stolen data from being leaked.
Anyone can be hit. Microsoft says ransomware can target any PC, from a home computer to government servers.
How does ransomware work?
The NCSC breaks a ransomware attack into 3 stages:
- Access. Attackers get into your network, take control and plant the encryption software. They may also copy your data.
- Activation. The malware runs, locking devices and encrypting data so you can no longer open it.
- Ransom demand. An on-screen message explains the ransom and how to pay it to regain access to your computer or data.
You often won't know anything is wrong until the last stage. Microsoft says ransomware usually doesn't show itself until you see a demand for money in a window, an app or a full-screen message, and these messages often appear after your files have been encrypted.
Microsoft says ransomware may also spread to other computers or storage devices on the same network. The NCSC cites WannaCry, which affected the UK's National Health Service in May 2017, as an example.
How ransomware gets onto your device
Microsoft lists some of the ways people get infected:
- Visiting unsafe, suspicious or fake websites
- Opening file attachments you weren't expecting or that come from people you don't know
- Opening malicious links in emails, social media posts, instant messages or SMS chats
No More Ransom says an attack is typically delivered through an email attachment and that criminals also plant the malware on websites. These emails work like phishing messages, so the warning signs in our guide to what phishing is apply here too.
Ransomware vs malware: what's the difference?
The NCSC calls ransomware "a type of malware." It says other malware can steal data, take control of devices or mine cryptocurrency. Ransomware is the kind that holds your device or data hostage for payment. The NCSC adds that some malware only poses as ransomware and doesn't decrypt files even after payment. It calls this wiper malware.
Should you pay the ransom?
The NCSC and UK law enforcement say they do not "encourage, endorse nor condone the payment of ransom demands." The NCSC lists what happens if you pay anyway:
- There's no guarantee you'll get access to your data or computer.
- Your computer will still be infected.
- You'll be paying criminal groups.
- You're more likely to be targeted again.
Microsoft gives the same advice: "Don't pay money to recover your files." No More Ransom says paying "is never recommended, mainly because it does not guarantee a solution to the problem."
If you've already paid, Microsoft says to contact your bank and your local authorities right away. If you paid by credit card, your bank may be able to block the transaction and return your money.
What to do if you get ransomware
- Clean the device first. Microsoft says to try fully cleaning your PC with Windows Security before you try to recover your files. In Windows Security, go to Virus & threat protection > Scan options. Save any open files, then choose Microsoft Defender Antivirus (offline scan). It restarts your PC and scans without loading Windows, which Microsoft says makes it harder for persistent malware to hide.
- Look for a free decryptor. The NCSC says files encrypted by most ransomware can't be decrypted by anyone other than the attacker. No More Ransom collects free decryption tools from the main anti-malware vendors. Its Crypto Sheriff tool helps identify which ransomware you have. The project says not every type of ransomware has a solution and that new tools are added when they become available.
- Restore from a backup. The NCSC says to connect backups only to devices you know are clean and to scan backups for malware before restoring, because ransomware may have reached them before it was discovered.
- Report it. In the US, CISA says every ransomware incident should be reported to the government, through the FBI, CISA or the US Secret Service. A victim only needs to report once, and the other agencies are notified. In the UK, the NCSC takes reports at report.ncsc.gov.uk and also encourages reporting to Report Fraud.
Can ransomware affect OneDrive and cloud storage?
Yes. The NCSC warns that cloud services often sync right after your files have been replaced with encrypted copies, so it says to use a service that protects previous versions from being deleted straight away and lets you restore them.
Microsoft's OneDrive has 2 features for this:
- Ransomware detection. When Microsoft 365 detects a ransomware attack, you get a notification on your device and an email. The OneDrive website then walks you through checking your files, cleaning every device that uses OneDrive and restoring. Microsoft says to clean devices first, or restored files could be encrypted again. If you don't subscribe to Microsoft 365, your first notification and recovery is free.
- Restore your OneDrive. Microsoft 365 subscribers can undo all changes to files and folders from the last 30 days. On the OneDrive website, select Settings > Options > Restore your OneDrive (with a work or school account, Settings > Restore OneDrive), then pick a date. After a ransomware detection, a suggested restore date is filled in. Files permanently deleted from the OneDrive Recycle Bin can't be recovered.
How to protect yourself from ransomware
Keep backups that ransomware can't reach
The NCSC calls up-to-date backups the most effective way to recover from a ransomware attack, and it says ransomware actively targets backups to make victims more likely to pay. Its advice:
- Back up your most important files regularly, and check that you know how to restore them.
- Keep an offline copy separate from your computer and network, or in a cloud service designed for backups.
- Use different backup methods and storage locations, not just a single removable drive or a single cloud service.
- Don't leave backup drives, such as external hard drives and USB sticks, permanently connected.
Keep software up to date
Microsoft says to keep your PC up to date with the latest version of Windows and all the latest patches. The NCSC recommends turning on automatic updates for operating systems, apps and firmware where you can. A PC that no longer gets security updates is a bigger risk. Our guide to Windows 10 end of support explains your options.
Turn on Windows Security and Controlled folder access
Microsoft says to keep Windows Security on and, in Windows 10 and Windows 11, to turn on Controlled folder access, which blocks unknown or unsafe apps from changing files in protected folders. By default it covers folders such as Documents, Pictures, Videos, Music and Desktop, and you can add more.
To find it, open the Windows Security app and select Virus & threat protection > Manage ransomware protection. From there you can choose Protected folders or Allow an app through Controlled folder access. Microsoft warns that any app you allow can change files in those folders. If you're deciding whether the built-in protection is enough on an older machine, see our guide to antivirus for old PCs.
Be careful with email, links and downloads
Treat unexpected attachments and links with suspicion, even when a message looks official. Microsoft says fake emails and web pages often have misspelled company names or unusual spacing and punctuation.
Use multi-factor authentication
The NCSC recommends multi-factor authentication (MFA) so that credentials stolen by malware can't easily be reused. Our guide to two-factor authentication shows how to turn it on for Google, Apple and Microsoft accounts.
Ransomware protection for businesses
The NCSC says attackers increasingly deploy ransomware after getting in remotely through exposed services such as Remote Desktop Protocol (RDP) or unpatched remote access devices. Its guidance for organizations recommends these steps, and it points smaller firms to its Small Business Guide.
- Disable RDP if you don't need it, and turn on MFA at every remote access point.
- Patch remote access and internet-facing devices, such as firewalls and VPN products, as soon as updates are available.
- Remove user permissions that are no longer needed, and keep administrator accounts away from email and web browsing.
- Plan for an attack before it happens, including how you'll respond to a ransom demand and a threat to publish your data.
CISA, the FBI, the NSA and the Multi-State Information Sharing and Analysis Center (MS-ISAC) publish a joint #StopRansomware Guide with a response checklist for organizations.
Frequently asked questions
Can ransomware be removed?
Security software such as Windows Security can clean the malware, but that doesn't decrypt your files. The NCSC says most ransomware can only be decrypted by the attacker, so recovery means a backup or a decryptor from No More Ransom.
Can phones get ransomware?
Yes. Microsoft says mobile devices can get ransomware too, and No More Ransom describes ransomware as malware that locks computers and mobile devices or encrypts files.
What is ransomware protection?
It usually means features that stop apps from encrypting your files or help you recover afterward. In Windows, the Ransomware protection page in Windows Security includes Controlled folder access and options for using OneDrive to recover from an attack.
More in Security
- What is a passkey, and how do you use one?
- What is a password manager, and is it safe to use?
- What is a VPN, and how does it work?
- What is phishing? How to spot a phishing email or text
- What is two-factor authentication, and how do you turn it on?