Just to think about this is mind boggling. But how do scientist get these numbers? What technology/system/theory do they they use?
The way it works is as follows. We do detailed studies of stars in the solar neighbourhood. This establishes the local density of stars and the mix of masses they possess (called the stellar mass function). We compare that with the mass function of clusters of stars and note that to first order it appears invariant.
We can then triangulate the problem in various ways: we can make a model for the stellar density of the Galaxy, assume it all has the same mass function and hence get a number of stars. The model may be based on crude light-to-mass conversions, but more often would be based on deep surveys of the sky - either narrow pencil beam surveys from HST, or broader surveys like SDSS, The key is to be able to count stars but also estimate how far away they are. This is highly uncertain and relies on some assumptions about symmetry to cover regions of our Galaxy we cannot probe.
Another method is to count up bright objects that might act as tracers of the underlying stellar population (eg red giants), compare that with the number of giants in our well-studied locale, and from this extrapolate to a total number of stars, again relying on symmetry arguments for those bits of the Galaxy that are distant or obscured by dust.
A third way is to ask, how many stars have lived and died in order to enrich the interstellar medium with heavy elements (a.k.a. metals). For example, it turns out there must have been about a billion core-collapse supernovae to create all the oxygen we see. If we assume the mass function is invariant with time and that supernovae arise from stars above 8 solar masses, then we also know how many long-lived low-mass stars were born with their high-mass siblings and hence estimate how many stars exist today.
The number, whether it be 100 billion or 300 billion is no more accurate than a factor of a few, but probably more accurate than an order of magnitude. The main issue is that the most common stars in the Galaxy are faint M dwarfs,that contribute very little light or mass to the Galaxy, so we really are relying on an extrapolation of our local knowledge of these objects.
The number of galaxies problem is easier, though the number is less well defined. We assume that on large scales the universe is homogeneous and isotropic. We count up how many galaxies we can see in a particular area, multiply it up to cover the whole sky. The number must then be corrected for distant faint galaxies that cannot be seen. The difficult here is that we are looking into the past and the number of galaxies may not be conserved, either through evolution or mergers. So we have to try and come up with a statement like "there are n galaxies in the observable universe today that are more luminous than L". I think this number is certainly only an order of magnitude estimate.
It's a matter of statistics.
Scientists take a small amount of the space (let's say 1 second of arc). They look at it carefully with strong telescopes, and count all the stars and galaxies they see. Then, they extrapolate that number at the total visible space.
Of course they can compute several spots of the space and make an average count.
Since the number is extrapolated, that's why it doesn't really matter if it is 100 billion or 300 billion of stars. The goal is to have an order of magnitude as pointed by Moriarty.