The Sun's magnetic field is generated by a magnetic dynamo within the Sun.