This is from wikipedia. Check out the whole article for more information.
The formation of sandstone involves two principal stages. First, a layer or layers of sand accumulates as the result of sedimentation, either from water (as in a river, lake, or sea) or from air (as in a desert). Typically, sedimentation occurs by the sand settling out from suspension; i.e., ceasing to be rolled or bounced along the bottom of a body of water (e.g., seas or rivers) or ground surface (e.g., in a desert or erg). Finally, once it has accumulated, the sand becomes sandstone when it is compacted by pressure of overlying deposits and cemented by the precipitation of minerals within the pore spaces between sand grains.