Forsyth–Edwards Notation (FEN)

This one is for all you chess lovers out there.

Imagine you're in the middle of a game of chess and you feel like recording the current position so you can maybe (over)analyze it later (and cry yourself to sleep for making so many blunders 🙈). Sure, there is a standard Algebraic notation for listing all the moves played during the game, so theoretically, you could just repeat all of them. Yeah right... maybe if you're into masochism.. 😓 cause there is a much better way: say hello to FEN, short for Forsyth-Edwards Notation.

So what is this FEN thing and how do we benefit from it? Well, for starters - it's a one-liner.
Yup, single line of text represents current position but also contains all the relevant game data:

  • who plays next
  • if castling & en passant are still possible
  • count of halfmoves & fullmoves
Not to mention time-saving since every modern chess software has the ability to import/export FENs, making it super-easy to be shared among nerds.

Let me make it clear with an examle:

Example 1

This particular position would have the following FEN:

rq2kbr1/2p2pp1/1p1pn2p/p2Np2P/4P1P1/2QP1P2/PPP3B1/R1B2RK1 w q - 5 17

In order to analyze it, lets split it into smaller logical-groups by using empty space as a delimiter: 
  1. rq2kbr1/2p2pp1/1p1pn2p/p2Np2P/4P1P1/2QP1P2/PPP3B1/R1B2RK1
  2. w
  3. q
  4. -
  5. 5
  6. 17
Group 1 ("rq2kbr1/2p2pp1/1p1pn2p/p2Np2P/4P1P1/2QP1P2/PPP3B1/R1B2RK1") represents current pieces and their position. If you look closely, you'll notice that it consists of 8 parts separated by a single slash ("/"). Each part corresponds to a single rank (row) starting from the upper-left corner (square A8).
Numbers represent count of consecutive empty squares, lowercase letters - black pieces, and uppercase - white pieces:
  • "p" stands for pawn
  • "r" for rook
  • "n" for knight ("k" would make more sence but it's already reserved for the king - guess who's the boss)
  • "b" for bishop
  • "q" for queen
  • "k" for king.
In other words, this combination should be read as follows:
  • r = black rook on A8
  • q = black queen on B8
  • 2 = 2 empty squares (C8, D8)
  • k = black king on E8
  • b = black bishop on F8
  • r = black rook on G8
  • 1 = 1 empty square (H8)
  • / = switch to the next rank (rank 7)
  • 2 = 2 empty squares (A7, B7)
  • p = black pawn on C7
  • 2 = 2 empty squares (D7, E7)
  • p = black pawn on F7
  • p = black pawn on G7
  • 1 = 1 empty square (H7)
  • / = switch to the next rank (rank 6)
  • 1 = 1 empty square (A6)
  • p = black pawn on B6
  • 1 = 1 empty square (C6)
  • p = black pawn on D6
  • n = black knight on E6
  • 2 = 2 empty squares (F6, G6)
  • p = black pawn on H6
  • / = switch to the next rank (rank 5)
  • p = black pawn on A5
  • 2 = 2 empty squares (B5, C5)
  • N = white knight on D5 (notice the uppercase for white)
  • p = black pawn on E5
  • 2 = 2 empty squares (F5, G5)
  • P = white pawn on H5
  • etc.... you probably got it by now
Group 2 represents an active color a.k.a. who moves next:
  • b = black
  • w = white, in our case
Group 3 is reserved for castling rights. Again, lowercase letters are reserved for black player and uppercase letters for white:
  • K = white may castle kingside
  • Q = white may castle queenside
  • k = black may castle kingside
  • q = black may castle queenside (as in our case)
  • - = neither side may castle
E.g. "Kkq" would mean that the white can castle only kingside, but the black can do both kingside & queenside castling.
Group 4 defines which player may perform en passant capture by marking the en passant target square. E.g.: if white pawn moves from square A2 to A4, the target square would be A3 because this is the square black pawn would go to when capturing the white.
In our case none of the players may perform en passant capture.

Group 5 - the number of halfmoves (moves since the last capture or pawn advance) for both players combined. This is relevant only when fifty-move rule is implemented.
In our case, count of halfmoves is 5.

Group 6 - similar to previous group, this number represents the fullmoves - count of completed turns during the game which increments every time black ends its turn (in our example 17).

That wasn't so hard, right? 🙃
Here are some more examples:

Example 2
FEN: 3r4/6Q1/2ppk2p/2pNp1pP/2P1P1P1/3P1P2/6B1/1R4K1 w - - 1 40

Example 3
FEN: 5k2/1R4r1/8/2pPp2P/2P1B1P1/3P2Q1/7K/8 w - - 12 52