The origin of the Earth's magnetic field has been a puzzle for millennia, and only in the last hundred years has an answer emerged, one that is still being refined. When it was realized that the geomagnetic field had to be produced dynamically within a liquid iron layer deep within the Earth, the "dynamo problem" arose. The essential resolution of this problem came through computational and theoretical research in magnetohydrodynamics (MHD). The primary challenge in this research was, and still is, the mathematical modelling and numerical simulation of the nonlinear dynamics of a turbulent, electrically conducting fluid. I will review historical progress in understanding the Earth's magnetic field, as well present more recent theoretical and numerical results. Although the focus here is a geophysical one, these results may also be relevant for understanding the magnetic fields of other planets, as well as of the sun and other stars.