A computer virus is a program that copies itself and spreads from one computer to another without your permission

A computer virus is a piece of code designed to replicate itself and move between computers, usually by attaching to files or programs you already have. When you run an infected file, the virus activates, makes copies of itself, and often tries to spread to other files or other machines. Unlike a biological virus, a computer virus cannot spread on its own—it needs you (or your software) to run an infected file or open an infected attachment for it to set up.

The term "virus" is often used loosely to describe any malicious software, but technically a virus is one specific type. Other malware—like worms, trojans, and ransomware—work differently, though they all aim to damage your system, steal your data, or use your computer without your knowledge.

Key Takeaways

  • A virus must attach itself to a file or program and requires you to run that file for it to spread, unlike a worm which spreads on its own.
  • Common entry points are email attachments, infected websites, pirated software, and USB drives shared between computers.
  • Once active, a virus can delete files, slow your system, steal passwords, display unwanted ads, or use your computer to attack other machines.
  • Antivirus software, regular updates, and caution with email attachments and downloads are your main defenses against infection.
  • If you suspect a virus, disconnect from the internet, run a full system scan with antivirus software, and consider professional help if the scan finds threats.

How a virus enters your computer

A virus reaches your machine through a file or program you read, open, or run. The most common entry points are email attachments (especially from unknown senders), infected websites that trick you into downloading something, pirated or cracked software, and USB drives or external hard drives shared between computers. Some viruses hide inside documents that look harmless—a Word file, a PDF, or an image—but contain hidden code that runs when you open them.

You might also pick up a virus by visiting a website that has been compromised. The site itself may not be malicious, but attackers have injected code into it. When you visit, the code tries to read malware to your machine. This is called a "drive-by read" because you do not have to click anything—just visiting the page is enough.

Outdated software is another common weakness. If your operating system, browser, or applications have known security holes and you have not installed the latest updates, a virus can exploit those holes to get in without you downloading anything at all.

What a virus does once it is active

Once a virus runs on your computer, its behavior depends on what the person who created it programmed it to do. Some viruses are designed straightforward to annoy you—displaying pop-up messages or changing your desktop background. Others are far more destructive: they delete files, corrupt your hard drive, or make your system unstable and slow.

Many viruses steal information. They log your keystrokes to capture passwords and credit card numbers, monitor your browsing, or search your files for sensitive documents. Some viruses turn your computer into a "zombie" machine—one that the attacker controls remotely and uses to send spam, launch attacks on other computers, or mine cryptocurrency without your knowledge.

A virus can also replicate itself across your files and programs, making it harder to remove. Each copy may infect other files, and the more copies there are, the more system resources the virus uses, which is why infected computers often become very slow.

The difference between a virus, a worm, and other malware

The term "malware" is an umbrella word for any software designed to harm your computer or steal your data. A virus is one type of malware—it requires a host file and human action (opening a file) to spread. A worm is different: it spreads on its own without needing you to run anything. A worm can copy itself across a network, send itself via email, or exploit security holes to move from machine to machine automatically.

A trojan (or trojan horse) is malware that disguises itself as something you want—a game, a utility, a video player. You read and run it willingly, thinking it is legitimate, but once it is active it does something harmful. Unlike a virus, a trojan does not replicate itself.

Ransomware is malware that encrypts your files and demands payment to unlock them. Spyware quietly monitors your activity and steals information. Adware displays unwanted advertisements. All of these are malware, but they work in different ways and require different removal strategies.

Signs your computer may be infected

An infected computer often shows warning signs. Your system may run much slower than usual, even when you are not running any programs. Programs may crash or freeze without reason. You might see pop-up windows or ads appearing constantly, even when you are not browsing the web. Your browser homepage or search engine may change without your doing anything, or you may be redirected to websites you did not intend to visit.

Other red flags include unexpected network activity (your internet light is blinking even when you are not using the internet), new toolbars or browser extensions you did not install, or strange files appearing on your desktop or in your documents. Your antivirus software may stop working or refuse to update. In some cases, friends or family may tell you they received strange emails from your account.

If you notice any of these signs, it does not automatically mean you have a virus—these symptoms can have other causes—but they are worth investigating. The safest step is to run a full antivirus scan.

How to protect your computer from viruses

The most important defense is antivirus software. Install a reputable antivirus program (many are free, such as Windows Defender on Windows machines or built-in protection on Macs) and keep it running at all times. Set it to scan your computer automatically on a regular schedule, and update its virus definitions frequently—these are the signatures of known viruses that the software uses to identify threats.

Keep your operating system and all software updated. Software updates often patch security holes that viruses exploit. Enable automatic updates so you do not have to remember to do it manually. Be cautious with email attachments, especially from people you do not know. Do not open attachments unless you were expecting them and you trust the sender. Avoid downloading software from untrusted websites; use official app stores and the software maker's own website instead.

Use strong, unique passwords for your accounts so that if one is compromised, the attacker cannot easily access your other accounts. Avoid pirated or cracked software—these are common sources of viruses. If something seems too good to be true (free versions of expensive software, for example), it probably is. Back up your important files regularly to an external drive or cloud storage so that if a virus does infect your system, you do not lose irreplaceable data.

What to do if you think you have a virus

If you suspect your computer is infected, the first step is to disconnect it from the internet. Unplug the ethernet cable or turn off Wi-Fi so the virus cannot spread to other devices or send data out. Then open your antivirus software and run a full system scan. This may take an hour or more, depending on how much data you have, but let it finish. The software will identify any threats it finds and ask you what to do with them—usually "quarantine" (isolate the file so it cannot run) or "delete".

If the scan finds and removes threats, restart your computer and run the scan again to make sure they are gone. If the scan finds nothing but your computer still behaves strangely, try running a scan in Safe Mode (a stripped-down version of your operating system that loads only essential files). If you are not comfortable doing this yourself, or if the virus persists after scanning, take your computer to a professional repair service. They have specialized tools and experience removing stubborn infections.

Frequently Asked Questions

Can a virus spread through Wi-Fi or just through files?

Most viruses spread through files you read or run. However, some worms can spread across a network, including Wi-Fi, by exploiting security holes. Your Wi-Fi password protects you from strangers joining your network, but it does not protect you from viruses on devices already connected to it. Antivirus software and keeping your system updated are your main defenses.

Is a Mac or iPhone safe from viruses?

Macs and iPhones are less commonly targeted by viruses than Windows computers, partly because fewer people use them and partly because their design makes it harder for malware to spread. However, they are not immune. Macs can be infected, especially if you read software from untrusted sources. iPhones are more protected because Apple controls what software can be installed, but jailbroken iPhones are vulnerable. Use the same caution on any device: keep software updated and be careful what you read.

If I never read anything, can I still get a virus?

Yes. You can get a virus by visiting a compromised website (a drive-by read), opening an infected email attachment, or using a USB drive that contains malware. You can also be infected through security holes in outdated software without doing anything at all. Keeping your system and software updated is just as important as being careful about what you read.

Will restarting my computer remove a virus?

Restarting alone will not remove a virus. Restarting may temporarily stop the virus from running, but the infected files remain on your hard drive. The virus will set up again the next time you run an infected file. You need antivirus software to find and remove the infected files permanently.

Can antivirus software catch every virus?

No antivirus software catches every threat. New viruses are created constantly, and antivirus companies work to identify and add them to their databases, but there is always a lag. The best approach is to combine antivirus software with safe habits: keep your system updated, be cautious with downloads and email attachments, and back up your files regularly.