Forums

The Standard Structure of a PGN

Sort:
Ian_Rastall

This is where you can find the standard for PGN files. This site is archiving the original text, which is from '94.
http://www.saremba.de/chessgml/standards/pgn/pgn-complete.htm

Each line (without any line endings, such as semi-colons) looks like this:

[TAG "VALUE"]

If you work with PGNs, you certainly know that. The most important takeaway from the standard is the notion of the Seven Tag Roster. These are the first seven lines -- as you might imagine -- and they need to be in order, with nothing stuck in there. Here's how it looks:

[Event "World Chess Championship 2018"]
[Site "London ENG"]
[Date "2018.11.10"]
[Round "2"]
[White "Carlsen, Magnus"]
[Black "Caruana, Fabiano"]
[Result "1/2-1/2"]

You can pick up from other PGNs some of the other tags, although the standard lists them.

After all your headers you leave a blank line, then the move list, in lines broken at 80 characters. It does appear that there is a space after every period, rather than something like 28.Kxf7, or something like that. It would be 28. Kxf7. Here is a complete PGN, in the form that I'm pretty sure is as close to standard as possible:

[Event "World Chess Championship 2018"]
[Site "London ENG"]
[Date "2018.11.10"]
[Round "2"]
[White "Carlsen, Magnus"]
[Black "Caruana, Fabiano"]
[Result "1/2-1/2"]
[EventDate "2018.11.09"]
[ECO "D37"]
[Opening "Queen's Gambit Declined: Harrwitz Attack"]
[WhiteElo "2855"]
[BlackElo "2791"]
[PlyCount "97"]

1. d4 Nf6 2. Nf3 d5 3. c4 e6 4. Nc3 Be7 5. Bf4 O-O 6. e3 c5 7. dxc5 Bxc5 8.
Qc2 Nc6 9. a3 Qa5 10. Rd1 Rd8 11. Be2 Ne4 12. O-O Nxc3 13. bxc3 h6 14. a4 Ne7
15. Ne5 Bd6 16. cxd5 Nxd5 17. Bf3 Nxf4 18. exf4 Bxe5 19. Rxd8+ Qxd8 20. fxe5
Qc7 21. Rb1 Rb8 22. Qd3 Bd7 23. a5 Bc6 24. Qd6 Qxd6 25. exd6 Bxf3 26. gxf3 Kf8
27. c4 Ke8 28. a6 b6 29. c5 Kd7 30. cxb6 axb6 31. a7 Ra8 32. Rxb6 Rxa7 33. Kg2
e5 34. Rb4 f5 35. Rb6 Ke6 36. d7+ Kxd7 37. Rb5 Ke6 38. Rb6+ Kf7 39. Rb5 Kf6
40. Rb6+ Kg5 41. Rb5 Kf4 42. Rb4+ e4 43. fxe4 fxe4 44. h3 Ra5 45. Rb7 Rg5+ 46.
Kf1 Rg6 47. Rb4 Rg5 48. Rb7 Rg6 49. Rb4 1/2-1/2

Some of this is self-explanatory. Rounds are often broken down by the order in which the various games were played. (This can often be found at the official site for the particular tournament or match.) So you might have [Round "3.2"]. PlyCount, i.e. "play count", is the number of half-moves in the game. It is *not* the number of moves doubled. If black doesn't play in the last move, then double the number of moves and subtract one, obviously.

ECO is the code for the opening, which can be found at the wiki in the List of chess openings. ECO stands for Encyclopedia of Chess Openings. At that page you can find what a code corresponds to easily by using CTRL+F in your browser. The three-character country code that the PGN standard uses (the IOC country code, used by the International Olympic Committee) can be found near the end of the standard.

Hope that is useful to someone looking for info on the subject.