
The king is the most important piece in the game of chess.
The object of the game is to threaten the opponent's king so that escape is not possible (i.e. checkmate).
If a player's king is threatened with capture, it is said to be in check, and the player must remove the threat of capture on the next move. If this cannot be done, the king is said to be in checkmate, resulting in a loss for that player.
Players cannot make any move that places their own king in check.
Kings move (and capture) by moving 1 square in any direction (vertical, horizontal, and diagonal).
There is a special move that the king has, called castling!

The king can move 1 square in any direction.

The king can be used to attack as well! In this example, the king attacks both the bishop and the knight.

The king can move to d6, attacking both the enemy bishop and enemy pawn. Double attack!

Since the king is the most valuable piece, you often want to keep your king behind your pawns. This is a very common position you will see in many chess games. This king has castled (explained below).
Castling
Castling is a move in the game of chess involving a player's king and either of the player's original rooks.
It is the only move in chess in which a player moves two pieces in the same move, and it is the only move aside from the knight's move where a piece can be said to "jump over" another.
Castling consists of moving the king two squares towards a rook on the player's first rank, then moving the rook to the square over which the king crossed.
Castling can be done on the Kingside (annotated as “0-0”) or Queenside (annotated as “0-0-0”)
Castling can only be done IF:
The king has never moved
The rook involved has never moved
The squares between the king and the rook involved are unoccupied
The king is not in check
The king does not cross over or end on a square attacked by an enemy piece

The king before it castles.

The king can castle kingside (to the right) or queenside (to the left). Queenside is toward to queen's side.

Castle kingside. The king moved 2 squares to the right. The rook jumps over the king and lands next to it.

Castle queenside. The king moved 2 squares to the left. The rook jumps over the king and lands next to it. Notice the difference between kingside and queenside castling.
Examples when your king cannot castle!
Castling can only be done IF:
The king has never moved
The rook involved has never moved
The squares between the king and the rook involved are unoccupied
The king is not in check
The king does not cross over or end on a square attacked by an enemy piece

White cannot castle because the knight is in the way.

White cannot castle because the enemy bishop attacks the square that the king will land on.

White cannot castle because the enemy rook attacks a square that the king will pass through.

White cannot castle next turn because the rook just moved. Even though the rook is in the correct position, it has already moved.