According to IRC 1001 you generally recognize a gain or a loss when you sell or dispose of property. However, there are a number of exceptions, specifically transfers of property to a corporation.
For example under IRC 351a no gain or loss is recognized if property is transferred to a corporation in exchange for stock in the corporation if immediately after the exchange the person transferring the property in question is in control of the corporation that received ownership of the property.
The intent of IRC 351 I believe is to apply when there is simply a change in the form of ownership of the property in question and you have not really profited or cashed out a loosing investment, which it turns out is a reasonable rule of thumb to use in making a determination as to whether a gain or loss is recognizable upon transfer.
The majority of the nonrecognition transfers of property I have been involved with to date have generally taken place in conjunction with forming a new corporation but these tax code sections also apply to transfers of property made to existing corporations.