Paint peels when something interferes with its adhesion. Moisture is usually the culprit, which can allow mildew to grow and compound the problem, but it can also be dust or even failure of the paint itself. When you want to repair peeling paint, the first step is always to remove all the loose paint; if you don't, you're bound to have adhesion problems again. You should then give the surface a good cleaning to make sure that all the dust and oils are gone before you apply a coat of primer and repaint the surface.
Remove a sample of the peeling paint and test it for lead if you suspect it was applied before lead-based paint became illegal in the 1970s. You can conduct the test yourself, using one of a variety of test kits available online or in stores. If the test is positive, you should consider having the paint removed by a contractor with lead paint remediation experience.
Scrape peeling paint that isn't lead-based using a paint scraper. Use a wire brush on metal surfaces. If you're working outside, a power washer effectively cleans siding, fences and other large surfaces.
Wash the surface with a solution of 1/2 cup of trisodium phosphate per gallon of water to remove grease and oil that could cause the paint to flake. For mildewed surfaces, add an ounce or two of chlorine bleach. Rinse with clear water and let the surface dry.
Scrape rust from metal surfaces and treat the rusted areas with a rust inhibitor. Paint the inhibitor on the rusted area and let it dry. Don't rinse it off.
Inspect the surface after you remove the flaking paint and fill voids with an appropriate filler. Use drywall joint compound to fill cracks and depressions in interior walls. Fill depressions and gouges on exterior walls with exterior spackling compound. Re-caulk joints between trim and walls or siding as necessary.
Prime the surface with oil- or shellac-based primer before painting. Primer contains adhesives that bond more securely than paint, and paint, in turn, bonds better to primer than it does to wood, drywall or metal.
Apply one or two topcoats of paint after the primer has dried.