Bob Gray was good enough to dig this up from his archives and post it to the Goldfish Mailing List. This is the best summary I've seen of causes for and treatments of goldfish floatation problems. There are many other treatments, both mainstream and "fringe", but this should be enough to get anyone started. I will add a few comments at the end.
"Why does my goldfish tend to float at the surface of the water and have a hard time going to the bottom of the tank?"
Because it's got swim bladder disease.
Swim bladder disease is a multifactorial illness which primarily affects ornamental goldfish which have globoid body shapes, like orandas, ryukins, and fantails. It most often presents as a fish which floats at the surface, or a fish which stays on the bottom and doesn't seem to be able to easily rise. A fish which has normal buoyancy but is listing to one side or the other often does not have swim bladder disease, but may have other diseases.
In order to understand swim bladder disease, a cursory discussion of fish anatomy and physiology is necessary. The swim bladder is a small epithelium-lined sac in the anterior abdomen which is responsible for maintaining buoyancy. It has a close association with blood vessels such that gases can diffuse across into and out of the sac according to the needs of the fish. The sac inflates if the fish needs to be more buoyant, and it deflates if the fish needs to be less buoyant. Goldfish and some other fish have a special addition to this system called the pneumocystic duct, which is a connection between the swim bladder and the esophagus, allowing additional adjustment of buoyancy by letting air out through the digestive tract.
People have debated for years over the cause of swim bladder disease. It is pretty well established now that a number of things can cause swim bladder disease. Some of the things which have been suggested are:
(Note: Some of this stuff is pretty far out, but effective.)
But the best thing to do is to prevent it from happening in the first place.
I'll just add a few of my opinions to Doug's excellent article. Diet seems to be far and away the most common cause of abnormal floating behavior. Look at the poops: they should come out in quarter or half inch chunks. Long, stringy poops are indicative of diet problems (though all fish have one of these every once in a while). To treat, I would start with: (1) fasting for a few days, and then (2) limited feedings of green peas popped out of their skins. I have read recommendations of cleaned earthworms as also being a laxative food, but I have no experience with this. I would view using a syringe to remove air from the swim bladder as a reasonable, but last ditch, way to buy time while treating a fish with really severe floatation problems, provided you are sure the problem is actually the swimbladder! Have a vet do this.