Nerd has two connotations, neither of which is very flattering.
The word was first used in Dr. Seuss's book If I Ran the Zoo, published in 1950 where it is simply a name for one of Seuss's many comical imaginary animals; the context is narrator Gerald McGrew's claim that he would collect "a Nerkle, a Nerd, and a Seersucker too" for his imaginary zoo. Another theory of the word's origin is that it is a version of Mortimer Snerd, the name of Edgar Bergen's ventriloquist dummy. Yet another theory is that it comes from Northern Electric Research and Developments where the employees wore pocket protectors with the acronym N.E.R.D. And yet another theory is that it comes from the word "drunk" reversed to "knurd", to illustrate someone who did not drink at parties. It was adopted in the mid-1960s to describe a stereotypical intelligent social recluse, one who usually is the butt of others' jokes.
Today, nerds are often thought of as people who are intelligent, yet socially awkward. The stereotypical nerd image as seen in the mass media and cartoons is a young man wearing thick black glasses (preferably broken and taped up with electrical tape), pocket protectors and dress shirts or clothes that are in general too formal for the circumstances in which they are worn. Nerds generally express an above-normal interest in computers, technology in general, and academic subjects.
Those labelled as nerds in high school are often ridiculed and bullied by more "popular," or more socially adept teens.
The second has been co-opted by computing jargon. Whereas nerds view themselves as technically competent and socially able, geeks are only technically competent. This analysis is often disputed. Although oft mentioned comparisons note that a geek is a lesser nerd.
There may be some regional differences in the use of the words "nerd" and "geek". Some claim that on the North American East coast the word "nerd" is preferred to "geek", and the meanings of the words are switched (see Ellen Spertus's page on The Sexiest Geek Alive). Others on the East coast dispute this, claiming that they have always found "nerd" used disparagingly (and "geek" used in a positive light).
Some self-proclaimed "nerds" use the term to describe any person who is deeply interested in science, technology and/or mathematics.