From a column at The Guardian:
On a Sunday in the spring of 1981 Douglas Adams was typing a letter. "Dear Ken," he began. "Your book was really very useful to me . . ." The thank-you letter from Adams to Australian writer Ken Welsh, author of Hitch-hiker's Guide to Europe, continues, "[One evening in 1971] I got frantically depressed in Innsbruck . . . When the stars came out I thought that someone ought to write a Hitchhiker's Guide to the Galaxy...Reposted from 2011 in recognition of Towel Day.
For many followers the question of "Why 42?" has been an enjoyable part of the enigma. Adams kept his magic in the tin, never revealing (other than to his friend Stephen Fry, who claims he'll take the secret to his grave) the full story... Adams was ever meticulous in his choice of words and numbers, and it's safe to say it wasn't a random pick.
As the book's title suggests, Adams, like most authors, was not afraid to borrow, and there are revealing similarities between Welsh's Hitch-hiker's Guide to Europe and The Hitchhiker's Guide to the Galaxy. One of these provides perhaps the most intriguing explanation for "Why 42?". As you may remember Adams had Deep Thought perform a little expectation management and say: "You're really not going to like it" before revealing the Ultimate Answer.
Curiously, Hitch-hiker's Guide to Europe had told of visitors to the UK searching for family roots finding "the answer a little disappointing" – after traveling around the world in search of "the solution to the most puzzling question of all". A coincidence, perhaps . . . but this coincidence is on page 42.