The total baryonic mass density can be estimated by combining analysis of the cosmic microwave background, estimates of the primordial abundances of helium and deuterium and measurements of the Hubble parameter.
The value of $\Omega_b h^2$, where $\Omega_b$ is the ratio of the baryon density to the critical density for a flat universe and $h$ is the value of the present-day Hubble parameter divided by 100 km/s/Mpc, is directly constrained by modelling the small scale anisotropies in the CMB.
The dependence of CMB angular variations on the baryon density (from Dodelson & Schmidt 2021 Modern Cosmology)
Primordial nucleosynthesis calculations also show that the primordial abundances of helium and deuterium depend on $\Omega_b h^2$.
Primordial abundances versus baryon density. The horizontal bands are measurements of the primordial helium and deuterium abundances. The curves are nucleosynthesis predictions. The vertical grey band is the constraint from the CMB. Note the excellent agreement. (From http://www.astro.ucla.edu/~wright/BBNS.html).
Combining these measurements can give the value of $\Omega_b$, but combining either with a value for the Hubble parameter $(h \simeq 0.7)$ would also give a value for $\Omega_b$.
There are of course (small) uncertainties in all of these numbers, at the level of 10 per cent or so.