The healthy ear
The ear canal is a tubular extension of the skin with some extra features. Skin cells mature and shed off approximately every three weeks. As this process is harder in a tube, the ear has a self-cleaning mechanism. Skin cells travel outwards and carry ear wax, micro-organisms that normally live on the skin surface and any foreign material that needs to be removed, towards the ear opening like a conveyor belt. This allows the dog to clean its own ears.
Self cleaning is important - if the ear drum area is covered in wax and skin cells then it is impossible for the dog to hear, one of the senses they rely heavily on.
If the self-cleaning mechanism fails due to inflammation and swelling, dirt and debris can build up. This creates a perfect environment for the bacteria and yeasts that normally live on the skin in low numbers, to multiply and overgrow (leading to an ear infection).