Hydrogen peroxide is one of the most frequently recommended home treatments for fungus gnats, and it does work — within limits that are worth understanding, because the limits explain why people report it failing.
What it actually does

The usual preparation is one part ordinary 3% hydrogen peroxide to four parts water, used as a normal watering so the soil is thoroughly wetted.
Peroxide kills fungus gnat larvae on contact by oxidising them. It then decomposes rapidly into water and oxygen, which is why it leaves nothing behind in the soil and does not harm the plant at that dilution. The brief fizzing when it hits damp soil is that decomposition happening.
There is a secondary effect: it temporarily reduces the fungal and organic material in the top layer that larvae feed on, which makes the soil marginally less hospitable for a short period.
What it does not do

It kills only what the solution physically reaches, on the day it is applied. Larvae deeper in the pot, larvae in a dry pocket the water ran past, and eggs that hatch the following day are all unaffected.
It also has no residual action. Twenty minutes after application there is no peroxide left in the pot, so a female laying eggs that evening produces a full new generation.
That is the whole reason for the pattern people describe — gnats gone for a few days, gnats back within a fortnight. The treatment did what it does; it simply does not do the other thing.
Using it sensibly
If you use it, use it as a knockdown alongside something that breaks the cycle rather than as the whole plan.
Apply it as a thorough watering rather than a light splash, so it penetrates the top few centimetres where the larvae actually live. Repeat every four to seven days for at least three applications, which covers roughly one full generation. Do not increase the concentration in the hope of better results — stronger solutions damage fine roots, and a plant with damaged roots is more vulnerable to everything.
Avoid using it on very young seedlings and freshly taken cuttings, whose root systems are least able to tolerate it.
What to pair it with
The change that actually breaks the cycle is letting the top two to three centimetres of the pot dry out between waterings. Fungus gnat eggs and young larvae do not survive a dry surface layer, and this costs nothing.
Bottom watering achieves the same thing while still keeping the roots supplied, and a layer of coarse sand or grit on the surface makes it physically difficult for adults to lay.
For a plant that genuinely cannot be allowed to dry — a fern, a carnivorous plant, some seedlings — a Bacillus thuringiensis israelensis drench is the better choice. It is a bacterium specific to fly larvae, it persists in the soil rather than dissipating in minutes, and it is used in the same way as a watering.
Judging whether it is working
Yellow sticky traps are the measuring instrument rather than the treatment. Count what is caught each week. A population under control produces a falling count over three to four weeks; a population being knocked down and rebuilding produces a sawtooth that returns to where it started.
Keep going for two weeks after the last adult is seen. Stopping the moment they disappear is the single most common reason an infestation comes back.
Why the soil got hospitable in the first place
Fungus gnat larvae feed on fungi and decaying organic matter in permanently damp soil. A pot that dries between waterings simply does not support them for long, which is why the same collection can have one plant infested and the others untouched.
The plants that get infested are usually the ones being watered on a routine rather than by checking, the ones in pots much larger than their root ball, and the ones in dense peat-heavy compost that holds water for a week. Correcting any of those does more long-term good than any treatment, and it also happens to be the same correction that prevents root rot.
New plants and fresh bags of compost are the usual point of entry. Quarantining anything new for two or three weeks away from the rest of the collection catches most of it before it spreads, and storing opened compost sealed and dry keeps it from becoming a breeding site of its own.
