FEN in Chess: Forsyth-Edwards Notation Field by Field

FEN, short for Forsyth-Edwards Notation, is a standard way of writing one chess position as a single line of text. It records where every piece stands, whose turn it is, and the few extra facts needed to continue the game. Engines, databases and web boards use it to pass positions around.

The standard starting position

The initial position reads:

rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1

A FEN record has six fields separated by single spaces.

  1. Piece placement. The ranks are listed from rank 8 down to rank 1 and separated by slashes. Inside a rank the squares run from the a-file to the h-file. White pieces are capital letters (P, N, B, R, Q, K), Black pieces are lowercase, and a run of empty squares is written as a digit from 1 to 8. In the example, rnbqkbnr is Black’s back rank and 8 is an empty rank.
  2. Active colour. The letter w means White is to move, and b means Black.
  3. Castling availability. K and Q stand for White castling on the kingside and queenside, k and q for Black. A hyphen means nobody can castle. KQkq is all four rights still available.
  4. En passant target. The square a pawn just jumped over, or a hyphen if there is none. The starting position has none.
  5. Halfmove clock. The number of half-moves since the last capture or pawn advance, used for the fifty-move rule.
  6. Fullmove number. It starts at 1 and goes up after each move by Black.

A second example

After 1.e4 the record becomes rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1. The pawn now stands on e4, so the fourth rank holds 4P3, meaning four empty squares, the pawn and three more empty squares. It is Black’s move, and e3 is the en passant target. The commonly cited version records that square even when no capture is possible, though a later revision records it only if a legal en passant capture exists.

Origin

The Scottish journalist David Forsyth devised the piece-placement part in 1883 for newspaper use, and it carried no other data. In 1993 Steven J. Edwards extended it for computers as part of the Portable Game Notation standard, adding the other fields.

Where it appears

The article on the mate in 64 gives the FEN of its position, and a mate problem is typically shared that way. Engines and databases read the same line, and the page on computer chess describes them.

Following the fields through a short game

The four-move sequence 1.e4 c5 2.Nf3 shows how the last three fields change. After 1.e4 the record ends b KQkq e3 0 1. Black answers 1…c5, a pawn move, so the halfmove clock stays at 0, the fullmove number rises to 2 because Black has just moved, and the en passant target becomes c6: rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 2. Then White plays 2.Nf3. A knight move is neither a capture nor a pawn advance, so the clock climbs to 1, the en passant field returns to a hyphen, and it is Black’s turn again: rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2.

Two details of the placement field are worth seeing in that last string. The digit 2 in pp1ppppp marks the single empty d7 square, and 5N2 places the knight on f3 by counting five empty squares from the a-file, then the knight, then two more empty squares. Digits never appear next to each other, since two adjacent empty runs are always written as one larger number.

The en passant field has two conventions

In the older and more widely used reading, the target square is written after every two-square pawn advance, whether or not an opposing pawn could take it. The Chess Programming Wiki adds that the square can only lie on rank 3 or rank 6. X-FEN, introduced by Reinhard Scharnagl in 2003, records the square only when an opponent pawn could really capture en passant, and a newer revision of the standard moved in the same direction. The difference matters when two programs compare positions as text: the same position can produce two different strings, and a position hash built from the string may then differ as well.

The halfmove clock and the fifty-move rule

The fifth field exists for the fifty-move rule. Under the FIDE wording a player to move may claim a draw once the last 50 moves by each player, so 100 halfmoves, have passed without a pawn move or a capture. Any pawn move or capture sets the clock back to zero. A clock reading of 100 therefore means a claim is available, and the clock is the only part of the record that tracks it. The rule’s automatic cousin is the 75-move rule, under which the arbiter ends the game as drawn after 75 moves by each player without a pawn move or capture, with no claim needed. A checkmate delivered on the 75th move still counts as a win.

Chess960 and the castling field

The letters KQkq assume one rook on each side of the king. In Chess960 both rooks can stand on the same side, and the letters become ambiguous. Shredder-FEN, introduced by Stefan Meyer-Kahlen in 2005, replaces them with the file letters of the castling rooks, capitals for White and lowercase for Black, so the traditional setup would read AHah. X-FEN keeps the familiar letters wherever they are unambiguous. Most graphical interfaces and engine protocols accept Shredder-FEN.

What a FEN record leaves out

A FEN string describes one position and nothing about how it arose. It cannot say how often a position has occurred, so threefold repetition cannot be judged from it, and it carries no record of draw offers. Extended Position Description, or EPD, covers more ground. EPD, developed by John Stanback and Steven J. Edwards, shares its first four fields with FEN and writes the halfmove clock and fullmove number as optional operations named hmvc and fmvn. Portable Game Notation uses FEN for games that do not start from the standard array: the SetUp and FEN tags in the game header hold the string. A plain text file that contains only FEN records should use the extension .fen.

Questions

Does FEN record the moves that led to a position?

No. The string holds the arrangement of pieces and a few state flags, nothing else. Two different move orders that reach the same arrangement with the same rights give the same string, apart from the clock values.

Why does a FEN string for the first move already have e3 in it?

After 1.e4 the pawn has passed over e3, and the commonly used convention writes that square even though no Black pawn can capture there. Variants such as X-FEN leave it as a hyphen unless a legal en passant capture exists.

What does the halfmove clock count?

It counts halfmoves, one move by one side, since the last capture or pawn move. The count is there for the fifty-move rule: 50 moves by each player equal 100 halfmoves.

How does FEN handle Chess960 castling?

The plain KQkq letters fail when both rooks lie on one side of the king. Shredder-FEN names the rook files instead, and X-FEN keeps the familiar letters even in Chess960 positions.

What is the difference between FEN and EPD?

The first four fields are the same. FEN then adds a halfmove clock and a fullmove number, while EPD puts those two values into optional operations and allows further operations after the position.