When Apple first revealed the Touch ID system, the company described a "secure enclave" within the A7 chip which stores sensitive fingerprint data. Now thanks to two patent applications detailed by Patently Apple, the mechanics of this secure enclave have been explained.
Images of fingerprints are never stored in the secure enclave or elsewhere. Fingerprint map input from the Touch ID sensor is processed and stored using a kind of encryption. For security when unlocking the iPhone, MacRumors explains that "the enclave only allows fingerprints to be checked against known valid ones, not the other way around."
Of course, Apple never transfers fingerprint data to iCloud or any other servers. In fact, the secure enclave isn't accessible by iOS software on the iPhone 5s. Patently Apple explains in more detail how Touch ID is kept secure:
Apple's invention includes a process of collapsing the full [finger] maps into a sort of checksum, hash function, or histogram. For example, each encrypted ridge map template can have some lower resolution pattern computed and associated with the ridge map. One exemplary pattern could be a histogram of, e.g., the most common angles (e.g., a 2 dimensional (2D) array of common angles). The exemplary pattern could include in each slot an average value over a respective vector of the map...Numerous other exemplary embodiments are also possible, and any other exemplary pattern calculation can be used, where the exemplary pattern includes enough associated information to narrow the candidate list, while omitting enough associated information that the unsecured pattern cannot or cannot easily be reverse engineered into a matching texture.
Another patent application detailed the individual parts that make up the Touch ID hardware system. Details such as the stainless steel ring which detects the user's finger, and the sapphire lens designed to protect the fingerprint sensor are described. Interestingly, the documents also mention an external fingerprint scanning accessory using the same technology.