A computer virus is a program that copies itself and spreads from one device to another, usually by attaching to files or programs you read or open
A virus is not a living thing — it is a piece of code written by someone to cause problems. It works like a biological virus in one way: it makes copies of itself and moves from one computer to the next. Unlike a biological virus, it cannot spread on its own. It needs you to do something — open an email attachment, read a file, click a link — to move to your machine.
Once a virus lands on your computer, it can do different things depending on what the person who wrote it programmed it to do. It might slow your machine down, steal passwords, delete files, display unwanted messages, or use your computer to attack other computers without your knowledge. The damage ranges from annoying to serious.
The key difference between a virus and other types of malicious code is that a virus specifically copies itself and spreads. Other harmful programs — called malware, spyware, trojans, and ransomware — work differently and cause different kinds of harm, but they are not viruses in the strict sense.
Key Takeaways
- A virus is code that copies itself and spreads when you open infected files or read from unsafe sources.
- Viruses need your action to spread — they cannot move between computers on their own.
- Different viruses cause different damage: some slow your machine, some steal data, some delete files, and some use your computer to attack others.
- Email attachments, downloads from untrusted websites, and USB drives are the most common ways viruses reach your computer.
- Antivirus software, keeping your operating system updated, and avoiding suspicious files are your main defenses.
How a Virus Spreads From One Computer to Another
A virus spreads when you perform an action that runs the infected code. The most common routes are email attachments, downloads, and removable storage like USB drives. If someone sends you an email with an attachment that contains a virus, opening that attachment runs the code. If you read a file from a website that hosts malicious code, the virus lands on your machine the moment the read finishes.
Once the virus is on your computer, it looks for ways to copy itself to other machines. It might attach itself to files you send to others, hide inside programs you read and share, or use your email contacts to send itself out automatically. Some viruses spread across a local network if your computer is connected to one — for example, in an office or school.
The speed of spread depends on the virus. Some spread slowly and stay hidden for months. Others spread rapidly and cause noticeable damage within days. The longer a virus goes undetected, the more machines it can reach and the more damage it can do.
Common Types of Viruses and What They Do
A boot sector virus infects the part of your hard drive that starts up your computer. It runs before your operating system loads, which makes it hard to remove. These are less common now because modern computers have protections against them.
A file virus attaches itself to program files or documents. When you open the infected file, the virus runs and makes copies of itself. It might attach to .exe files (Windows programs), Word documents, or PDF files. File viruses are one of the most common types.
A macro virus hides inside the macros — automated instructions — in documents like Word files or Excel spreadsheets. When you open the document and enable macros, the virus runs. These viruses often spread through email attachments.
A polymorphic virus changes its code each time it copies itself, which makes it harder for antivirus software to recognize and remove. It is like a criminal who changes their appearance to avoid being caught.
The Difference Between Viruses and Other Malware
The term "malware" is broader than "virus." Malware means any malicious software — anything written to harm your computer or steal your data. All viruses are malware, but not all malware is a virus.
A trojan (or trojan horse) pretends to be something useful — a game, a tool, a video player — but does harmful things once you run it. Unlike a virus, it does not copy itself. You have to read and run it yourself.
Spyware watches what you do on your computer — the websites you visit, the passwords you type, the files you open — and sends that information to someone else. It does not copy itself like a virus does.
Ransomware locks your files or your entire computer and demands money to unlock them. It usually arrives as a trojan or through a phishing email, not by copying itself like a virus.
Worms are similar to viruses in that they copy themselves, but they spread across networks without needing you to open a file. They can move from computer to computer on their own once they are on a network.
How Antivirus Software Detects and Removes Viruses
Antivirus software works in two main ways. Signature-based detection looks for known virus code — like a fingerprint database. When you read or open a file, the antivirus compares it to a database of known viruses. If it finds a match, it blocks or removes the file. This method works well for viruses that have been around for a while and are already documented.
Heuristic detection looks for suspicious behavior instead of matching known code. If a program tries to do something that viruses typically do — like modifying system files, hiding itself, or sending data to the internet without permission — the antivirus flags it as potentially dangerous. This method can catch new viruses that have not been seen before.
Most antivirus programs use both methods. They also run scans on a schedule or when you ask them to, checking every file on your computer for known viruses. Real-time protection watches files as you read or open them and stops anything suspicious before it runs.
Steps to Protect Your Computer From Viruses
Keep your operating system and all programs updated. Updates patch security holes that viruses exploit. Windows, macOS, and Linux all release updates regularly. Turn on automatic updates so you do not have to remember to do it manually.
Use antivirus software and keep it updated. The antivirus database needs to be current to recognize new viruses. Most antivirus programs update their virus definitions automatically, sometimes multiple times per day.
Be cautious with email attachments and downloads. Do not open attachments from people you do not know. Do not read files from websites that look suspicious or that you found through a random link. If a read seems too good to be true — a free copy of expensive software, for example — it probably is.
Avoid clicking links in emails or messages from people you do not know. These links often lead to websites that host viruses or trick you into downloading malware. If an email claims to be from your bank or a service you use, go to the official website directly instead of clicking the link in the email.
Use a firewall. Windows and macOS both have built-in firewalls that monitor incoming and outgoing network traffic. A firewall blocks unauthorized access to your computer and can prevent some viruses from spreading to other machines on your network.
What to Do If You Think Your Computer Has a Virus
If your computer is running slowly, crashing often, showing pop-up ads you did not click, or behaving strangely, a virus might be the cause. Other signs include programs opening on their own, your antivirus software being disabled, or files disappearing.
Run a full scan with your antivirus software. Most antivirus programs have a "full scan" or "deep scan" option that checks every file on your computer. This can take an hour or more, but it is thorough. If the antivirus finds something, follow its instructions to remove or quarantine the threat.
If your antivirus software is disabled or will not run, restart your computer in Safe Mode — a limited version of your operating system that loads only essential programs. In Safe Mode, viruses often cannot run, which gives your antivirus a better chance to work. On Windows, restart and press F8 or Shift+F8 during startup. On macOS, restart and hold Shift.
If the virus has caused serious damage or your antivirus cannot remove it, you may need to back up your important files and reinstall your operating system. This erases everything on your computer and starts fresh, which removes any virus. Before you do this, back up files you want to keep to an external drive or cloud storage.
Frequently Asked Questions
Can a virus spread through WiFi without me doing anything?
A virus itself cannot spread through WiFi on its own — you have to run the infected code. However, a worm (which is similar to a virus) can spread across a network without your action. Also, if you are on the same WiFi network as an infected computer, someone could potentially use that connection to attack your machine, but this requires technical skill and is less common than viruses spread through downloads and email.
Can my phone get a computer virus?
Phones run different operating systems than computers — iOS on iPhones and Android on most other phones. Viruses written for Windows or macOS cannot run on a phone. However, phones can be infected with malware designed for mobile devices. The protection is similar: read only from official app stores, keep your phone updated, and be cautious with links and attachments.
Is it safe to use antivirus software from a company I have never heard of?
Stick with established antivirus companies like Windows Defender (built into Windows), Malwarebytes, Kaspersky, Norton, or McAfee. Unknown antivirus programs might themselves be malware — fake antivirus software that pretends to protect you while actually stealing data or installing other threats. Free antivirus from reputable companies is safer than paid antivirus from unknown sources.
If I delete an infected file, is the virus gone?
Deleting a file that contains a virus removes that copy, but the virus might have already copied itself to other files or locations on your computer. That is why running a full antivirus scan is important — it finds and removes all copies, not just the one you deleted. straightforward deleting one infected file is usually not enough.
Can a virus survive if I restart my computer?
Most viruses survive a restart because they are stored on your hard drive. Restarting does not erase the hard drive — it just stops running programs temporarily. Some viruses are designed to run automatically when your computer starts up, so they come back after a restart. This is why antivirus software and operating system updates are necessary to actually remove a virus, not just stop it temporarily.