Alkaloids are naturally occurring chemical compounds containing basic nitrogen atoms. The name derives from the word alkaline and was used to describe any nitrogen-containing base. Alkaloids are produced by a large variety of organisms, including bacteria, fungi, plants, and animals and are part of the group of natural products (also called secondary metabolites). Many alkaloids can be purified from crude extracts by acid-base extraction. Many alkaloids are toxic to other organisms. They often have pharmacological effects and are used as medications and recreational drugs. Examples are the local anesthetic and stimulant cocaine, the stimulant caffeine, nicotine, the analgesic morphine, or the antimalarial drug quinine. Some alkaloids have a bitter taste.
Alkaloids are usually classified by their common molecular precursors, based on the metabolic pathway used to construct the molecule. When not much was known about the biosynthesis of alkaloids, they were grouped under the names of known compounds, even some non-nitrogenous ones (since those molecules' structures appear in the finished product; the opium alkaloids are sometimes called "phenanthrenes", for example), or by the plants or animals they were isolated from. When more is learned about a certain alkaloid, the grouping is changed to reflect the new knowledge, usually taking the name of a biologically-important amine that stands out in the synthesis process.
The basicity of alkaloids depends on the lone pairs of electrons on their nitrogen atoms. As organic bases, alkaloids form salts with mineral acids such as hydrochloric acid and sulfuric acid and organic acids such as tartaric acid or maleic acid. These salts are usually more water-soluble than their free base form.