The tiny black flies that rise from a pot when you water are usually fungus gnats. The adults are just a nuisance, but their larvae in the soil can damage the roots of seedlings and young plants. Here is how to tell what you have, how to get rid of gnats in houseplants step by step and how to keep them from coming back.
More on this topic: why houseplants get sick, houseplants: names and care, how to repot a houseplant.
Eggs and larvae arrive in bagged potting mix or on a new plant, and adults fly in through open windows.
They breed in constantly moist soil rich in organic matter: larvae feed on fungi and plant debris and, when that runs short, on fine roots.
So the main causes are frequent watering, water left in saucers, pots without drainage and homemade fertilisers such as tea leaves or coffee grounds.
To check for larvae, lay a slice of raw potato on the soil for 1–2 days; larvae gather underneath.
Step 1. Let the top 2–3 cm of soil dry out completely before watering. Larvae die in dry soil and females won't lay eggs there.
Step 2. Stick yellow sticky traps near the pots to catch adults and show whether numbers are falling.
Step 3. Top the pot with 1–1.5 cm of dry sand, fine grit or decorative gravel so there is nowhere to lay eggs.
Step 4. Water from below via the saucer and pour away what's left after 20–30 minutes.
Step 5. For heavy infestations, drench the soil with a biological product based on Bacillus thuringiensis israelensis or a systemic houseplant insecticide, following the label. Repeat after 7–10 days.
Step 6. Last resort: repot. Shake off the old soil, trim rotten roots and use fresh mix; see how to repot a houseplant.
A hydrogen peroxide drench (1 part 3% peroxide to 4 parts water) kills larvae on contact. It helps but doesn't replace letting the soil dry.
A trap of cider vinegar with a drop of washing-up liquid catches adult gnats and fruit flies.
Matches pushed into the soil, garlic or potassium permanganate have weak or doubtful effect, and strong permanganate can burn roots.
The right fix depends on what exactly is flying around the pot. Watch the insects for a few minutes:
If drying out the soil and traps have not worked within 1–2 weeks, move on to dedicated products. Garden centres and pet shops with a plant section sell them.
Use chemicals strictly as the label says: wear gloves, work on a balcony or by an open window, and keep them away from children, cats and aquariums. Do not treat windowsill herbs you eat with insecticides; for those, stick to drying, sand and traps.
The flies hovering over cut flowers are usually fruit flies, not fungus gnats: they are drawn to fermenting water and fallen petals. No insecticide is needed.
After that, change the water every 1–2 days and the flies will disappear along with the smell.
Looking for a living gift that lasts for months? A potted orchid is a great choice for home or office.

See houseplants and orchids.

No. They don't bite or carry disease; they are just annoying.
Let the soil dry, use yellow sticky traps and top-dress with sand; for heavy infestations drench with a biological product or insecticide.
Plants drink less in winter but are often watered out of habit, so the soil stays wet.
No, they are springtails: mostly harmless, but a sign of overwatering.
A fungus gnat completes its life cycle in roughly 3–4 weeks in a warm flat. Keep drying, trapping and treating for at least a month, even after you stop seeing adults.
No. Fungus gnats do not bite or carry disease; they only harm the roots of young plants and seedlings.