Sun emits radiation in terms of light and heat energy. These radiations are in the form of visible rays, UV rays and Infrared rays. These rays will have to first pass the earth’s atmosphere before reaching the earth’s surface. The ozone layer present in the atmosphere blocks some amount of the ultraviolet rays from reaching the earth surface.
Of the remaining rays reaching the surface part of it are absorbed by the earth and some especially the infrared rays are reflected back into the space. But some gases in the atmosphere trap this heat radiation and re-emits it to the surface which leads to heating up of the environment. This exchange of the incoming and outgoing heat radiation that warms the earth is referred as greenhouse effect and the gases involved in it are called greenhouse gases which mainly include CO2, Methane (CH4), CFCs, Water Vapor etc.
This greenhouse effect is necessary to keep our planet warm. In the absence of this effect the temperature of the earth’s surface would have been -20 to -40 degree celsius. But too much of anything is not good.