The beautiful symmetry of a total solar eclipse happens because —by pure chance— the sun is 400 times larger than the moon, but is also 400 times farther from Earth, making the two bodies appear the exact same size in the sky.
The sun is about 400 times farther from Earth than the moon and has a diameter about 400 times larger than the moon. As a result, both the sun and moon (near perigee) appear to be the same size in the sky, allowing the moon to perfectly block out the sun and cast a shadow on Earth during a total eclipse.