§101 of the Patent Act states that patentable inventions must be "useful."  The utility requirement is so basic that it is rarely an issue in obtaining or contesting a patent. After all, since obtaining a patent is an expensive process, it would be irrational to patent a useless invention. Similarly, if a patented invention is useless, then no one would is likely to contest the patent's validity in an attempt to gain the legal right to produce the same invention. There are conditions where the utility requirement can become an issue, however.
In addition to the utility requirement of §101, there is also a requirement under §112 to show that the invention actually works.  In general, if there is a known and beneficial use for an invention (or the result of a process), then utility will exist.
These days, the §101 utility requirement helps to prevent speculative patenting. Utility becomes a problem when people attempt to patent inventions that they think will be useful in the future, but have no use now. The best example of this is in chemical patents. A process for making a compound with no known use is not patentable, even if a use could be discovered in the future.  In the field of computer science, the incorporation of a mathematical algorithm in a piece of computer software can satisfy the utility requirement, if the patent doesn't come into conflict with the prohibition against patenting laws of nature. 
§112, however, adds to general utility the requirement that the invention do what the inventors claim it does. A patent application is required to describe the invention in a way that allows other people "skilled in the art... to make or use the [invention]."  If a patent does not give usable direction on how to use the invention, then the patent is invalid. In addition, the application must disclose the "best mode" of using or "carrying out" the invention. The purpose of the "best mode' requirement is to keep inventors from revealing an inferior version of the invention to the PTO and to the public, while using the patent to gain exclusive rights over a better version. An inventor who fails to disclose the best mode may be subject to charges of inequitable conduct, and may be unable to enforce her patent later on. In the development of the laser, several court battles ensued over the patents, one of which dealt with the §112 disclosure requirements. Gordon Gould developed a method, called "Q-Switching", for boosting the power output of a laser, before the laser itself had been developed, and applied for a patent. Later, Robert Hellwarth developed a laser, and also developed the Q-Switching method. Hellwarth also applied for a patent. The resulting competition between the two patent applications ended with the court stating that Gould did not sufficiently describe the utility of his invention, because he didn't adequately explain how to make his invention.