The riboflavin biosynthesis in bacteria was analyzed using comparative analysis of genes, operons and regulatory elements. A model for regulation based on formation of alternative RNA structures involving the RFN elements is suggested. In Gram-positive bacteria including actinomycetes, Thermotoga, Thermus and Deinococcus, the riboflavin metabolism and transport genes are predicted to be regulated by transcriptional attenuation, whereas in most Gram-negative bacteria, the riboflavin biosynthesis genes seem to be regulated on the level of translation initiation. Several new candidate riboflavin transporters were identified (impX in Desulfitobacterium halfniense and Fusobacterium nucleatum; pnuX in several actinomycetes, including some Corynebacterium species and Streptomyces coelicolor, rfnT in Rhizoblaceae). Traces of a number of likely horizontal transfer events were found: the complete riboflavin operon with the upstream regulatory element was transferred to Haemophilus influenzae and Actinobacillus pleuro-pneumoniae from some Gram-positive bacterium; non-regulated riboflavin operon in Pyrococcus furiousus was likely transferred from Thermotoga; and the RFN element was inserted into the riboflavin operon of Pseudomonas aeruginosa from some other Pseudomonas species, where it had regulated the ribH2 gene.