How do oysters form pearls?

Oysters and many other types of mollusks that create pearls line the inside of their shells to create a soft layer called the nacre. The nacre acts like a raincoat for the oyster and helps to protect the soft tissues of the animal. Sometimes, the oyster gets irritated and the nacre starts lining somewhere other than the shell, like a grain of sand stuck in the oyster's shell. The nacre builds until a round "pearl" forms around the irritant.