Weapons, body armor and shields can have sockets. 15% of the ones that drop have some. The smith can also cut a socket for gold, and each socket costs more than the one before.
A one-handed weapon or a shield can have up to 2 sockets. A two-handed weapon or body armor can have up to 3. The smith's Extra socket upgrade lets him cut one more than that.
You can put a gem into a socket anywhere, even in the dungeon, for free. Only the smith can take a gem out, for gold, and you keep the gem and the item.
Gems come in three grades. The smith fuses 3 gems of the same kind and grade into 1 of the next grade, for gold.