Slang words tend to be fanciful creations of uncertain origin, and nerd is certainly no exception. There are a number of theories on its beginnings, so roll for initiative and let's sort through them.
In Dr. Seuss's (Theodore Geisel's) 1950 composition of whimsy, If I Ran the Zoo, we have what seems to be the first occurrence of nerd in print:
And then, just to show them, I'll sail to Ka-troo
And bring back an It-kutch, a Preep and a Proo,
A Nerkle, a Nerd, and a Seersucker, too!
In October of the following year, Newsweek carried an article about the latest slang that includes the word nerd. "In Detroit," it notes, "someone who once would be called a drip or a square is now, regrettably, a nerd, or in less severe cases, a scurve."
It's not until the 1960s, however, that nerd (as well as its alternate spelling nurd) takes off and starts appearing more frequently in running text (as opposed to lists of slang). Over the decade and into the '70s, print usage of nerd became truly abundant. It could be said, then, that nerd established colloquial usage around that time.
If indeed nerd was borrowed from Dr. Seuss, (and someone convincingly explains how it transfers from a book of children's rhyme to teenage slang within a year), its connotation of "squareness" may have arisen partly from the Nerd's decidedly uncool appearance in Dr. Seuss's illustration—not to mention, the juxtaposition of Nerd with Seersucker (seersucker being a rather uncool fabric). On the other hand, it can be argued that Dr. Seuss's Nerd appears as more of a disapproving grouch than a "drip" or "square," which, then, leaves us wondering: if it's not the nonsense coinage Nerd, what inspired the formation and popularization of the slang term? Did the good Doctor really make it up or did it originate before the publication of his book?
Another character whose name has been mentioned as a possible source of the word is Mortimer Snerd, a ventriloquist's dummy created by Edgar Bergen. Modeled on a country bumpkin, Snerd perhaps reminded listeners of a "drip" (someone who is looked on as tiresomely or annoyingly dull), and, therefore—according to Newsweek in 1951—a nerd. Snerd's drippy qualities were magnified by his sophisticated foil, the dummy Charlie McCarthy. Bergen's radio show was popular from the late 1930s through the 1950s, and it's possible that Seuss had Snerd in mind when he wrote the rhyme—but the claim is unverifiable.
Theories on the origin of nerd also include wordplays. For example, it has been conjectured that nerd is an alteration of nerts, an early 20th-century slang word applied to things that were extraordinary (as in "Your idea is the nerts") or used as an interjection like nuts.
Another idea is that nerd developed in college slang from knurd—a coinage formed by spelling drunk backwards. The implication is that a "knurd" would rather study than party—in other words, the "knurd" is a sober individual (the opposite of a drunken one). Unfortunately, no hard evidence has surfaced in support of knurd as the source. Another theory related to the spelling nurd is that it is a euphemism of turd, which can refer to a contemptible person—but, again, proof is lacking.
Gradually, the "socially inept but brainy" connotation became associated with the term (perhaps the nerds themselves influenced it in self-defense). By the 1980s, the image of the nerd as someone who has a knack for computers and sports a "nerd pack" (a plastic penholder) in his shirt pocket and unsightly glasses is fully realized.
In time, the revolutionary digital age gave prestige to the studious nerd who sought to harness the power of binary code and had no time to waste on socializing. With its emergence, the connotation of the word nerd was also revolutionized.
Though they resembled the slide rule-toting nerds of the precomputer age, these specimens had been transformed by the power of the microchip into electronic wizards.
— Frank Rose, Science, November 1982"In a way, you could say that we're more film nerds than film critics," said a member of the group named Mason Wiley, who told us that he graduated from Columbia Journalism School in 1978…. "We're the sort of people who go to see a film at the Museum of Modern Art and rush to get a seat in the front row."
— The New Yorker, 18 Feb. 1980
Nowadays, being labeled a nerd is something often worn with pride. It's a word that implies that a person possesses a depth of knowledge in a particular area, whether it's in science, books, words, vast multimedia franchises, gaming, etc. Today, a nerd is brainy and a bit geeky, but that's pretty cool.