What Causes Ear Mites?

I have found several 'cures' for ear mites - but what causes them in the first place? Contagion, air borne, outside like ticks, etc.? My furry friend is normally extremely affectionate, but it took me almost a week to figure out what was bothering him because he was keeping to himself and didn't want anyone anywhere near his head/ears. I got OTC meds, and his relief was immediate! I want to avoid ever having him suffer like that again.