"The answer to this is very simple. It was a joke. It had to be a number, an ordinary, smallish number, and I chose that one. Binary representations, base thirteen, Tibetan monks are all complete nonsense. I sat at my desk, stared into the garden and thought '42 will do' I typed it out. End of story."
But of course nobody is an entirely reliable narrator, and certainly not the author of The Guide so... Maybe?
(Edit: I see a peer respondent already linked it, but I'll leave this anyway)