We investigate the discrepancy between estimates of the total baryon mass fraction obtained from observations of the cosmic microwave background (CMB) and of galaxy groups/clusters using a sample of 91 X-ray selected groups from the COSMOS survey complemented by 27 nearby clusters. We constrain the behavior of the stellar and baryon mass fractions for groups and clusters over the unprecedented mass range ~1013