Tablebase
From Chesspedia, the Free Chess Encyclopedia.
In chess, a tablebase is a database containing the win/loss status of every possible position of pieces in the endgame. Such a database acts as an oracle for the remainder of the game, providing perfect play. On the winning side, a tablebase will show how to force a win in the shortest possible way; on the losing side, a tablebase will show how to prolong loss as long as possible. Any position that is not a win or loss is a guaranteed draw.
Tablebases are generally limited to 6 pieces on the board and below, because it is currently computationally infeasible to be larger. The 6-piece tablebases factored heavily into the analysis of Kasparov versus The World.
Algorithm
The basic algorithm for creating a tablebase is relatively simple. Optimization and handling the "stateful" cases of en passant and castling are more complicated. (Castling is usually ignored in a tablebase, because games in practice rarely reach the endgame without a king or rook moving.)