Technology

Virus vs Worm vs Trojan: What's the Difference?

What's the difference between a computer virus, a worm and a Trojan? How each type of malware spreads, famous examples, and how to stay safe.

Published 5 min read
A laptop screen distorted by a malware program
Photo: BrayLockBoy · CC BY-SA 4.0

“My computer has a virus” has become shorthand for any security problem, but cybersecurity experts distinguish between several kinds of malicious software. So what is the difference between a virus, a worm and a Trojan? And why can some spread around the world in hours while others need you to make a mistake first? Here’s a clear explanation.

What is malware?

Malware (short for malicious software) is an umbrella term for any program designed to damage a device or network, steal data, or take control of a system without the owner’s knowledge. Viruses, worms and Trojans are three types of malware, and what separates them is how they get in and how they spread.

What is a computer virus?

A computer virus attaches itself to a legitimate file or program (its host), much as a biological virus needs a cell to live in.

  • It can’t run on its own. It stays dormant until someone opens the infected file or runs the program.
  • It spreads with human help, when infected files are emailed, copied to USB drives or shared online.
  • It can corrupt files, slow the device down or delete data.

What is a computer worm?

A worm is standalone malware. It doesn’t need a host file and usually needs no action from the user at all. Worms exploit weaknesses in operating systems or networks to copy themselves from one machine to the next automatically.

That’s why worms spread fastest: a single infected computer on a company network can infect hundreds of others in a short time, and even a worm with no destructive payload can clog a network with its own traffic.

What is a Trojan horse?

A Trojan is malware disguised as something useful: a free game, a “PC speed booster”, or a pirated copy of a paid app. The name comes from the Greek legend of the wooden horse that hid soldiers inside to get them into the city of Troy.

  • It usually doesn’t replicate the way viruses and worms do.
  • It relies on deception: the user installs it, believing it’s legitimate.
  • It opens a back door: stealing passwords or banking details, giving an attacker remote control, or downloading more malware.

Comparison table

Virus Worm Trojan
Needs a host file? Yes No No (it poses as a program)
Copies itself? Yes Yes, automatically Usually not
Needs user action? Yes (opening the file) Usually not Yes (installing it)
Spreading speed Moderate Very fast Limited
Typical goal Damaging files Spreading and paving the way for other attacks Spying, theft and remote control

Did you know? The Morris worm, released on 2 November 1988, was one of the first worms to spread across the internet. It’s estimated to have infected about 6,000 machines, roughly a tenth of the computers online at the time, and it led to the creation of the first Computer Emergency Response Team (CERT).

Famous examples from history

  • Creeper (1971): one of the first programs to move between computers by itself. It was an experiment rather than an attack and simply displayed a cheeky message.
  • Morris worm (1988): meant to measure the size of the internet, but a programming error made it reinfect machines over and over until they ground to a halt.
  • ILOVEYOU (May 2000): a worm that spread by email disguised as a love letter, reaching millions of users worldwide within days.
  • WannaCry (May 2017): ransomware that spread like a worm through a Windows vulnerability, hitting computers in more than 150 countries. A security update fixing the flaw had been released about a month earlier; unpatched machines were the ones hit.

How to protect your devices

  1. Keep your operating system and apps updated. Most worms exploit old vulnerabilities that already have fixes.
  2. Don’t open unexpected attachments or links, even when they seem to come from someone you know.
  3. Download software only from official sources, and avoid pirated copies and suspicious “free” tools.
  4. Use reputable security software and keep your firewall on.
  5. Back up important files somewhere separate from your device, so you can recover from ransomware.
  6. Turn on two-step verification for important accounts, so a stolen password alone isn’t enough.

Frequently asked questions

Is all malware a virus?

In everyday speech, people often say so. Technically, though, a virus is just one type of malware, alongside worms, Trojans, ransomware, spyware and others.

Can phones get malware too?

Yes. Smartphones are targets too, especially when apps are installed from outside the official stores. Trojans are the most common type on phones.

What is ransomware?

Ransomware encrypts your files and demands payment to unlock them. It can arrive through a worm, a Trojan or an infected email attachment. Security agencies generally advise against paying, since payment doesn’t guarantee you’ll get your files back.

Are Macs and Linux computers completely safe?

No system is completely safe. There is more malware aimed at Windows because it’s so widely used, but macOS and Linux are attacked too, especially internet-facing servers.

Key takeaway

The difference between a virus, a worm and a Trojan comes down to how they spread: a virus rides on a file and waits for you to open it, a worm spreads by itself across networks, and a Trojan tricks you into installing it. The best defence against all three is simple: keep everything updated, be careful with links and attachments, and get software from official sources. As artificial intelligence advances, good security habits matter more every day.

Read next