A "bad apple" is someone or something that ruins everything around it. This particular phrase is part of a longer saying which states that "One bad apple spoils the barrel." Idioms like "bad apple" are able to communicate something more than just the meanings of the individual words. The word idiom is derived from the ideas behind two Greek words: idios, meaning personal or private and idiousthai, meaning to make your own. In modern vernacular, this idiom refers to one single thing or person can have a negative effect on all the things or persons around it.
In literal terms, the phrase 'bad apple" simply means that one bad or rotten apple can negatively affect all of the other apples in the same barrel. Rotting fruit produces various gases, like ethylene oxide, amylases, and proteases. Plant tissues also emit hormones, which may signal quicker ripening and, therefore, quicker rotting. Some apple growers actually pick fruit before it is ripe and expose it to ethylene gas right before sending it to market.
This particular idiom is thought to be derived from an old proverb, popular when societies were more agrarian. Similar popular sayings from the past state that "A good apple tree has the most sticks under it," and "A fish rots from the head down." Sayings like these have fallen out of use because people don't have to inspect the fish they have caught or the apples they have picked before they eat them. Rotten fish and apples usually don't reach the supermarket. "Bad apple" has remained because it has meaning that is applicable to modern life.
Today, "bad apple" may refer to one or a few members of a large organization whose behavior or antics affect an entire group in a negative way. A few loan officers may have been responsible for creating a wide-ranging mortgage crisis, a few bad cops could ruin the reputation and integrity of an entire police force, or one person's attitude could have a negative effect on the other people around them. So a "bad apple" is someone or something which causes the people or things in close proximity to be negatively affected.