Sky appears blue because sunlight is scattered in the earth's atmosphere and out of all wavelenghts, blue one is scattered the most. During sunset and sunrise, the angle of incidence of sunlight changes to almost 0 or pi, due to which the amount of scattering faced by sunlight increases. Also the density of atmosphere decreases with height, and hence light rays suffer total internal reflection. Red wavelengths having the least frequency, suffer minimum scattering (higher the wavelength, lesser the scattering) and have maximum penetration power. Further more, we can see the sun a few minutes before and after the actual rIsing and setting , again due to TIR. Now during sunrise, the first wavelengths that reach us are the red ones while during sunset they are the last ones. Hence the difference in the color transition during sunrise and sunset.