Bile acids are important for absorbing nutrients. Most mammals produce cholic and chenodeoxycholic bile acids. Here, we investigated genes in the bile acid synthesis pathway in four mammals that deviate from the usual mammalian bile composition. First, we show that naked-mole rats, elephants, and manatees repeatedly inactivated CYP8B1, an enzyme uniquely required for cholic acid synthesis, which explains the absence of cholic acid in these species. Second, no gene-inactivating mutations were found in any pathway gene in the rhinoceros, a species that lacks bile acids, indicating an evolutionarily recent change in its bile composition. Third, elephants and/or manatees that also lack bile acids altogether have lost additional nonessential enzymes (SLC27A5, ACOX2). Apart from uncovering genomic differences explaining deviations in bile composition, our analysis of bile acid enzymes in bile acid-lacking species suggests that essentiality prevents gene loss, while loss of pleiotropic genes is permitted if their other functions are compensated by functionally related proteins.