According to Coyle S. Connolly, DO, the most common cause of discolored nails is a condition called onychomycosis. This nail fungus occurs when organisms known as dermatophytes move in under your nails. According to the National Onychomycosis Society, 11 million new cases are diagnosed each year. Why so common? Toenails and fingernails and surrounding skin are prone to everyday wear and tear, which invites dirt, germs, and infection-causing fungi to take up residence there. The first sign of a fungal infection is a change in color. The nail often becomes yellow to brown, and then it gets thicker and may develop a bad odor. Debris may collect beneath the nail, and a white area on the nail edge may form as the nail begins to lift from the nail bed. The infection can spread to other nails and even the skin. Toenails are affected more frequently than fingernails. This whole process often happens more frequently with age, Connolly says. In addition, age alone—without fungal infection—can also cause your nails to become yellow, but in this case, the nails are just discolored, but not thick and misshapen. Here’s how to treat discolored nails, or keep these changes from happening to you.

Keep Clean

Because fungi are everywhere, including the skin, they can be present months before they find opportunities to strike. By following proper hygiene and regularly inspecting your feet and toes, you can reduce your chances of the problem, or even stop the chain of events once it starts, says Paul Kechijian, MD. “Clean, dry feet resist disease. A strict regimen of washing the feet with antibacterial soap and water every night before bedtime, and remembering to dry thoroughly, is the best way to prevent an infection,” says Kechijian. This habit helps rid the feet of excess bacteria from shoes and gives them a full night of cleanliness before they are back into shoes.

Wear Your Shoes In Yucky Surroundings

If you’re prone to developing fungal infections, walking barefoot in public facilities can expose your feet to the troublesome fungi, Kechijian says. So slip your feet into shoes or sandals rather than placing your bare feet in harm’s way. (Here’s what really happens if you go barefoot at the gym.)

Snip Nails Short

“Longer nails can get caught on things or rub against tight shoes, which can cause the nail to lift from its bed,” says Connolly. “That opening can invite fungus inside.” Clip toenails straight across so that the nail doesn’t extend beyond the nail bed, he suggests.

Keep Feet Cool

Use a quality foot powder—talcum, not cornstarch—and wear shoes that fit well and are made of materials that breathe, says C. Ralph Daniel III, MD. The reason? “Sweating makes matters worse, since it creates a warm, moist environment—perfect for spreading nail fungus,” he says. The fungus digests the nail keratin, the protein that makes up the nail, causing the discoloration, which ranges from white to yellow and less often green to black.

Wash Your Hands

Fungal infection can spread from your feet to your hands. So wash your hands after inspecting your feet, says Connolly. Also, smooth away dead skin by gently scrubbing it with soap and water, because fungus often attaches itself to dead, dry skin and moves on to other areas. “Watch for any rash or nail involvement of any new rash,” he advises.

Watch Those Nail Products

Ordinarily, any moisture that collects underneath the surface of the nail passes through the porous structure of the nail and evaporates. Acrylic nails applied to the tops of the nails may impede that, however. The moisture trapped below can become stagnant and unhealthy, ideal conditions for fungi and similar organisms to thrive, says Daniel.

Try Vinegar

Sometimes nails can develop a greenish hue caused by a bacterial infection, Connolly says. Pour some white vinegar in a bowl and soak your nails in it a few times a day. Vinegar is actually a mild acid, and it can be helpful in these cases. MORE: 20 Natural Home Remedies That Work

Or Try Lemon Juice

To remove run-of-the mill stains from your fingernails, soak them in lemon juice, suggests Gina Morgan, a nail care instructor.

Prevent Polish Stains With A Base Coat

A base coat is typically a clear nail polish that goes onto your fingernails first, keeping the colored fingernail polish—and its potential lingering stain—off your nails, Morgan says. It also helps keep the polish on your nails. (Fnd out if your manicure is ruining your nails.)

Cover Them Up

If you have staining that’s not linked to fungus or any other growth on your fingernails, and you don’t have pain or other symptoms of a true health problem, then feel free to just cover it up with nail polish, Connolly suggests.

Be Careful When Getting Your Nails Done

When getting a manicure or pedicure, ask the nail technician not to be overly aggressive with your cuticles, Connolly says. This thin seal of skin around the edges of your nail acts like a sort of “weather strip,” keeping out the elements. Oftentimes when people visit the nail salon, their cuticles are overly trimmed and pushed back, providing an opening for invisible attackers to enter.

Don’t Expect Too Much From Nonprescription Treatments

Over-the-counter treatments for nail fungus typically don’t work well, if at all, Connolly says. Nails are so thick, and made of such strong material, that these treatments penetrate poorly. Your doctor can prescribe medications that you take orally, which attack the fungal infection from the inside out. Even these take many months to work.

When To Visit A Doctor About Nail Discoloration

According to Connolly, onychomycosis is not a problem to be ignored. “In fact, if left untreated, it can spread to other nails and make everyday activities, such as walking or writing, painful and difficult,” he says. See your doctor if:

You notice unexplained changes in the color of your nail. Your nails appear to be abnormally thick. The area surrounding your nails are painful or tender. You have swelling on the skin surrounding the nail. You have a nail that appears to have separated from the nail bed.

“If it’s a fungus, it’s best to catch it in its earlier stages. If the discoloration is a symptom of something more serious, early detection is even more important,” Connolly says.

Panel Of Advisors

Coyle S. Connolly, DO, is a dermatologist and assistant clinical professor at the Philadelphia College of Osteopathic Medicine and the president of Connolly Dermatology in Linwood, New Jersey. C. Ralph Daniel III, MD, is a clinical professor of dermatology at the University of Mississippi Medical Center and a clinical associate professor of dermatology at the University of Alabama at Birmingham. Paul Kechijian, MD, is a former clinical associate professor of dermatology and chief of the nail section at the New York University Medical Center in Great Neck. he’s now in private practice in Great Neck. Audrey Kunin, MD, is a cosmetic dermatologist in Kansas City, Missouri, the founder of the dermatology educational website, DERMAdoctor.com, and author of The DermaDoctor Skinstruction Manual. Gina Morgan is an instructor at the International School of Skin and Nail Care in Atlanta.