Quantum contextuality is one of the fundamental notions in quantum mechanics. Proofs of the Kochen-Specker theorem and noncontextuality inequalities are two means for revealing the contextuality phenomenon in quantum mechanics. It has been found that some proofs of the Kochen-Specker theorem, such as those based on rays, can be converted to a state-independent noncontextuality inequality, but it remains open whether this is true in general, i.e., whether any proof of the Kochen-Specker theorem can always be converted to a noncontextuality inequality. In this paper, we address this issue. We prove that all kinds of proofs of the Kochen-Specker theorem, based on rays or any other observables, can always be converted to state-independent noncontextuality inequalities. Besides, our constructive proof also provides a general approach for deriving a stateindependent noncontextuality inequality from a proof of the KS theorem.