The word was first used in Dr. Seuss's book If I Ran the Zoo, published in 1950. It was adopted in the mid-60s 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 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. Sometimes, the ridicule reaches the extent that the "nerds" react violently, the most well known incident of which was the Columbine High School massacre.
The second has been co-opted by computing jargon. A nerd is a lesser geek. Whereas geeks view themselves as technically competent and socially able, nerds are only technically competent.
There are some regional differences in the use of the words "nerd" and "geek". It appears that on the North American East coast the word "nerd" is preferred to "geek", and the meaning of the words is switched (see Ellen Spertus's page on The Sexiest Geek Alive).
Some self-proclaimed "nerds" use the term to describe any person who is deeply interested in science, technology and/or mathematics.
See also: "Why Nerds are Unpopular"