Why do I sound bad in recording but good while singing

A common misconception that most amateur singers have is - I sound good when I am singing , but horrible when I listen to my own recording. How can we explain this phenomenon. Is it due to the fact that recording equipment is not good,?  or something changes mentally when you record ? or is it even true that one can sound good while not recording. ?

First time when I recorded my own voice , i felt the same. Its horrible, i dont think I sing so bad, it must be about the device or speakers. However it was none of that. Its just that I was naive singer and not really a trained playback singer. 
1.The question to ask yourself is , when you are singing are you analyzing or focusing on singing the song physically?. Most likely you are determined to deliver the song , the words, the melody pitch and what you hear back you feel that you sound good, but in reality that may not be the case. You can hear your own bone vibrations which others cannot hear. Certain percentage of the sound that you hear in real time is heard through bone, which can distort things. So you may be disillusioned to believe that you sound rich and deep. Only after you have recorded you are analyzing your own voice and sound.  Your mistakes and flaws become more visible to you and it may sound bad.  This just means that you need to practice more towards becoming a professional.
USE this TRICK -  Without recording if you would like to know how you sound, then you should put your hands behind the ears such that your palms are your extended ears, like mickey mouse. Curve your hand towards front. Now you can sing. What you hear now is very near to how others listen to your sound. 
2. Another explanation to this may have to do with the recording equipment. In case you do not agree with above point then try to do a studio recording once to check if you really sound as good as you sing. Professional recording requires many things like good room, a high-end microphone, a quality pre-amp. After you have recorded, you need compression, equalization and similar software processing before it can be called a professional recording. You cannot compare your home recording with other singers who have recorded in studio. The fact they have recorded in studio gives them an edge over you. Unless you have a fully professional studio setup at your home. Acoustics in the room you are recording may be unpleasant.  
Whenever you hear a sublime vocal recording, its almost certainly done in a studio with absorptive acoustic panels set up at all the main reflection points. This absorbs the sound rather than bouncing it back at you.  An untreated room will always give unpredictable characteristics to your recorded sounds. You can try the following to improve the sound in your room. To remove echo or reverb, try small room with furniture , carpets, etc to absorb the sound.
3. Your own mental image of your voice is also a contributing factor. Everyone has their own psychological perception of their own self which impacts the way you perform and even more important is the way you hear yourself afterwards. However you are the best judge of your imperfections. No one can point out the flaws in your voice better than what you can when you are listening to your own recording. I generally listen to my own recordings after few days and not immediately after recording. This way I am not comparing myself against my own singing which I heard when i was recording but comparing myself to the original song.