It is estimated that there are about 300 billion galaxies in the universe.
This is determined by counting all the galaxies in a small (very small) portion of space and then doing simple arithmetic.
Here is an example. Say you wanted to
know how many rain drops fall in one second on a
football field area. The way you could do this is
to actually count the number of rain drops that
fall on one square yard (a tiny fraction of the
entire field) and then multiply by the ratio of
the area of the entire field to 1 square yard.
In this calculation WE USE THE COSMOLOGICAL PRINCIPLE which states that ON AVERAGE any piece of the universe is JUST LIKE ANY OTHER PIECE OF THE UNIVERSE. That is, at a large enough scale, the universe is homogeneous.