Like viruses in humans or animals, computer viruses work by spreading themselves, by attaching themselves to an innocuous program or computer process and replicating with the spread of information between computers. Average computer users see viruses spread through websites or email.
Computer viruses are like real viruses in that they can't reproduce on their own. A computer program is defined as a virus if users open it or spread it inadvertently. A common form of computer virus is a trojan virus, a program that masquerades as a beneficial program and spreads itself by enticing users to download it. The trojan virus works by using a simple psychological trick. Users download a file labeled "CoolProgram.exe" but it is actually a harmful program.
Another way viruses work is by attaching, or "piggybacking," themselves to a useful program. Websites can transmit information to your computer without a user realizing it. A computer user may visit a website that loads a virus onto their computer without them knowing it. Piggyback viruses also come attached to emails. Many popular email clients scan email attachments because of the threat of piggybacking.
Other viruses work by relying on physical transportation of information. These viruses embed themselves in hard drives or other portable storage and replicate when attached to a new host.