Multiple pronunciations of one sound unit
Phonemes are the abstract sound units that speakers treat as the same. Allophones are the different physical pronunciations that speakers accept as variants of a single phoneme. In English, the sound /p/ is one phoneme. But it is pronounced differently depending on context. Before a stressed vowel, /p/ is released with a burst of air (aspirated). After /s/, as in 'spin', /p/ is released without that burst (unaspirated). Speakers do not consciously distinguish these two pronunciations; they are interchangeable variants or allophones of the phoneme /p/. In other languages, such as Mandarin, aspirated and unaspirated /p/ are separate phonemes because changing aspiration changes the word's meaning.
The difference between phonemes and allophones is language-specific. What counts as one phoneme in one language may count as two separate phonemes in another, depending on whether the difference ever changes meaning.
Distribution and complementarity
Allophones of the same phoneme often show complementary distribution, meaning each allophone appears in certain contexts and others appear in different contexts. The aspirated /p/ in English never appears after /s/, and the unaspirated /p/ is rare before a stressed vowel. This predictability means listeners can infer which allophone is coming based on its phonetic context. When two sounds do not have complementary distribution and can appear in the same position, they must be separate phonemes.