The short answer
A fish swimming upside down or floating on its side is usually struggling with its swim bladder, the organ that controls buoyancy. In common aquarium fish this most often follows overfeeding or constipation. The practical first steps are to fast the fish for a day or two, then offer a blanched pea, and to test your water to rule out anything else.
The swim bladder and overfeeding
When a fish gulps air, gorges on dry floating food, or becomes constipated, its digestive tract can press on the swim bladder and throw off its balance. Fasting for 24β48 hours gives the gut time to clear. After that, a small piece of blanched, deshelled pea acts as gentle roughage that many fishkeepers find helps. Going forward, feed less and pre-soak dry food so it sinks β see how often should I feed my fish?.
Donβt overlook the water
Buoyancy problems arenβt always digestive. Ammonia or nitrite poisoning and sudden temperature swings can also leave a fish disoriented, so test with a liquid test kit and confirm the heater holds a steady range. If anything is off, do a water change with dechlorinated, temperature-matched water. Related buoyancy behaviour is covered in why is my fish swimming erratically?.
When to get help
Some swim bladder issues are stubborn or reflect a deeper problem, and not every fish recovers. If fasting and a pea donβt help within several days, or the fish is also off its food and listless, watch for other symptoms and compare with how do I know if my fish is sick?. For a fish that keeps deteriorating, consult an aquatic vet or an experienced fishkeeping community rather than reaching for a medication blindly.