Water damage seeps well into the surface of the wood, but it can be sanded off. Use an electric hand sander and test an area of the damage to see how deep it goes. If it is only just beneath the surface, you can sand it out. If it goes more than 1/4 inch into the wood, you are better served by sealing the beam and painting it to hide the water damage.
If the exposed beams are finished (stained), you will need to find the exact same wood stain for your fix. If you cannot find the right color, get as close as possible; otherwise, you'll have to re-stain all of the beams to match. Sand out the damage, apply the wood stain and then protect the wood with a clear coat of polyurethane. This will help protect the wood from future water damage.
If the water stains go deep, first sand the entire surface of the exposed beams with a fine grade of sandpaper. Prime them first with an oil-based primer and let this dry completely, usually about four to six hours. Apply an oil-based paint over the primer. You may need two coats of paint if the stain is particularly stubborn. The downside to this repair is that all the beams will have to be painted to match.
Exposed beam ceilings should be properly protected from water damage. Check for roof leaks frequently and have repairs done as quickly as possible. Coating the wood with polyurethane will help water bead off the surface instead of soaking through it. It's a good idea to add a coat of polyurethane, even if the beams are not finished, just as a precautionary measure. A new coat should be applied every few years to keep the finish strong.