Abstract Codon usage bias refers to the nonequal usage of synonymous codons. This phenomenon is fundamentally important in biology as it is jointly shaped by mutation, genetic drift, and natural selection, and influences translation rate, decoding accuracy, and mRNA stability. However, popular tools for codon usage bias analysis are not flexible nor efficient enough and fail to incorporate recent advancements in this field. To address these issues, we developed the Codon Usage Bias Analysis in R (cubar) package. Cubar is highly modular and can calculate common codon usage indexes in a user-friendly manner. In addition, it can perform sliding-window analyses of codon usage, assess differential usage between gene sets, and optimize user-provided genes based on the codon usage of a target organism. Furthermore, cubar is highly efficient and can analyze millions of coding sequences within a few minutes on a laptop.