Earwax is both anti-fungal and anti-bacterial. It serves as a water repellent for the auditory canal. Earwax is produced by tiny glands in the outer ear passage/canal. These glands are called ceruminous glands and they are a special type of sweat gland. They produce earwax to form a protective coating inside the ear canal. The wax traps dust and other tiny objects, preventing them from getting into the delicate interior of the ear.
Some people produce more earwax than others. It usually makes its way out of the ear gradually. Little pieces or flakes of wax fall out of the ear from time to time, but in some people the wax builds up and hardens, forming a blockage.