FEN (.fen)


    • Standard notation for describing positions of a chess game.
    • FEN is an acronym for ForsythEdwards Notation.
    • A single FEN string describes one state of the chess game.
    • A FEN file often stores a number of positions described with a FEN string.
    • ASCII format.
    • First developed by Scottish journalist David Forsyth; later extended by Steven J. Edwards.
    • FEN strings are used in PGN files to describe the initial position of a game.

Import & Export

  • Import["file.fen"] imports a FEN file, returning graphics showing the positions.
  • Import["file.fen",elements] imports the specified elements.
  • See the following reference pages for full general information:
  • Importimport from a file
    CloudImportimport from a cloud object
    ImportStringimport from a string
    ImportByteArrayimport from a byte array

Import Elements

  • General Import elements:
  • "Elements" list of elements and options available in this file
    "Summary"summary of the file
    "Rules"list of rules for all available elements
  • Game elements:
  • "ActivePlayer"player who moves next
    "FENStrings"FEN string for the move
    "MoveNumber"the move number of the game
    "PositionRendering"a Graphics rendering of the position
  • Import by default uses the "PositionRendering" element for the FEN format.
  • Move numbers should not necessarily correspond to the actual number of the move in the game. Typically, 0 means an unknown move number.
  • Overall file element:
  • "PositionCount"number of positions stored in the file


  • Elements that involve rendering a chessboard take the following options:
  • "BoardOrientation"Automaticon which side of the board to place white pieces
    "Icons"Automatica set of icons to use for chess pieces
    "SquareColors"Automatica list of two colors for light and dark squares


open allclose all

Basic Examples  (1)

Render a chessboard from a FEN string:

Scope  (1)

List available Import elements:

Import Elements  (8)

ActivePlayer  (2)

See which player is to move in the given position:

Get the active player in the 4th position in the sample FEN file:

FENStrings  (1)

Get all positions from a FEN file as FEN strings:

Get the last 5 positions:

MoveNumber  (1)

Extract move number from a FEN string:

PositionCount  (1)

Get number of positions listed in a FEN file:

PositionRendering  (2)

Render position described by a FEN string:

Render positions 5 to 8 from a FEN file:

Summary  (1)

Get a summary of a FEN file:

Import Options  (5)

"BoardOrientation"  (3)

Render a position from black's perspective:

Render a position with white pieces on the left side of the board:

By default, Import displays white pieces at the bottom:

"Icons"  (1)

Use a custom set of icons for kings and pawns:

"SquareColors"  (1)

Specify custom colors for chessboard squares:

Properties & Relations  (2)

FEN strings are often used in PGN files to store starting positions:

Import can produce FEN strings for any position that occurred in a game from a PGN file:

Possible Issues  (1)

Even though technically incorrect, FEN strings without move numbers are accepted by Import:

FEN strings without information about player to move, castling rights or en-passant square are not accepted: