What is the oxidation number of carbon, and how do you derive this number?

It is usually +4, but can be +2 (in carbon monoxide). It can be -1, as in a metal carbide (K2C2, and CaC2). One derives this number from the observed molecular formulas of existing chemical compounds).