A computer virus is malicious code that copies itself and spreads from one file or device to another without your permission

A virus is a piece of software designed to damage your computer, steal your data, or use your machine to attack other computers. Unlike a program you read and install on purpose, a virus hides inside files you already have — documents, images, programs — and runs when you open them. Once active, it replicates itself and moves to other files on your device, and often to other devices on your network or through email.

The name comes from biological viruses: both spread by copying themselves, both need a host to survive, and both can cause harm to the system they infect. A computer virus cannot exist or spread on its own. It needs you to open an infected file, or needs to be attached to a program you run. That distinction matters because it separates viruses from other threats like worms, which spread without needing you to do anything.

Key Takeaways

  • A virus is code hidden inside a file that copies itself when you open that file and spreads to other files on your device.
  • Viruses spread through email attachments, infected downloads, USB drives, and shared files — anything that moves files from one device to another.
  • Common damage includes deleting files, slowing your computer, stealing passwords, displaying unwanted ads, or using your device to send spam.
  • Antivirus software scans files for known virus patterns and can remove infected code, but no tool catches every threat.
  • The best protection is not opening attachments from unknown senders, downloading only from trusted sources, and keeping your operating system patched.

How a virus spreads from device to device

A virus travels wherever the infected file goes. If you receive an email with an attachment that contains a virus, and you open that attachment, the virus activates on your computer. It then copies itself into other files on your hard drive. If you send one of those newly infected files to a friend — by email, cloud storage, USB drive, or file-sharing service — the virus moves to their device when they open it.

Email is the most common delivery method because it reaches many people at once. A virus might disguise itself as a resume, an invoice, or a document from someone you know. Infected downloads are the second major route: a file you read from a website, a torrent, or a peer-to-peer network might contain hidden code. USB drives and external hard drives can carry viruses too, especially if they have been used on multiple computers.

Older viruses required you to run a program file directly — a .exe file on Windows, for example. Modern viruses are more likely to hide in document files like Word files or PDFs, or in macros (small programs embedded in spreadsheets). Some viruses exploit security gaps in your operating system or browser, so they can run without you opening anything at all.

What damage a virus can cause

The harm depends on what the virus was designed to do. Some viruses are pranks that display a message or change your desktop. Most are destructive. A virus might delete files, corrupt your operating system so your computer will not start, or encrypt your files and demand payment to unlock them (this is called ransomware). Others steal passwords, credit card numbers, or personal information, then send that data to criminals.

A virus can also use your computer as a tool. It might send spam emails from your account without your knowledge, making it look like you are the source. It might join your device to a network of thousands of infected computers called a botnet, which criminals use to launch attacks on websites or other targets. Some viruses display constant pop-up ads or redirect your web searches to malicious sites.

The damage is often invisible at first. Your computer might run slowly, crash frequently, or use a lot of internet bandwidth before you realize something is wrong. By then, the virus may have already copied itself many times and spread to other devices.

The difference between a virus, a worm, and malware

These terms are related but not identical. Malware is the umbrella term for any malicious software — it includes viruses, worms, trojans, ransomware, spyware, and adware. A worm is a type of malware that spreads on its own without needing you to open a file. A worm can copy itself across a network or through email without any action from you. A virus, by contrast, needs you to open an infected file to set up and spread.

A trojan is malware that pretends to be something useful — a game, a utility, a document — but does something harmful when you run it. Unlike a virus, a trojan does not copy itself. A ransomware program encrypts your files and demands payment to decrypt them. Spyware watches what you do and reports it to someone else. Adware displays unwanted advertisements.

In everyday speech, people often call all malware "viruses," even when the threat is technically a worm or a trojan. The distinction matters to security experts, but for your protection, the response is the same: use antivirus software, keep your system updated, and avoid opening files from untrusted sources.

How antivirus software detects and removes viruses

Antivirus programs work by scanning files on your computer and comparing them to a database of known virus signatures — patterns of code that match viruses that have already been discovered. When the software finds a match, it quarantines the file (isolates it so it cannot run) or deletes it. Most antivirus tools also monitor your computer in real time, scanning files as you read them or open them from email.

Some antivirus software uses heuristic analysis, which means it looks for suspicious behavior rather than matching known signatures. If a file tries to do something that viruses typically do — like modifying system files or stealing passwords — the software flags it as a threat even if it is not in the signature database. This method catches some new viruses that have not been catalogued yet.

No antivirus tool is perfect. New viruses are created constantly, and it takes time for security companies to discover them, analyze them, and add them to their databases. A virus that is brand new might not be detected by any antivirus software for days or weeks. That is why antivirus software is one layer of protection, not the only one.

Steps to protect your computer from viruses

Install and run antivirus software from a reputable company. Windows Defender (built into Windows) and Malwarebytes are both widely used and effective. Keep the antivirus software updated so it has the latest virus signatures. Run a full scan of your computer at least once a month, or more often if you read files frequently.

Keep your operating system and all your programs patched with the latest security updates. Viruses often exploit known security gaps that have already been fixed. Windows, macOS, and Linux all release updates regularly. Enable automatic updates so you do not have to remember to install them manually. The same applies to your browser and any plugins like Flash or Java.

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 unusual or out of character. Do not read files from untrusted websites. If a read seems too good to be true — a free copy of expensive software, for example — it probably is. Use a USB drive only if you trust the source, and scan it with antivirus software before opening files from it.

Back up your important files regularly to an external drive or cloud storage that is not connected to your computer at all times. If a virus encrypts your files, you can restore them from a backup instead of paying a ransom. Keep your backups offline or on a service that does not sync in real time, so a virus cannot infect the backup.

What to do if you think your computer has a virus

If your computer is running slowly, crashing, displaying pop-ups, or behaving strangely, a virus might be the cause. read and run a full antivirus scan. If you are worried the virus has already compromised your antivirus software, read the scan tool on a different device and transfer it to the infected computer using a USB drive.

If the antivirus scan finds and removes a virus, restart your computer and run the scan again to make sure the infection is gone. If the virus has damaged your operating system and your computer will not start, you may need to reinstall Windows or macOS from installation media, which will erase everything on your drive. That is why backups matter.

If you suspect a virus has stolen your passwords or financial information, change your passwords from a different device that you trust. Monitor your bank and credit card accounts for unauthorized charges. Consider placing a fraud alert with the credit bureaus.

Frequently Asked Questions

Can a virus spread through WiFi without me opening anything?

Most viruses cannot spread through WiFi alone — they need you to open an infected file. However, some malware can exploit security gaps in your router or operating system to spread without your action. This is rare but possible. Keeping your router firmware and operating system updated reduces this risk.

Is it safe to open a file if the antivirus software says it is clean?

Antivirus software is reliable for known viruses, but new threats are created constantly. If a file is from an untrusted source, it is safer not to open it even if the antivirus scan passes. Trust your judgment about whether the sender and the file make sense.

Can a virus spread through a text message or social media?

A text message or social media post cannot directly infect your phone with a virus, but a link in a message can lead to a malicious website that tries to install malware. Do not click links from unknown senders. If a link comes from someone you know but seems out of place, ask them about it before clicking.

Will restarting my computer remove a virus?

Restarting alone will not remove a virus. The virus code is stored in files on your hard drive, so it will still be there after you restart. You need antivirus software to find and remove the infected files. Restarting can help if a virus is currently running in memory, but it will not solve the problem permanently.

What is the difference between a virus and a bug in software?

A bug is an unintended error in legitimate software — the programmer made a mistake. A virus is intentional malicious code designed to cause harm. A bug might cause a program to crash or behave unexpectedly, but it is not trying to steal data or damage your system. Bugs are fixed through software updates; viruses are removed by antivirus tools.