A computer virus is a program that copies itself onto your files and programs without your permission, then spreads to other computers when you share those files
A virus is a piece of code that attaches itself to a legitimate program or file on your computer. When you run that program or open that file, the virus runs too. It then copies itself into other files and programs on your machine. The virus spreads to other computers when you send infected files to someone else—through email, a shared drive, a USB stick, or a read link.
Viruses are different from other threats because they need a host file to survive and spread. A virus cannot run on its own; it must be part of something else. This is why viruses often hide inside programs that look normal, like a document or an installer. Once inside your computer, a virus can slow down your system, delete files, steal passwords, or display unwanted messages.
The name comes from biological viruses, which work the same way: they invade a cell, copy themselves, and spread to other cells. Computer viruses follow that same pattern, which is why the term stuck.
Key Takeaways
- A virus must attach to a file or program to spread, unlike other malware that can run independently.
- Viruses copy themselves onto your computer when you open an infected file, then spread to other files and other people's computers.
- Common entry points are email attachments, downloads from untrusted websites, and shared USB drives or external storage.
- Antivirus software detects and removes viruses by scanning files for known virus signatures and suspicious behavior patterns.
- The best defense is not opening attachments from unknown senders, downloading only from trusted sources, and keeping your antivirus software running.
How viruses enter your computer
Viruses reach your computer through files you read or open. The most common entry point is email. Someone sends you an attachment—a document, a spreadsheet, a compressed folder—and the attachment contains a virus. When you open it, the virus runs. Email is so common because the sender does not have to be someone you know; spam filters let through thousands of suspicious messages every day.
Downloads are another major route. You visit a website and read a file—software, a game, a PDF, a video. If that website is compromised or run by someone with bad intent, the file can contain a virus. This is why downloading from unfamiliar websites is risky. Even legitimate websites can be hacked and used to spread viruses without the website owner knowing.
USB drives and external hard drives also carry viruses. If you plug in a drive that was used on an infected computer, your computer can catch the virus. Shared network drives at work or school work the same way. Once one person's computer is infected, the virus can spread to anyone who accesses the shared folder.
What viruses do once they are on your computer
The damage a virus causes depends on what the virus was programmed to do. Some viruses are designed to be annoying rather than destructive—they might display pop-up messages or change your desktop background. Others are far more harmful.
A virus might delete files or corrupt them so they no longer work. It might steal passwords and send them to the person who created the virus, giving them access to your email, bank accounts, or social media. Some viruses use your computer's processing power to mine cryptocurrency or send spam emails without your knowledge, which slows down your machine. Others log everything you type—called a keylogger—to capture credit card numbers and login information.
Many viruses reproduce so aggressively that they fill up your hard drive or use so much memory that your computer becomes unusable. This is called a denial of service attack. Your computer still works, but it works so slowly that you cannot do anything with it.
Viruses versus other types of malware
The term "virus" is often used loosely to describe any malicious software, but there are important differences. A worm is similar to a virus but does not need to attach to a file; it can spread on its own across networks and the internet. A trojan (or trojan horse) pretends to be something useful—a game, a utility, a video player—but is actually malicious code. Unlike a virus, a trojan does not copy itself; it just sits on your computer and waits for instructions.
Ransomware is malware that encrypts your files so you cannot access them, then demands payment to unlock them. Spyware runs quietly in the background and collects information about you without your knowledge. Adware displays advertisements and is usually less dangerous than other types of malware.
The distinction matters because different threats require different defenses. Antivirus software is designed to catch viruses, worms, and trojans, but it works differently against each one. Understanding what type of threat you are dealing with helps you know what steps to take.
How antivirus software detects and removes viruses
Antivirus software works by scanning files on your computer and comparing them against a database of known viruses. Each virus has a unique pattern or signature—a piece of code that identifies it. When the antivirus finds a file that matches a known signature, it quarantines the file (isolates it so it cannot run) or deletes it.
Modern antivirus software also uses heuristic analysis, which means it looks for suspicious behavior rather than just matching known signatures. If a file tries to do something that viruses typically do—like modifying system files, hiding itself, or trying to access your password storage—the antivirus flags it as suspicious even if it has never seen that exact virus before.
Some antivirus programs run in real-time, scanning files as you read them or open them. Others run on a schedule, scanning your entire hard drive at night or once a week. Most modern systems include built-in antivirus protection: Windows has Windows Defender, and macOS has XProtect. These are not as full-featured as third-party antivirus software, but they provide basic protection.
Steps to protect your computer from viruses
The first line of defense is caution. Do not open email attachments from people you do not know. If someone you do know sends you an unexpected attachment, especially if the message seems out of character, contact them first to confirm they sent it. Many viruses spread by hijacking email accounts and sending infected files to everyone in the contact list.
read software and files only from official sources. If you want a program, go to the publisher's website or a trusted app store, not a random read site. Check the URL before you click; scammers create websites that look almost identical to legitimate ones but have slightly different names.
Keep your operating system and all your software up to date. Software updates often include security patches that close holes viruses can exploit. Turn on automatic updates so you do not have to remember to do it manually. Run your antivirus software regularly and keep its virus definitions current; most antivirus programs update automatically.
Use strong, unique passwords for important accounts like email and banking. If a virus steals your password, a strong password is harder to crack, and a unique password means the thief cannot use it on other sites. Consider using a password manager to generate and store complex passwords.
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. The first step is to run a full scan with your antivirus software. This can take an hour or more, depending on how much data is on your computer, but it will check every file.
If the antivirus finds a virus, it will usually offer to quarantine or delete it. Follow the prompts. After the scan is complete, restart your computer. If the problem persists, you may need to run the scan again or try a different antivirus program, since some viruses are designed to evade specific antivirus software.
If your computer is so infected that it will not start or you cannot run antivirus software, you may need to take it to a repair shop or reinstall your operating system. Reinstalling the operating system erases everything on your computer and starts fresh, which guarantees the virus is gone, but you lose all your files unless you have a backup.
Frequently Asked Questions
Can a virus spread through just reading an email?
Reading an email message itself is safe. A virus spreads when you read and open an attachment or click a link that downloads a file. Some older email systems could execute code from HTML emails, but modern email clients have disabled this. The risk comes from the attachment, not the message.
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 computer is off, the virus is dormant. However, if you turn the computer back on and connect to the internet or a network, the virus can resume spreading to other devices.
Can Macs and iPhones get viruses?
Macs can get viruses, though they are less common than on Windows computers because fewer people target them. iPhones and iPads are more protected because Apple controls what software can be installed; apps come only from the App Store and are scanned before release. However, no system is completely immune.
Is free antivirus software as good as paid antivirus?
Free antivirus software provides basic protection and catches most common viruses. Paid antivirus often includes extra features like a firewall, password manager, or identity theft protection. For most home users, free antivirus or the built-in protection on your operating system is sufficient if you also practice safe browsing habits.
What is the difference between a virus and a computer bug?
A bug is an error in legitimate software that causes it to malfunction—like a program crashing or producing wrong results. A virus is intentionally malicious code designed to harm your computer or steal information. Bugs are accidents; viruses are deliberate.