Hard spheres are ubiquitous in condensed matter: they have been used as models for liquids, crystals, colloidal systems, granular systems, and powders. Packings of hard spheres are of even wider interest as they are related to important problems in information theory, such as digitalization of signals, error correcting codes, and optimization problems. In three dimensions the densest packing of identical hard spheres has been proven to be the fcc lattice, and it is conjectured that the closest packing is ordered (a regular lattice, e.g., a crystal) in low enough dimension. Still, amorphous packings have attracted much interest because for polydisperse colloids and granular materials the crystalline state is not obtained in experiments for kinetic reasons. A theory of amorphous packings, and more generally glassy states, of hard spheres is reviewed here, that is based on the replica method: this theory gives predictions on the structure and thermodynamics of these states. In dimensions between two and six these predictions can be successfully compared with numerical simulations. The limit of large dimension is also discussed where an exact solution is possible. Some of the results presented here were published, but others are original: in particular, an improved discussion of the large dimension limit and new results on the correlation function and the contact force distribution in three dimensions. The main assumptions that are beyond the theory presented are clarified and, in particular, the relation between static computation and the dynamical procedures used to construct amorphous packings. There remain many weak points in the theory that should be better investigated.