A virus replicates itself by attaching to another file, whereas a worm can replicate itself independently.