Depends what's attached. In CH4 the oxidation number of C is -4, as C is more electrongative than H, and were the compound ionic (which it isn't) it would be [C]4- ; 4[H]+
In CO2 the oxidation number of C is +4, as O is more electrongative than C, and were the compound ionic (which it is not) it would be [C]4+ ; 2
In CH2O (formaldehyde) C is attached to both two H's (less electrongeative than C) and one O (more electronegative than C). Were it ionic it would contain two[H]+ ; one
- 2-, leaving the C atom with no charge. Therefore the oxidation number of C is zero.
Yet in all four compounds the carbon has a valency of four, it forms four bonds.
For this kind of reason the concept of oxidation number is really only useful in simple organic or inorganic compounds, where the elements involved are clearly either electropositive (metals) or electronegative (halogens, oxygen). Here the valencies and oxidation states usually are the same. Thus in CrO3, SO3 and SF6 the oxidation numbers of the central atoms are +6, as are their valencies.