FEN errors
If the FEN value is invalid, the chessboard uses the default starting position and shows a FEN notation error. Check the FEN string for the common problems below.
Piece placement length
The first FEN field describes the pieces on the board ranks. The board size is detected from this field, so every rank must expand to the same number of squares. The number of ranks defines the board height.
Common problems:
- one rank expands to a different number of squares than the others;
- there are too few or too many ranks for the intended board size;
0is used instead of a positive empty-square number;- multi-digit empty-square numbers are split incorrectly.
// Invalid: the first rank expands to 9 squares, while the other ranks expand to 8.
"rnbqkbnr1/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
// Valid 8x8 board.
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
// Valid 12x12 board.
"qqrnbqkbnrqq/pppppppppppp/12/12/12/12/12/12/12/12/PPPPPPPPPPPP/QQRNBQKBNRQQ w - - 0 1"
Incorrect pieces
Piece placement can contain only valid chess piece letters and empty-square numbers.
Valid piece letters:
- white pieces:
PNBRQK; - black pieces:
pnbrqk; - empty squares: positive numbers such as
1,8, or12.
// Invalid: "x" is not a FEN piece.
"rnbqkbnx/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
// Valid.
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
Incorrect en passant square
The en passant target square is the fourth FEN field. It must be - when there is no en passant target, or a valid board square on rank 3 or 6.
Common problems:
- the square is outside the board, for example
i3; - the rank is not
3or6, for examplee4; - the value is not
-and not a square coordinate.
// Invalid: e4 cannot be an en passant target square.
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq e4 0 1"
// Valid: no en passant target.
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
Incorrect castling
Castling availability is the third FEN field. It must be - or a combination of K, Q, k, and q.
Common problems:
- unsupported letters are used;
- the same castling marker is repeated;
-is combined with castling markers;- the order is ambiguous. Prefer the standard order:
KQkq.
// Invalid: "A" is not a castling marker.
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQAq - 0 1"
// Valid.
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"