  The second data release of the Gaia mission contained astrometry and
photometry for an incredible 1,692,919,135 sources, but how many sources did
Gaia miss and where do they lie on the sky? The answer to this question will be
crucial for any astronomer attempting to map the Milky Way with Gaia DR2. We
infer the completeness of Gaia DR2 by exploiting the fact that it only contains
sources with at least five astrometric detections. The odds that a source
achieves those five detections depends on both the number of observations and
the probability that an observation of that source results in a detection. We
predict the number of times that each source was observed by Gaia and assume
that the probability of detection is either a function of magnitude or a
distribution as a function of magnitude. We fit both these models to the 1.7
billion stars of Gaia DR2, and thus are able to robustly predict the
completeness of Gaia across the sky as a function of magnitude. We extend our
selection function to account for crowding in dense regions of the sky, and
show that this is vitally important, particularly in the Galactic bulge and the
Large and Small Magellanic Clouds. We find that the magnitude limit at which
Gaia is still 99% complete varies over the sky from $G=18.9$ to $21.3$. We have
created a new Python package selectionfunctions
(https://github.com/gaiaverse/selectionfunctions) which provides easy access to
our selection functions.
