Twilight
is caused by the scattering of sunlight by the upper
layers
of the Earth's atmosphere. There are different definitions
of twilight.
Astronomical twilight begins at sunset (ends at sunrise)
and ends (begins) when the Sun's center is 18 degrees
below the horizon. Civil twilight begins (ends) when
the Sun's center is 6 degrees below the horizon; nautical
twilight begins (ends)
when the Sun's center is 12 degrees below the horizon.