For a fish to be buoyant or float, it must displace less water or the same amount of water as its own body mass.
To ascend, a fish must reduce its overall density by increasing its volume without significantly increasing its mass. Most fish do this with something called a swim bladder. A swim bladder is just an expandable sac, like a human lung. To reduce its overall density, a fish fills the bladder with oxygen collected from the surrounding water via the gills. When the bladder is filled with this oxygen gas, the fish has a greater volume, but its weight is not greatly increased. When the bladder is expanded, it displaces more water and so experiences a greater force of buoyancy. When the bladder is completely inflated, the fish has maximum volume and is pushed to the surface. When the bladder is completely deflated, the fish has minimum volume and sinks to the ocean floor. To stay at a particular level, a fish fills its bladder to the point at which it displaces a volume of water that weighs what the fish weighs. In this case, the forces of buoyancy and gravity cancel each other out, and the fish stays at that level.