Methods to remove carpet mildew, which causes both stains and odors, include vacuuming the carpet, applying a cleaning agent or a homemade solution to the affected area, then rinsing it well and allowing it to dry thoroughly. Choose an appropriate method depending on the extent of the problem.
If the carpet is removable, clean it outdoors to prevent the spread of mildew spores inside the house. Vacuum the affected area to remove residue, making sure to dispose of the vacuum bag. Next, make a solution by mixing ½ cup of borax in 1 gallon of warm water. Borax is used for its antifungal properties. Scrub the solution into the carpet using a brush. Rinse the area, and allow it to dry, using fans and hairdryers if needed. For small and isolated mildew stains, make a solution with 1 tablespoon of salt, 1 tablespoon of vinegar, and a few drops of tea tree oil. Apply to the affected area, then rinse and dry as above.
Replace carpets extensively affected by mildew or, if possible, cut out and replace an isolated affected part not larger than 2 feet square. However, to treat small areas identified early on, use a steam-cleaning machine to clean the carpet with water and detergent, and ensure thorough drying to prevent recurrence. If this fails, use stronger cleaning agents, but only after testing them on a small, inconspicuous part of the carpet for at least 24 hours.