The function of a fish's swim bladder is to help the fish control its buoyancy and maintain its position in the water column. By adjusting the amount of gas inside the swim bladder, the fish can either rise or sink in the water. This helps the fish conserve energy while swimming and allows it to stay at a desired depth without constantly having to swim.