Scrape off loose and peeling paint, or varnish with a stiff or chisel-edged scraper.
Scrub the wood molding clean with a mixture of detergent and warm water. TSP (trisodium phosphate) is an effective cleaner, but dishwashing detergent works well, too. Use a rough kitchen sponge or wet-dry sandpaper, then rinse the molding with clean water and a rag. Let it dry several hours or overnight.
Repair dents, holes and other damage with carpenter's wood putty. It's stronger than spackling paste, and it doesn't shrink.
Sand the molding smooth. Older molding might have multiple coats of paint and will be lumpy or rough. A power sander with 80- or 120-grit sandpaper will make the job go much faster. When the molding surface is smooth, wipe it down with a damp, lint-free rag.
Prime the molding. If you are priming over stained or varnished wood, use a stain-blocking, shellac- or oil-based primer. Use water- or oil-based primer on painted surfaces.Only bare wood areas need priming, but for maximum durability, prime all the molding.
Caulk gaps and cracks. It's easier to see what needs caulking after the molding has been primed, and caulk doesn't require priming. Apply the caulk, then smooth it down with a damp finger or a soft rag.
Paint the molding with two coats of water-based (latex or acrylic) or oil-based (alkyd) paint in your choice of gloss. Use a good-quality brush to apply thin, even coats, allowing them to dry as directed on the label.