A barr body is an inactive X chromosome in female cells or the inactive Z in a male. Lyonization is the process where the chromosome is inactivated in species. In addition to this, it is thought to be down to complete chance as to which X chromosome is inactivated and it is still unknown to till date as to how the cell decides which X chromosome is to be made into a Barr body. It allows dosage compensation, so that there is not two alleles being expressed in women for every one in male.
In men and women with more than one X chromosome, the number of Barr bodies visible at interphase is always one less than the total number of X chromosomes.
For example, a person with Klinefelters syndrome, which is characterized by 47 chromosomes and XXY karyotype will have two Barr bodies, whereas an individual with Turners syndrome has 45 chromosomes and karyotype XO does not have any Barr bodies.