# What causes our Sun to oscillate around its mean Galactic orbit?

It's good old Newtonian gravity! The plane of the galaxy can be approximated as a disk made up of stars and gas, with a density $\rho(|z|)$, that decreases with absolute distance $|z|$ from the plane.

If you were to assume that the Sun was close enough to $z=0$ and that the radial variation in $\rho$ was negligible enough to treat the disk as an infinite plane (this is not bad, the amplitude of the Sun's motion is only about 10% of the radial scale length of the disk density), then you could construct a little cylinder through the plane, with one face at $z=0$, where $g=0$, and use Gauss's law for gravity to estimate the gravitational acceleration at height $z$. $$ g(z) \simeq -4\pi G \int_0^{z} \rho(z)\ dz$$

Now $\rho(z)$ approximates to an exponentially decaying function with a scale height of maybe 200-300 pc. If we are closer to $z=0$ than that, then the density can be roughly said to be a constant $\rho_0$. Putting this into the equation above, we see that $$g(z) =-4\pi G\rho_0 z.$$ But this is simple harmonic motion with an angular frequency $\sqrt{4\pi G\rho_0}$.

The density of the disk near the Sun is estimated to be 0.076 solar mass per cubic parsec (Creze et al. 1998). Using this value, we get an *approximate* predicted oscillation period up and down through the disk plane of 95 million years.

Note added: The previous paragraph is the reverse of what is actually done - the dynamics of stars in the solar vicinity are used to estimate the density in the plane. However, just counting up stars and estimating the contribution of gas does give a similar result - and in the process, illustrates that the contribution of dark matter to the density of the disk is very small.

The plane where the Sun and most of the Milky Way are comfined to is neither a plane nor a disk: it is a dense, matter filled section with non-zero width. This means this "disk" also generates a gravitational potential that traps the Sun. In a way, we can say that the Sun has its galactic orbit centered both at the galactic centre and its planar oscillations centred at the galactic "disk". If this approximated disk had a constant density and the Sun were never perturbed in non-planar directions, then the orbit would indeed be confined to a plane; but matter is non-uniformly arranged within the galaxy and this anisotropy provides the non-planar perturbation needed to create an harmonic motion around the galactic plane not only for our Sun, but (at least theoretically) for all celestial bodies.

I feel like the existing answers make the explanation seem too complicated, so I'll add a simple explanation.

Imagine "throwing" a new star into the galaxy, aiming for the orbit to be approximately (but NOT exactly) along the galactic plane. Would you expect the orbit to magically get locked into the galactic plane? Of course not--that would violate conservation of momentum. Would you expect it to forever continue in its own plane? Of course not--that's only expected for a spherical mass, and the galaxy isn't a spherical mass. The closer parts of the galaxy to the star will pull the star toward them too, and hence you get a wobble.