The chemical reactions and pathways resulting in the formation of alkaloids, nitrogen-containing natural products which are not otherwise classified as nonprotein amino acids, amines, peptides, amines, cyanogenic glycosides, glucosinolates, cofactors, phytohormones, or primary metabolite (such as purine or pyrimidine bases).