text:
Castling

Castling is a move in chess. It consists of moving the king two squares toward a rook on the same and then moving the rook to the square that the king passed over. Castling is permitted only if neither the king nor the rook has previously moved; the squares between the king and the rook are vacant; and the king does not leave, cross over, or finish on a square attacked by an enemy piece. Castling is the only move in chess in which two pieces are moved at once.

Castling with the is called kingside castling, and castling with the  is called queenside castling. In both algebraic and descriptive notations, castling kingside is written as 0-0 and castling queenside as 0-0-0.

Castling originates from the king's leap, a two-square king move added to European chess between the 14th and 15th centuries, and took on its present form in the 17th century. Local variations in castling rules were common, however, persisting in Italy until the late 19th century. Castling does not exist in Asian games of the chess family, such as shogi, xiangqi, and janggi, but it commonly appears in variants of Western chess.

Description
During castling, the king is shifted two squares toward a rook of the same color on the same rank, and the rook is transferred to the square crossed by the king. There are two forms of castling:
 * Castling (short castling) consists of moving the king to g1 and the rook to f1 for White, or moving the king to g8 and the rook to f8 for Black.
 * Castling (long castling) consists of moving the king to c1 and the rook to d1 for White, or moving the king to c8 and the rook to d8 for Black.

Requirements
Castling is permitted provided all of the following conditions are met:
 * 1) Neither the king nor the rook has previously moved.
 * 2) There are no pieces between the king and the rook.
 * 3) The king is not currently in check.
 * 4) The king does not pass through or finish on a square that is attacked by an enemy piece.

Conditions 3 and 4 can be summarized by the mnemonic:

Castling rules often cause confusion, even occasionally among high-level players. Alexander Beliavsky and Viktor Korchnoi both had to consult the arbiter during tournaments on whether castling was legal when the rook was on or passed over an attacked square, Yuri Averbakh once mistakenly thought that Black queenside castling was illegal when b8 was attacked, and Nigel Short once attempted to castle queenside as Black when d8 was under attack (this was not allowed). Illegal castling has also occasionally occurred in serious games between top players (including Gata Kamsky, Viktor Korchnoi, and Richard Réti) when they forgot that the king or rook had previously moved and returned to its home square, and has not always been noticed by the opponent. Yasser Seirawan once even accidentally castled queenside as White with his queen's rook on b1 (which was not allowed), and Alexander Alekhine once "castled his queen" (moving his queen from d1 to b1 and his rook from a1 to c1, which was also not allowed). To clarify:
 * The rook can be under attack.
 * The rook can pass through an attacked square. (White can castle queenside even if Black is attacking b1; Black can castle queenside even if White is attacking b8.)
 * The king can have been in check earlier in the game.

Tournament rules
Under FIDE rules and USCF rules, and enforced in most tournaments, castling is considered a king move, so the king must be touched first; if the rook is touched first, a rook move must be played instead. As usual, the player may choose another legal destination square for the king until releasing it. When the two-square king move is completed, however, the player is committed to castling if it is legal, and the rook must be moved accordingly. The entire move must be completed with one hand. A player who attempts to castle illegally must return the king and rook to their original squares and then make a legal king move if possible (which may include castling on the other side). If there is no legal king move, the touch-move rule does not apply to the rook.

These tournament rules are not commonly enforced in nor commonly known by casual players.

Castling rights
An unmoved king has castling rights with an unmoved rook of the same color on the same rank. In the context of threefold and fivefold repetition, two positions with different castling rights are considered to be different positions.

Example of castling rights
In a 1986 game between Anatoly Karpov and Tony Miles, play continued from the diagrammed position as follows:

 * 22... Ra4 23. Nc3 Ra8 24. Nb5 Ra4 25. Nc3 Ra8 26. Nb5

With his 26th move, Karpov attempted to claim a draw by threefold repetition, thinking that the positions after his 22nd, 24th, and 26th moves were the same. It was pointed out to him, however, that the position after his 22nd move had different castling rights than the positions after his 24th and 26th moves, rendering his claim illegal. As a result, Karpov was penalized five minutes on his clock. After thinking for about ten minutes, Miles decided to agree to a draw anyway (even an incorrect claim of threefold repetition is also a draw offer).

Notation
Both algebraic notation and descriptive notation indicate kingside castling as 0-0 and queenside castling as 0-0-0 (using the digit zero). Portable Game Notation and some publications use O-O for kingside castling and O-O-O for queenside castling (using the letter O) instead. ICCF numeric notation indicates castling based on the starting and ending squares of the king; thus, castling kingside is written as 5171 for White and 5878 for Black, and castling queenside is written as 5131 for White and 5838 for Black.

History
Castling has its roots in the king's leap. There were two forms of the leap: the king would move once like a knight, or the king would move two squares on its first move. The knight move might be used early in the game to get the king to safety or later in the game to escape a threat. This second form was played in Europe as early as the 13th century. In North Africa, the king was transferred to a safe square by a two-move procedure: the king moved to the player's second, and the rook and king moved to each other's original squares.

Various forms of castling were developed due to the spread of rulesets during the 15th and 16th centuries which increased the power of the queen and bishop, allowing these pieces to attack from a distance and from both sides of the board, thus increasing the importance of king safety.

The rule of castling has varied by location and time. In medieval England, Spain, and France, the white king was allowed to jump to c1, c2, d3, e3, f3, or g1 if no capture was made and the king was not in check and did not move over check; the black king might move analogously. In Lombardy, the white king might also jump to a2, b1, or h1, with corresponding squares applying to the black king. Later, in Germany and Italy, the rule was changed such that the king move was accompanied by a pawn move.

In the Göttingen manuscript (c. 1500) and a game published by Luis Ramírez de Lucena in 1498, castling consisted of moving the rook and then moving the king on separate moves.

The current version of castling was established in France in 1620 and in England in 1640. It served to combine the rook's move and the king's jumping move into a single move.

In Rome, from the early 17th century until the late 19th century, the rook might be placed on any square up to and including the king's square, and the king might be moved to any square on the other side of the rook. This was called free castling.

In the 1811 edition of his chess treatise, Johann Allgaier introduced the 0-0 notation. He differentiated between 0-0r (right) and 0-0l (left). The 0-0-0 notation for queenside castling was introduced in 1837 by Aaron Alexandre. The practice was adopted in the first edition (1843) of the influential Handbuch des Schachspiels and soon became standard. In English descriptive notation, the word "Castles" was originally spelled out, adding "K's R" or "Q's R" if disambiguation was needed; eventually, the 0-0 and 0-0-0 notation was borrowed from the algebraic system.

Strategy
Castling is generally an important goal in the opening: it moves the king to safety away from the of the board, and it moves the rook to a more active position (the f-file if castling kingside; the d-file if castling queenside).

The choice regarding to which side one castles often hinges on an assessment of the trade-off between king safety and activity of the rook. Kingside castling is generally slightly safer because the king ends up closer to the edge of the board and can usually defend all of the pawns on the castled side. In queenside castling, the king is placed closer to the center and does not defend the pawn on the a-; for these reasons, the king is often subsequently moved to the b-file. In addition, queenside castling is initially obstructed by more pieces than kingside castling, thus taking longer to set up than kingside castling. On the other hand, queenside castling places the rook more efficiently on the central d-file, where it is often immediately active; meanwhile, with kingside castling, a tempo may be required to move the rook to a more effective square.

Players may forgo castling for various reasons. In positions where the opponent cannot organize an attack against a centralized king, castling may be unnecessary or even detrimental. In addition, in certain situations, a rook can be more active near the edges of the board than in the center; for example, if it is able to fight for control of an open or semi-open file.

Kingside castling occurs more frequently than queenside castling. It is common for both players to castle kingside, somewhat uncommon for one player to castle kingside and the other queenside, and somewhat rare for both players to castle queenside. If one player castles kingside and the other queenside, it is called opposite castling or opposite-side castling. Castling on opposite sides usually results in a fierce fight, as each player's pawns are free to advance to attack the opponent's castled position without exposing the player's own castled king. Opposite castling is a common feature of many openings, such as the Yugoslav Attack.

Tactics involving castling
Tactical patterns involving castling are rare. One pattern involves castling queenside to deliver a : the king attacks a rook (on b2 for White or b7 for Black), while the rook attacks a second enemy piece (usually the king). In the example shown, from the game Mattison–Millers, Königsberg 1926, Black played 13...Rxb2 and resigned after 14.0-0-0+, which wins the rook.

Chess historian Edward Winter has proposed the name "Thornton castling trap" for this pattern, in reference to the earliest known example, Thornton–Boultbee, published in the Brooklyn Chess Chronicle in 1884. Other chess writers such as Gary Lane have since adopted this term.

Another example of tactical castling is illustrated in the diagrammed position from the correspondence game Gurvich–Pampin, 1976. After 1.Qxd8+ Kxd8 2.0-0-0+ Ke7 3.Nxb5, White has won a rook by castling with check and simultaneously unpinning the knight.

Such a double attack can also be made by castling kingside, although this is much rarer. In this position from the blindfold game Karjakin–Carlsen, 2007, the move 19...0-0 threatens to win the rook on h7, as well as 20...Bxg5, when White cannot recapture due to the threat of back rank mate. Black will thus win the g5-knight next move; 20.Rh6 Bxg5 21.Rxg6+ Kh7 22.Rxg5 would not work, as it would be met by 22...Rf1.

Korchnoi vs. Karpov
Viktor Korchnoi, in his 1974 Candidates final match with Anatoly Karpov, asked the arbiter if castling was legal when the castling rook was under attack. The arbiter answered in the affirmative, Korchnoi executed the move, and Karpov resigned shortly after.

Heidenfeld vs. Kerins
Castling occurred three times in the game Wolfgang Heidenfeld–Nick Kerins, Dublin 1973. The third instance of castling, the second one by White, was illegal, as the white king had already moved. The game is as follows:

Averbakh vs. Purdy
In the game Yuri Averbakh–Cecil Purdy, Adelaide 1960, when Purdy castled queenside, Averbakh queried the move, pointing out that the rook had passed over an attacked square. Purdy indicated e8 and c8 and said, "The king", in an attempt to explain that this was forbidden only for the king. Averbakh replied, "Only the king? Not the rook?" Averbakh's colleague Vladimir Bagirov then explained the castling rules to him in Russian, and the game continued.

Edward Lasker vs. Thomas
In the game Edward Lasker–Sir George Thomas (London 1912), White could have checkmated with 18.0-0-0, but he instead played 18.Kd2#. (See Edward Lasker's notable games.)

Prins vs. Day
The diagram shows the final position of the game Lodewijk Prins–Lawrence Day (1968), where White resigned. Had the game continued, Black could have checkmated by castling:

 * 29. Kf6 Qf5+ 30. Kg7 Qg6+ 31. Kh8 0-0-0

(See Lawrence Day's notable chess games.)

Feuer vs. O'Kelly
In the 1934 Belgian Championship, Otto Feuer caught Albéric O'Kelly in the Thornton castling trap. In the position in the diagram, the game continued 10...Rxb2 11.dxe5 dxe5?? 12.Qxd8+ Kxd8 13.0-0-0+, and O'Kelly resigned. Feuer's last move simultaneously gave check and attacked the rook on b2.

Fischer vs. Najdorf
The diagram illustrates the consequences of losing castling rights. Fischer, with the white pieces, played 16.Ng7+ Ke7 17.Nf5+ Ke8. Although all the pieces were now on the same squares, the two positions were not identical because Black, having moved his king, no longer had the right to castle. White now had time to build pressure on the black king without worrying that the king might escape by castling.

Artificial castling
Artificial castling, also known as castling by hand, is a maneuver whereby a player achieves a castled position without the use of castling.

Example of artificial castling
In the first diagram (arising from the Ruy Lopez, Classical Defence):
 * 1. Nxe5 Bxf2+

Black sees that if he plays 1...Nxe5, White responds with 2.d4, winning back the minor piece with a fork and taking control of the center. Instead of allowing this, Black hopes to cause trouble for White by returning the piece while depriving White of the right to castle. White can easily castle artificially, however. For example:
 * 2. Kxf2 Nxe5 3. Rf1

White begins castling artificially.
 * 3... Ne7 4. Kg1 (second diagram)

White has achieved a normal castled position via several moves. With the bishop pair and a central pawn majority, White has a slight advantage.

Castling in chess variants
Variants of Western chess often include castling in their rulesets, sometimes in a modified form.

In variants played on a standard 8×8 board, castling is often the same as in standard chess. This includes variants that replace the king with a different royal piece, as is the case with the knight in Knightmate. Some variants, however, have different rules; for example, in Chess960, the king may move more or fewer than two squares (including none) when castling, depending on the starting position. Former world Fischer Random Chess Champion Wesley So was confused by the castling rules during the 2022 championships, and attempted to illegally castle out of check versus Ian Nepomniachtchi.

Castling can also be adapted to variants with different board sizes and shapes. Some such variants, like Capablanca chess (10×8) or chess on a really big board (16×16), preserve the castling movement of the rooks, meaning that the king moves a different distance along the. In a few variants, most notably Wildebeest chess (11×10), the player may choose to move the king any distance and move the rook accordingly.

Castling sometimes features in chess variants not played on a square grid, such as masonic chess, triangular chess, Shafran's and Brusky's hexagonal chess, and millennium 3D chess. In 5D Chess with Multiverse Time Travel, castling is possible within the spatial dimensions but not across time or between timelines.

Some chess variants do not feature castling, such as losing chess, where the king is not, and Grand Chess, where the rooks have significantly more opening mobility.

In a handicap game with rook odds, the player giving odds may castle with the absent rook, moving only the king.

Chess without castling
Writing in 2019, former world chess champion Vladimir Kramnik proposed a variant of chess without castling. This variant would reduce king safety, theoretically leading to more dynamic games, as it would be considerably harder to force a draw and the pieces would be forced to engage in a mêlée. In 2021, former world champion Viswanathan Anand defeated Kramnik 2½–1½ in a no-castling exhibition match under classical time controls.

Castling in chess problems
Castling features in some chess problems. The earliest known study containing castling was published in 1843 by Julius Mendheim.

Retrograde analysis
Castling is common in retrograde analysis problems. By chess problem convention, if a player's king and rook are on their original squares, the player is assumed to have castling rights unless it can be proved otherwise. In some retrograde analysis problems, the solver (who usually plays White) is required to prove that the opponent has previously moved their king or rook and therefore cannot castle. This is sometimes accomplished by castling or by capturing en passant, thereby disproving other possible game histories.

The diagram shows a mate in two. 1.Rad1 0-0 does not work. The is 1.0-0-0 This demonstrates that the white king has not moved yet and that the rook on d4 must therefore be a promoted piece. Therefore, either the black king or black rook has previously moved to let the white rook off the back rank. Therefore Black cannot castle. After any move by Black, 2.Rd8 is mate.

Novelty problems
Some joke chess problems involve castling with a promoted rook of the opponent's color. In orthodox chess, this would be illegal since the rook would be giving check to the king, but under fairy chess conditions, this might not actually be check.

The diagrammed problem involves castling with an opposing rook under the Koko fairy condition (each piece must end up adjacent to another piece when moving). The solution (Black's move being given first per helpmate convention) is:
 * 1. Bg7 h8=R 2. Bf6 Kg6 3. 0-0 Kh7#

where, after 3.0-0, White's rook is not checking the king; a hypothetical capture of the king would result in the rook not being adjacent to any other piece, which is illegal under the Koko condition.

The allowance of castling with a "phantom rook" in handicap games has also been used in joke problems. Many other joke variations on castling are possible.

Vertical castling
In 1907, C. Staugaard composed a two-mover in which White promotes a pawn to a rook and then castles vertically with the newly promoted rook (placing the king on e3 and the rook on e2), since the rook has not moved. In the position on the right, White plays 1.e8=R, and after the forced move 1...Kxc2 castles vertically with the promoted rook, checkmating Black.

Vertical castling, also known as "Staugaard castling" or "Pam–Krabbé castling", has been used in a few novelty chess problems.

Tim Krabbé's 1985 book Chess Curiosities includes a problem featuring vertical castling, along with an incorrect claim that the problem's 1973 publication prompted FIDE to amend the castling laws in 1974 to add the requirement that the king and rook be on the same rank. In reality, the original FIDE Laws from 1930 explicitly stated that castling must be done with a king and a rook on the same rank (traverse in French). It is unclear whether any historically published sets of rules would technically allow such a move.

Nomenclature
In most European languages, the term for castling is derived from the Persian rukh (e.g. rochieren, rochada, enroque), while queenside and kingside castling are referred to using the adjectives meaning "long" and "short" (or "big" and "small"), respectively.

title: Castling