Modified gravity theories have received increased attention lately due to combined motivation coming from high-energy physics, cosmology and astrophysics. Among numerous alternatives to Einstein's theory of gravity, theories which include higher order curvature invariants, and specifically the particular class of f(R) theories, have a long history. In the last five years there has been a new stimulus for their study, leading to a number of interesting results. We review here f(R) theories of gravity in an attempt to comprehensively present their most important aspects and cover the largest possible portion of the relevant literature. All known formalisms are presented -- metric, Palatini and metric-affine -- and the following topics are discussed: motivation; actions, field equations and theoretical aspects; equivalence with other theories; cosmological aspects and constraints; viability criteria; astrophysical applications.