When a fragment of a song repeats over & over in your mind.
Earworms (aka Involuntary Musical Imagery) are pieces of music that ceaselessly repeat in your mind until something finally breaks the cycle, ending the loop. Almost everyone experiences earworms. Sometimes a song gets stuck in your head after you recently heard it but other times it can be triggered by a memory (such as seeing a product and remembering an old commercial jingle).
The types of songs that get stuck in our heads tend to be faster simpler melodies that have some unique/catchy element that make them stand out from other songs. They also tend to be (but are not always) songs you like, particular to your musical tastes, and are songs you listen to more often. Another quality that makes a song a strong candidate for an earworm, which is also a quality that our brains like, is repetition. Typically when a song gets stuck in your head it’s not the whole song but instead is just a catchy fragment of a song that can seamlessly repeat over & over. Related to the Zeigarnik effect and how our brains hold on to unfinished tasks, a song fragment will remain in our brains, unfinished, looping over & over until we are able to complete the song (or until we get distracted). As such one way to stop an earworm is to listen to the entire song. Like nudging the needle on a record player that is skipping over and over, listening to the entirety of the song can help break the loop and bring a sense of closure.
Other potential cures for earworms, beyond listening to the song in its entirety, are:
• Listen to “cure” songs (not the band, although …). Listening to other songs can distract/free your mind from the loop it is in.
• Do something else. Since we aren’t as good at multitasking as we thing we are, putting your conscious thoughts towards some other task can end the earworm.
• Chew gum. The act of chewing uses some of the same regions of the brain as speech and, since most earworms are songs with lyrics, chewing can help distract your brain from the looping lyrics of the earworm.
Added info: as for literal worms or bugs in your ears, it happens but it’s not common. Cockroaches (who are not adept at walking backwards), spiders, and flies seem to be the most common types of insects/arachnids that accidentally find their way into human ears. These creatures typically don’t want to be there but may end up getting stuck which is bad for everyone involved.