Fungal nail infections can be caused by three different types of fungus, alone or in combination.
Dermatophytes are a type of fungus that can grow on the skin, hair, and nails. They don't invade the deeper tissues of the body. The most common dermatophyte, Trichophyton rubrum, causes most cases of athlete's foot. Athlete's foot, in turn, can infect the toenails. You can get infected by contact with objects that have dermatophytes on them, such as clothing, shoes, nail clippers, nail files, shower and locker room floors, and carpet. Dermatophytes cause almost all fungal toenail infections.
Yeasts are a type of fungus that grows on the skin and nails. They are normally present on the human body. Things like illness, antibiotic or birth control pill use, and immune system problems may allow an overgrowth of yeast, leading to a yeast infection.
Molds (often called nondermatophytes) are a type of fungus that commonly grows in soil and can grow on the skin and nails. They aren't usually passed between people.
You can get a fungal nail infection when you come in contact with the fungus and it begins to grow on or under your nail. Fungi grow best in warm, moist areas, such as the area around the toes. But you can have fungi on your skin without getting a nail infection. You have to be likely to get the infection (susceptible) for it to develop. If you are susceptible to fungal infections, they tend to return, even after successful treatment and especially if you don't take preventive steps.
It is not clear why some people are more susceptible to fungal infections than other people.