The word itself was originally a contraction of the (now archaic) 'pundigrion'. This latter term is thought to have originated from 'punctillious', which itself derived from the italian 'puntiglio' (meaning "a fine point").
Although there are several varieties of puns, there are two main linguistic methods for creating them:
The compound pun is one in which multiple puns are colocated for additional and amplified effect. The best example of this is the following story: A woman who had three sons who emigrated from Ireland to the USA. They prospered and soon became the owners of a large cattle ranch. They weren't however sure what to call it so they wrote back to their mother advice. She sent a one-word reply on a postcard: Focus. Puzzled, they wrote back for an explanation. Her response was (wait for it): "It's where the sons raise meat". (sun's rays meet)
Numerous pun formats exist, see also:
Tom Swifty
Spoonerism
Knock-knock joke
Shaggy dog story
Daffynition
Transpositional puns
For related wordplay see also:
Palindrome
Anagram
Mondegreen