We describe the construction of a multiphase equation of state for carbon at extreme pressures based on ab initio electronic structure calculations of two solid phases (diamond and BC8) and the liquid. Solid-phase free energies are built from knowledge of the cold curves and phonon calculations, together with direct ab initio molecular-dynamics calculations of the equation of state, which are used to extract anharmonic corrections to the phonon free energy. The liquid free energy is constructed based on results from molecular-dynamics calculations and constraints determined from previously calculated melting curves, assuming a simple solidlike free-energy model. The resulting equation of state is extended to extreme densities and temperatures with a Thomas Fermi-based free-energy model. Comparisons to available experimental results are discussed.