The big problem: how much phonetic detail to represent when we write meaningful units (i.e. the word, the morpheme, the sentence etc.)? Can we ignore certain phonetic details? Are there certain things that while phonetically present, don't need to be represented, while other phonetic differences must be taken into account?
For instance, we don't write aspiration in English stops, even though they are phonetically so; we don't write vowels before voiced stops as long, even tho they are. Why not? they are predictible, and every speaker of E. knows that stops must be aspirated and vowels must be long. If they are not, IT DOESN'T MAKE A DIFFERENCE IN MEANING OF THE WORD. It may sound funny, but it doesn't make a difference in meaning. Notice I don't say they ``have meaning", just that they don't represent a difference.
But voicing in E. consonants does make a difference in meaning; almost always there may be another word with a different meaning; or if not, we recognize that the sound is different, and could represent a word of English that doesn't happen to be a word.
If the difference between English t and d, p and b, s and z etc. is phonetically significant and makes a difference in meaning, (while the difference between ph and p is phonetically significant but doesn't make a difference in meaning), what shall we call this difference? Let us call it a phonemic difference.
Let us say that certain phonetic differences which can not be ignored at the level of phonetic detail can be ignored at a slightly higher level, which we shall call the phonemic level. This level may perhaps be the most efficient way to write language; writing systems may perhaps be ideally phonemic, rather than phonetic. Let us say that certain phonetic details seem to have a distribution that complement each other and because of this complementarity, they can be considered almost like the same sound. They can be considered to be a class of sounds in complementary distribution, and we call each class a PHONEME. Thus, [p, ph], and [p`] are a phoneme /p/ in English. The members of the class we call allophones and while we recognize their phonetic details we do not need to represent (write) them. What we write is only the most significant phonetic differences, details that if ignored may bring confusion in the meaning of the meaningful units. That is, we must write /p/ and /b/ as different. They do not have inherent difference in meaning, but when combined in morphemes or words the result may be a difference in meaning. Putt and but are different meaningful units in English. In some other language there may be no difference between /p/ and /b/, or in some language there may be a difference between /ph/, /p/ and /b/, so in that language, there will be 3 phonemes where E. has only 2.