The first known computer bug was a real bug. It was a moth that got stuck inside the enormous inner workings of an early computer in 1947.
On September 9, 1947, Grace Murray Hopper recorded this first computer bug in her log book as she worked on the Harvard Mark II.
The problem was traced to a moth stuck between a relay in the machine. After "debugging" the computer, Hopper taped the moth into the Mark II's log book with the explanation: “First actual case of bug being found.”
The first computer worm was invented by John Brunner. It did not occur inside a computer program, but in his 1975 science fiction novel, The Shockwave Rider. He called it a “tapeworm,” since it worked in a way similar to that fleshy parasite. It was the first description of a set of computer codes that moves from one computer to another on a network as a coherent entity.
A computer worm is a standalone malware computer program that replicates itself in order to spread to other computers. Often, it uses a computer network to spread itself, relying on security failures on the target computer to access it.
It differs from a computer virus, it does not need to attach itself to an existing program. Worms almost always cause at least some harm to the network, even if only by consuming bandwidth, whereas viruses almost always corrupt or modify files on a targeted computer.
On November 2, 1988, Robert Tappan Morris, a Cornell University computer science graduate student, unleashed what became known as the Morris worm, disrupting a large number of computers then on the Internet, guessed at the time to be one tenth of all those connected.
Museum of Science - Morris Internet Worm, CC BY-SA 2.0,
https://commons.wikimedia.org/w/index.php?curid=3959700 By Go Card USA from Boston, USA