The short answer to the title question is that there were twelve, to the best of our knowledge. So why do we so often hear and read, even from Thomas scholars, that there were 13? That takes longer to answer. There are two sources of confusion, one minor, one major. The minor one is a phantom 13th codex that never existed. The major one is that there is something called Codex XIII which, however, is not a codex at all. As it turns out, both of these confusions have the same cause, viz., the early decision of those who dealt with the Nag Hammadi find to call eight unbound papyrus leaves (containing a complete copy of Trimorphic Protennoia) a codex.
With respect to the first, but relatively minor, source of confusion, the Egyptian peasant Muhammad Ali, chiefly responsible for the Nag Hammadi find, said in some interviews that there were 13 books in the jar. He could not have been referring to the so-called Codex XIII, however, since that was in fact a set of loose pages tucked into Codex VI, so he would not have counted that as a book. But did he count at all? As James Robinson wrote in The Secrets of Judas (2007):
"Muhammad 'Ali decided to divide the codices on the spot among the seven camel drivers present. Evidence of only twelve codices survives today. What is called Codex XIII consists of only eight leaves, which were removed from the center of the codex in late antiquity, in order to separate out a tractate inscribed on them, and then laid inside the front cover of Codex VI. These leaves probably would not even have been noticed by the discoverers, much less considered a separate codex. Yet when pressed, Muhammad 'Ali maintained that the number of codices in the jar was not twelve, but thirteen. ... [But] If another codex existed, no trace of it has been brought to light ..." (SJ, pp.39-40, emphasis mine - should be 'a codex')
This much Robinson quotes from his 1979 article in Biblical Archaeologist, but he adds an explanation not in that article:
"Muhammad 'Ali had heard me and others talk of thirteen codices, and so he would naturally speak of thirteen, not recalling what he had counted at the time (if he had counted at all - he was illiterate). In all probability, he was just playing back what he had learned was the 'correct' number." (SJ, p.40)
From Robinson's account, one can see that the cause of both confusions mentioned above was the decision of his team to refer to the unbound tractate in Codex VI as a codex (viz, 'Codex XIII'.) Not only did it confuse Muhammad 'Ali, but it continues to confuse scholars today, to the point where Robinson and others seem to have given up trying to explain it. Robinson's statement in the 1988 edition of The Nag Hammadi Library is admirably accurate:
"The Nag Hammadi library consists of twelve books, plus eight leaves removed from a thirteenth book in late antiquity and tucked inside the front cover of the sixth. These eight leaves comprise a complete text [Trimorphic Protennoia], an independent treatise taken out of a book of collected essays." (p.10)
But in a 1987 video interview, he used the number 13, and even as late as his preface to Marvin Meyer's The Nag Hammadi Scriptures (2007), he wrote:
"The Nag Hammadi Scriptures is a collection of thirteen papyrus codices - bound books, not scrolls - that were buried near the city of Nag Hammadi in Upper Egypt ..."
Whether this wording was a joint decision with Meyer or not, what is meant, when one gets to the bottom of statements such as this, is that "the jar contained 13 things that we've designated 'codices'". Rather than to have to explain the name 'Codex XIII', scholars sometimes simplify the story by ignoring the fact that it isn't a codex, thus avoiding messy details. But messy details can be important. What if the exact number of books that were put into the jar for burial was significant for the jar-packers? What if they specifically wanted there to be 12, and specifically did not want there to be 13? What if they tore the unbound tractate out of its codex and put it into Codex VI because they wanted the tractate, but didn't want there to be a 13th book? (In that case, it would be extraordinarily ironic that modern-day scholars have inadvertently defeated that purpose by calling the unbound tractate a 13th codex, anyway!) We do know that the number 13 came to be considered unlucky by Christians at some point in time. Was it already so among that group at that point in (say around 370)? Even if not, the number 12 would seem to have had a much greater symbolic significance for them, judging from the approving usages of that number in several tractates. In The Apocryphon of John, for example, one reads:
"... these are the twelve aeons that stand before the Child of the Great One, the Self-generated, the anointed, by the will and grace of the Invisible Spirit."
Since Ap.John was evidently regarded as the most important text in the collection - occurring first in 3 of the 12 books - its fondness for numbers may have been both reflection of and influence on those who treasured it. There's also a tractate called "The Acts of Peter and the Twelve Apostles", but information like this from within the NH Library only confirms what we know about the number 12 from other sources as well, namely that it was rich in significant associations, some deriving from others. Twelve was the number of months in the Roman calendar, the number of tribes of Israel, the number of signs of the zodiac, etc. No such significance was attached to the number 13. So it is certainly plausible, at least, to suggest that the number of books in the jar wasn't accidental, and that that is what accounts for the unbound tractate.
What lessons can we draw from all this? Certainly, to be careful what you name something, because you may have to live with that name and its implications forever. (I'm reminded of the unfortunate 2012 decision to call a little fragment of unknown provenance 'The Gospel of Jesus' Wife'.) Secondly, however, when we "dumb down" an account in order to make for a simpler story, we should be careful that some of what we're leaving out isn't important.
Mike Grondin, orig Oct 2006, rev Nov 2013 (minor correction Oct 2014)