The first book was compiled in 1722 during Bach's appointment in Köthen; the second book followed it twenty years later while he was in Leipzig. Both were widely circulated in manuscript editions, but printed copies were not made until 1801.
Each book contains twenty-four pairs of preludes and fugues. The first pair is in C major, the second in C minor, the third in C-sharp major, the fourth in C-sharp minor, and so on. The rising chromatic pattern continues until every key has been represented by one prelude and one fugue.
Bach recycled some of the preludes and fugues from earlier sources: the 1720 Klavierbüchlein for Wilhelm Friedemann Bach, for instance, contains versions of eleven of the preludes. The C sharp major prelude and fugue in book one was originally in C major - Bach just added a key signature of seven sharps to convert it into the required key.
The work indicates that Bach was at this time using some sort of musical tuning system that allowed all keys to be played in tune (this is opposed to meantone temperament, for example, where some keys sound out of tune). For a long time it was supposed that this system was equal temperament, but modern scholars suggest instead it was some form of well temperament.
The first complete recording of the Well-Tempered Clavier was made by Edwin Fischer between 1933 and 1936.