The number of bettas that can be kept together in the same aquarium depends on the gender of the betta. Only one male can be kept in an aquarium, as males will fight with one another (hence their common name, Siamese fighting fish). In the wild, one would retreat. But that isn't possible in an aquarium; fighting continues, to the death of one or both.
Females are only a bit more tolerant of each other. With adequate room, many can be housed together. However, if the tank becomes too crowded, females may start showing territorial behaviors as well. Do not mix males and females in the same tank, other than temporarily for breeding purposes.
Betta lovers will sometimes use a "betta condo" to allow them to keep multiple males in a single aquarium. The condo is simply a small container with dividers; walls are vented to allow water circulation through it. It hangs inside the aquarium, effectively keeping any fish inside separated from the rest of the tank.
Controversy surrounds the use of betta condos. Single condos kept in separate locations within the tank are acceptable. However, whenever betas can still see each other through clear walls, any close visual proximity will induce males and even females to flare in a fight stance. Bettas have excellent vision and can even be challenged by (and stressed by) bettas in another tank across the room!
Most betta owners feel that the stress caused by this unnatural proximity can negatively affect the health of the fish, thereby shortening its life. In the wild, fish never suffer such prolonged exposure to rivals. If condos are used, fish should be separated from all others by more than 12 or 15 inches, and they should have plants to hind behind.
Tank Size and Territory
The species is native to the Mekong basin in Southeast Asia, living in rice paddies and canals. In the wild, more than one male would live in a rice paddy. However, rice paddies are quite large, often encompassing miles of space. This allows each male to have its own territory. In small tanks, there simply isn't enough room for the establishment of territories, so it is not advisable to keep more than one male.
Tank sizes smaller than 20 gallons are usually a problem. Sizes larger than 20 gallons provide enough territorial space to allow multiple males. However, few people keep bettas in these larger tanks. Traditionally bettas are kept in very small tanks, hence the common statement of "one male per tank." A more accurate way of putting it would be one male per 20-gallon territory.
One additional factor is that domesticated bettas are the product of selective breeding for heightened aggression. In Thailand, they were collected specifically to fight in competitions. Domesticated bettas are more likely to keep fighting, whereas the wild breed would spar briefly and then retreat. This enhanced aggressive tendency makes it even more necessary to give each fish a large territory of its own.
Ramos, A., Gonçalves, D. Artificial selection for male winners in the Siamese fighting fish Betta splendens correlates with high female aggression. Frontiers in Zoology, 16, 34 (2019). doi:10.1186/s12983-019-0333-x