Computer virus

Also known as: virus

On this page 7

A computer virus is a type of malicious program that inserts copies of itself into other programs, documents or boot records and spreads when the infected host is executed or opened. In cybersecurity, the defining property of a virus is that it needs a host and a user or system action to replicate, which distinguishes it from a self-propagating worm.

The word virus is often used loosely for any malware, but specialists reserve it for self-replicating code that infects other objects. Viruses dominated the threat landscape from the late 1980s to the early 2000s, and although ransomware, infostealers and trojans are now more common, file infectors and macro viruses still appear in incident response work.

How a computer virus infects and replicates

A computer virus operates through a life cycle of dormancy, propagation, triggering and execution. It stays hidden inside a host, copies itself into new hosts whenever its code runs, and eventually performs its payload when a trigger condition such as a date, a counter or a specific event is met.

Infection techniques differ by host type. A file infector modifies an executable so that the viral code runs first and then passes control to the original program, which keeps the user unaware. A boot sector virus replaces the code that runs before the operating system loads. A macro virus hides in the scripting language of office documents and runs when the document is opened with macros enabled.

PhaseWhat the virus doesTypical indicator
DormancyWaits inside the host without visible activityAltered file size or hash
PropagationCopies itself into other files, disks or documentsMany files modified at once
TriggeringChecks a date, count or event conditionActivity on a specific date
ExecutionRuns the payload, from messages to data destructionCorrupted files, system instability
Phases of the virus life cycle

Types of computer viruses

Computer viruses are classified mainly by the object they infect and by the evasion technique they use. These categories overlap, so one sample can be both a file infector and polymorphic.

TypeHost or techniqueCharacteristic behavior
File infectorExecutable files such as PE or ELFAppends or prepends viral code
Boot sector virusMaster boot record or volume boot recordLoads before the operating system
Macro virusOffice documents with embedded macrosSpreads through shared documents
Polymorphic virusEncrypted body with a mutating decryptorChanges its appearance on each infection
Metamorphic virusRewrites its own codeNo constant decryptor to detect
Resident virusStays in memory after the host exitsInfects files as they are opened
Common virus categories

Polymorphic and metamorphic viruses were developed specifically to defeat signature scanners. They forced antivirus vendors to adopt emulation, generic decryption and behavioral analysis, techniques that remain central to modern endpoint protection.

Computer virus compared with worms, trojans and other malware

A virus differs from other malware chiefly in how it spreads. Malware is the umbrella term; a virus, a computer worm and a trojan are distinct propagation models, and a single modern threat may combine them.

Malware typeNeeds a host fileSelf-replicatesMain spread mechanism
Computer virusYesYesInfected files, documents or media
Computer wormNoYesNetwork services and vulnerabilities
TrojanNoNoDeception of the user
RansomwareNoVariesOften delivered by other malware
Fileless malwareNoRarelyScripts and memory-only execution
How viruses differ from related malware

The practical consequence is that a virus depends on sharing behavior: copying files, exchanging removable media or sending documents. A worm can spread across a network without any user action, which is why worms historically produced faster and wider outbreaks than classic viruses.

Detection and removal of computer viruses

Viruses are detected by a combination of signature matching, heuristics, emulation and behavior monitoring. Signatures catch known samples quickly; heuristics and sandboxed emulation identify new or mutated variants by what the code attempts to do.

Removal is more delicate than for standalone malware because the virus is woven into legitimate files. A disinfection routine must locate the original entry point, strip the viral code and restore the host, which is not always possible. When disinfection fails, the safe choice is to restore the file from a clean backup or reinstall the affected software.

SymptomLikely causeRecommended response
Executables grow in sizeFile infector appending codeIsolate host, scan offline, restore from backup
System fails before bootBoot sector infectionBoot from trusted media and repair boot records
Documents prompt to enable macrosPossible macro virusKeep macros disabled, inspect in a sandbox
Scanner flags different hashes of one familyPolymorphic variantRely on behavioral and generic detection
Symptoms, likely causes and responses

Prevention practices and common mistakes

Effective virus prevention relies on reducing execution of untrusted code and limiting how far an infection can spread. Most measures are inexpensive and overlap with general malware defense.

  • Enable macro blocking for files from the internet and allow only signed macros where business processes require them.
  • Use application allowlisting so that unknown executables cannot run on critical systems.
  • Enable Secure Boot and UEFI firmware protections to block boot-level infections.
  • Maintain offline or immutable backups, because infected files may be unrecoverable.
  • Scan removable media and shared drives automatically before files are opened.

A frequent mistake is to assume that one antivirus scan proves a system clean. Resident and polymorphic viruses can evade or reinfect during a scan, so investigators prefer offline scanning from trusted media and verification of file hashes against known-good versions.

In everyday language

A computer virus is a small harmful program that hides inside something you already trust, such as a program or a document. When you open that file, the virus runs too and quietly copies itself into other files.

It behaves much like a cold passed between people: it cannot travel on its own, so it spreads when infected files are shared. The best protection is to avoid opening files you do not trust, keep security software up to date and keep backups.

Seen in the real world

An engineering firm with about 120 workstations notices that several CAD workstations run slowly and that many executable files on a shared network drive have grown by the same number of bytes. The help desk first suspects a failing disk, but the endpoint protection console begins flagging a known file infector family.

The security team disconnects the shared drive, boots the affected machines from trusted media and runs an offline scan. About 2,300 executables are infected; roughly a third cannot be disinfected safely and are restored from the previous night’s immutable backup. The source turns out to be an old installer on a contractor’s USB drive. The firm then enables automatic scanning of removable media and application allowlisting, and no reinfection is observed in the following months.