A cough is supposed to protect you. It gets out stuff that doesn't belong in your lungs and windpipe, like inhaled dirt or food. Here are the common triggers.
Viruses. Colds and the flu are the most common causes. While annoying, coughs that are “productive” get germy mucus out of your lungs when you're sick. Most will go away in a few days. After a cold, though, some "dry" coughs last weeks or months. That could be because coughing irritates your lungs, which leads to more coughing, which irritates your lungs, and so on ...
Allergies and asthma. If you have them, inhaling a trigger like mold can cause your lungs to overreact. They're trying to cough out what’s bothering them.
Irritants. Even if you're not allergic, things like cold air, cigarette smoke, or strong perfumes, can set off a hacking spell.
Postnasal drip. When you're congested, mucus drips down from your nose into your throat, and makes you cough. You can get postnasal drip from colds, flu, sinus infections, allergies, and other problems.
Acid reflux. When you have heartburn, stomach acids back up into your throat, especially at night. They can irritate your windpipe and make you cough.
Other causes. Many other problems -- lung inflammation, sleep apnea, and drug side effects -- can be triggers. Get coughs that won't go away checked out to make sure you don’t have a separate problem.