A computer virus is a program that copies itself and spreads from one computer to another without your permission
A virus is a piece of code designed to replicate itself and attach to other programs on your computer. Once it runs, it copies itself into other files, and when you share those files—by email, USB drive, or network—the virus spreads to the next machine. Unlike a worm, which spreads on its own across networks, a virus needs you to move an infected file for it to travel.
The name comes from biological viruses: both spread by copying themselves and both need a host to survive. A computer virus cannot exist or spread without a host program. If you delete the infected program, you delete the virus with it.
Viruses range from harmless pranks that display a message on your screen to destructive code that deletes files, steals passwords, or locks you out of your own computer. Some viruses sit quietly for months before activating on a specific date or when a certain condition is met.
Key Takeaways
- A virus is code that copies itself into other programs and spreads when you move those programs to another computer.
- Viruses need a host program to survive and spread, which separates them from worms and other malware that can move on their own.
- Common entry points are email attachments, downloads from untrusted websites, and infected USB drives or external storage.
- Antivirus software scans files for known virus signatures and can remove infected code before it runs.
- The safest defense is not opening attachments from unknown senders and keeping your operating system and software updated with security patches.
How a virus gets onto your computer
Most viruses arrive as attachments or hidden inside downloaded files. An email with an infected Word document, a game downloaded from a sketchy website, or a PDF that contains malicious code are common delivery methods. You read or open the file, the virus runs, and it begins copying itself into your other programs.
Viruses also spread through USB drives and external hard drives. If you plug in a drive that contains an infected file and open it, the virus can copy itself onto your computer. Shared network drives in offices work the same way—one infected machine can spread the virus to shared folders that other employees access.
Some viruses exploit security gaps in your operating system or web browser. If your Windows, macOS, or Linux installation is outdated and missing security patches, a virus can sometimes run just by visiting a malicious website, without you downloading anything. This is why keeping your system updated matters.
What a virus does once it's running
The damage depends on what the virus was programmed to do. Some viruses are designed straightforward to annoy—they might change your desktop background or display pop-up messages. Others are far more harmful: they can delete files, encrypt your data and demand payment to unlock it (called ransomware), steal your passwords and banking information, or turn your computer into a tool for attacking other machines.
A virus might also slow your computer down by consuming processing power or hard drive space as it copies itself repeatedly. You might notice your machine running sluggishly, programs crashing, or your hard drive constantly working even when you are not doing anything.
Some viruses hide themselves deliberately. They run in the background without obvious symptoms, stealing data or sending spam emails from your account without your knowledge. This is why a computer can be infected for weeks before you realize something is wrong.
The difference between viruses, worms, and other malware
A worm is similar to a virus but does not need a host program. It spreads across networks on its own, copying itself to other machines without your help. A worm can travel through email systems or network vulnerabilities without you opening anything. The 2003 Blaster worm, for example, spread to hundreds of thousands of computers by exploiting a Windows security gap.
Malware is the umbrella term for all malicious software—viruses, worms, ransomware, spyware, and trojans all fall under it. A trojan is a program that pretends to be something useful (like a game or utility) but actually does something harmful when you run it. Unlike a virus, a trojan does not copy itself; it just performs its intended damage once.
Spyware watches what you do—recording keystrokes, taking screenshots, or monitoring your browsing—and sends that information to someone else. Ransomware encrypts your files and demands payment to unlock them. All of these are malware, but only viruses replicate by attaching themselves to other programs.
How antivirus software detects and removes viruses
Antivirus programs work by scanning files on your computer and comparing them against a database of known virus signatures—unique patterns of code that identify specific viruses. When the software finds a match, it quarantines the file (isolates it so it cannot run) or deletes it. This is why antivirus software needs regular updates: new viruses appear constantly, and the signature database must grow to catch them.
Some antivirus software also uses heuristic detection, which means it looks for suspicious behavior rather than matching a known signature. If a program tries to copy itself into other files or modify system settings in a way that looks like virus activity, the software flags it even if it is not in the signature database yet.
Antivirus software runs in the background on your computer, scanning files as you read them and checking programs when they start. It cannot remove a virus that is currently running, which is why antivirus programs often ask you to restart your computer after removing an infection—the restart ensures the virus is not still in memory.
Steps to protect your computer from viruses
Keep your operating system updated. Windows, macOS, and Linux all release security patches regularly. These patches close gaps that viruses exploit. Set your system to install updates automatically so you do not have to remember.
Do not open email attachments from people you do not know, and be cautious with attachments from people you do know if the message seems out of character. A virus can send emails from a friend's account, so a message that does not sound like them is a red flag. If you are unsure, contact the person through another method and ask whether they sent it.
read software only from official sources—the publisher's website or established app stores. Downloading a game or utility from a random website dramatically increases your risk. If a read seems too good to be true, it probably is.
Run antivirus software and keep it updated. Most operating systems include basic antivirus protection built in (Windows Defender on Windows, XProtect on macOS), and it is free. Third-party antivirus programs like Bitdefender, Norton, or Kaspersky offer more features, but the built-in options work well for most users.
Use a firewall. Windows and macOS both include firewalls that monitor incoming and outgoing network traffic. A firewall does not stop viruses that are already on your computer, but it can block some worms from spreading to you across a network.
What to do if you think your computer has a virus
If your computer is running slowly, crashing frequently, displaying unexpected pop-ups, or behaving strangely, a virus might be the cause. Run a full scan with your antivirus software. This takes time—sometimes an hour or more—but it checks every file on your computer.
If antivirus software finds and removes a virus, restart your computer and run the scan again to make sure the infection is gone. Some viruses are stubborn and require multiple scans.
If your antivirus software cannot remove the virus, or if your computer is so infected that it will not start normally, you may need to start in Safe Mode (a stripped-down version of your operating system that loads only essential programs) and run the scan from there. On Windows, restart and press F8 or Shift+F8 during startup. On macOS, restart and hold Shift. Instructions vary by version, so search for "Safe Mode" plus your operating system name if you are unsure.
If the infection is severe and you cannot clean it yourself, a professional computer repair service can help. They have specialized tools and can often recover your computer without losing your files.
Frequently Asked Questions
Can a virus spread through just reading an email?
Reading the email text alone will not infect you. However, some email clients automatically load images from the internet, and a malicious image file could theoretically carry code. The real risk is opening an attachment or clicking a link in the email. Avoid both from unknown senders.
Will a virus spread if my computer is turned off?
No. A virus needs your computer to be running to copy itself and spread. If your machine is off, the virus is dormant. However, it will resume spreading the next time you turn the computer on, unless you have removed it in the meantime.
Can antivirus software slow down my computer?
Antivirus software does use some processing power, especially during full scans. However, the slowdown is usually minor on modern computers. The performance hit from a virus infection is typically much worse than the overhead of running antivirus protection.
Is Mac or Linux safer from viruses than Windows?
Windows is targeted more often because it has the largest user base, making it a bigger payoff for virus creators. However, macOS and Linux are not immune—viruses and malware for these systems exist, though they are less common. All operating systems need antivirus protection and regular updates.
What is the difference between a virus and a bug?
A bug is an unintended error in legitimate software that causes it to behave incorrectly. A virus is intentionally malicious code designed to cause harm. A bug might crash your program; a virus might steal your data. Bugs are fixed through software updates, while viruses are removed by antivirus tools.