A realistic description of partially-ionized matter in extreme thermodynamic states is critical to model the interior and evolution of the multiplicity of high-density astrophysical objects. Current predictions of its essential property, the ionization degree, rely widely on analytical approximations that have been challenged recently by a series of experiments. Here, we propose a novel ab initio approach to calculate the ionization degree directly from the dynamic electrical conductivity using the Thomas-Reiche-Kuhn sum rule. This Density Functional Theory framework captures genuinely the condensed matter nature and quantum effects typical for strongly-correlated plasmas. We demonstrate this new capability for carbon and hydrocarbon, which most notably serve as ablator materials in inertial confinement fusion experiments aiming at recreating stellar conditions. We find a significantly higher carbon ionization degree than predicted by commonly used models, yet validating the qualitative behavior of the average atom model Purgatorio. Additionally, we find the carbon ionization state to remain unchanged in the environment of fully-ionized hydrogen. Our results will not only serve as benchmark for traditional models, but more importantly provide an experimentally accessible quantity in the form of the electrical conductivity.