Metadynamics is a powerful technique for enhancing sampling in molecular dynamics simulations and reconstructing the free-energy surface as a function of few selected degrees of freedom, often referred to as collective variables (CVs). In metadynamics, sampling is accelerated by a history-dependent bias potential, which is adaptively constructed in the space of the CVs. Since its first appearance, significant improvements have been made to the original algorithm, leading to an efficient, flexible, and accurate method that has found many successful applications in several domains of science. Here, we discuss first the theory underlying metadynamics and its recent developments. In particular, we focus on the crucial issue of choosing an appropriate set of CVs and on the possible strategies to alleviate this difficulty. Later in the second part, we present a few recent representative applications, which we have classified into three main classes: solid-state physics, chemical reactions, and biomolecules.