Swim Bladder Disease

Symptoms
Fish floats sideways at the surface, sinks tail-first to the bottom, swims upside down, or struggles to control depth. Often otherwise alert and trying to eat. Most common in fancy goldfish (egg-shaped bodies compress the bladder), bettas, and large gouramis.
Causes
Several possible causes: (1) Constipation from overfeeding dry food, most common cause in fancy goldfish, the bloated gut presses on the swim bladder. (2) Body shape, selectively-bred round goldfish are mechanically prone. (3) Bacterial infection of the bladder itself (uncommon, more serious). (4) Birth defects in linebred fish. (5) Sudden temperature changes.
Treatment
Constipation cases: fast the fish for 48 hours, then offer a shelled deshelled green pea (cooked and squeezed out of skin) or a small piece of cooked spinach. The fiber clears the gut. Switch from floating pellets to sinking pellets or pre-soaked food going forward, swallowed air from gulping floating pellets is a known trigger in goldfish. If symptoms don't resolve in a week, suspect bacterial infection and consider a broad-spectrum antibiotic.
Prevention
Don't overfeed. Use sinking pellets or soak floating pellets first. Vary the diet, gel foods and vegetables prevent constipation. Avoid dramatic temperature swings during water changes.
Notes
If you can press the fish gently and feel a hard belly, it's constipation. If the fish is soft and limp, it's likely bacterial, different treatment path. Fancy goldfish with chronic swim bladder problems may simply have the wrong body shape, there's no permanent fix.