An introduction to "oxidation state"/"oxidation number"
#TL;DR;

Oxidation States are useful tools used in nomenclature, redox chemistry etc.
There are a few simplistic rules to determine the oxidation state of elements in an atom; but they're not applicable to all the cases.
There are instances where the assignment of oxidation state isn't useful, or where the oxidation state is ambiguous.
We're easier off assigning, rounding off or estimating oxidation states ourselves in some cases, such as intermetallic compounds.


##What is an oxidation state?
Oxidation state (OS), or oxidation number, is an integer or decimal number assigned to an element in a chemical species. This assignment follows certain rules and guidelines, to make it a useful tool whenever we need it. Oxidation states can be negative, positive, or zero.
According to Comprehensive definition of oxidation state
(IUPAC Recommendations 2016), p 833:

The oxidation state of an atom is the charge of this atom after ionic approximation of its heteronuclear
bonds.

All those fancy words up there mean that, when you're assigning OS, you take all of the bonds in the species to be completely ionic. No purely ionic compound exists, and even, say, the $\ce{Cs-F}$ bond in $\ce{CsF}$ has some covalent character. So you have to understand that OS does not happen. It doesn't refer to any real-life phenomenon.
##Why do we assign OS's, then?
Oxidation states are a powerful tool for chemists, and save us a lot of headache. You might question &quot;why do we need to give an element a number anyway?&quot; which arises because you usually only learn how to give elements those numbers, but no real-life application becomes necessary or evident.
OS is a tool, and is not the only tool, wherever it's being used. It's like the shovel that digs the ground. You can also do the digging with a spoon. Why do you choose a shovel?
#Assigning OS
##The Basis
The basis of assigning OS, in simpler cases, is just good old electronegativity. There are exceptions where this would not work, but you don't need to worry about them at this stage.
You're usually given the values of electronegativities, and those aren't what you should worry yourself about. There are different scales for measuring electronegativity, and IUPAC recommends the Allen scale because it's the only scale independent of OS.
##OS Assignment Using the (Molecular) Formula
You're given a formula of a compound you've never met, and you're asked to determine the OS of some, or all of the elements present. This is a classic scare if you don't understand what you're doing.

Determine the OS of all the elements in $\ce{H2C2O4}$.

Like most of the problems you face, there are some &quot;unknown&quot; and some &quot;known&quot; values. You need to identify a starting point, go on from there until everything sorts itself out.
Here's what we know: We need to use the electronegativities to find out what the OS's are. O is the most electronegative, C is next, and H is the least electronegative.
Here's what we want to know: We have three OS's here that we need to determine. C, H and O.
As it happens, the elements in the rightmost and leftmost parts of the periodic table are the most and least electronegative elements of all, respectively. So we expect their stance to be more clear: The ones on the left, the alkaline metals, tend to lose electrons and the ones on the right, tend to gain. As a general rule of thumb, the closer an element is to the middle of periodic table, the fuzzier and harder determining its OS is.

Always try to remember the location of the element in the periodic table, and start from one that's the rightmost and/or the leftmost. Don't try to quantify this rule, since it's merely a guideline. Sometimes, deciding the OS of oxygen becomes difficult!
Thus, we would expect oxygen or hydrogen to be easier to determine here. That is the case: the electronegativities tell us that oxygen must have a negative OS, and hydrogen a positive one.
Time to quantify this. You remember from the intro to electronic configurations that O's electronic configuration ends in $\mathrm{2p^4}$, and that if it ended in $\mathrm{2p^6}$, it would've given oxygen a relative amount of stability. It would've done the same here if it could grab the two electrons from the carbon, but in reality, that hasn't happened. But anyway, when assigning OS, you assume that the bonds are ionic, and the oxygen has already stolen carbon's two electrons.
If a neutral oxygen with an electronic configuration ending in $\mathrm{2p^4}$ gains electrons to become one ending $\mathrm{2p^6}$, how many electrons has it gained? Two. Thus, the OS of oxygen in $\ce{H2C2O4}$ is −2.
You can apply the same process for hydrogen. It has only one electron in its neutral form, and it's about to lose it. How many electrons can it lose?
Determining carbon's OS is more tricky. Carbon is in group 14, and it's not obvious what its OS should be. It's the closest element to the middle. Here's a workaround: Instead of trying to find out which OS's carbon can have, we calculate how much is left as carbon's share.
$$\color{green}{\text{The sum of the OS's in the species is equal to the charge} \\ \text{of the species, be it a molecule, an ion etc.}}$$
This is a rule you have probably also met in your textbook. The charge of the species is an indication of excess or lack of electrons, and should definitely affect what OS's we assign to the elements. Why? Because OS is itself some form of counting electrons.
($\Rightarrow$ if they're just counting electrons, why do we see fractional oxidation states? See OS Assignment Using the Lewis Structure below)
$\ce{H2C2O4}$, oxalic acid, is a neutral molecule. So the sum of OS's must equal zero. Note that we count hydrogen twice, because two hydrogens have two electrons in neutral form, and they will lose two electrons. Likewise, four oxygens will, in a hypothetical purely ionic oxalic acid, gain eight electrons overall.
$$\begin{equation}
2(+1) + 2(\mathrm{OS}_\ce{C}) + 4(-2) = 0 \\
\mathrm{OS}_\ce{C} = +3
\end{equation}$$
##Most Common Patterns in the OS of elements
If you consider all the possible species that can be synthesized, there are great many bizarre trends and anomalies in OS assignment. Refer to the Further Reading section to learn more about them.
However, for most educational purposes, OS's for a number of elements follow simple guidelines worth mentioning:

Fluorine's OS is always −1 (except in $\ce{F2}$ itself).
Halogens below fluorine typically adapt a −1 OS as well, but always check when there are more electronegative elements such as fluorine and oxygen present.
Alkaline metals adopt a +1 OS.
Alkaline earth metals adopt a +2 OS.
You're almost always better off determining the OS of transition metals using the sum rule.
If oxygen is not the leftmost element present, or there are alkaline and alkaline Earth metals present, don't start by assigning an OS to oxygen.
If there are any of the elements in guidelines 1–4; don't start by assigning an OS to hydrogen.


Determine the OS of all the elements in $\ce{NaO3}$.

There are only two possibilities: Start from Na, or start from O. Both are, as said, in left and right parts of the periodic table. So which?
If we take oxygen, and assign the &quot;normal&quot; OS, −2, we see that Na has to be +6 because the sum should equal zero. Something doesn't sound right. As guideline 6 says, we shouldn't start from O when there's Na present in the compound. So we take the other route.
$$\begin{equation}
+1 + 3(\mathrm{OS}_\ce{O}) = 0 \\
(\mathrm{OS}_\ce{O})= \frac{-1}3
\end{equation}$$
###Check your understanding
Find the OS of all the elements in these compounds:

1.$\ce{NaAlF6}$  2. $\ce{C2O2F2}$
3. $\ce{C8O8}$ 4. $\ce{Au2O3}$

##OS's That Don't Exist
The upper bound for OS's that you will meet is +7 for some manganese $(\ce{MnO4-})$, or chlorine $(\ce{ClO4-})$ compounds. OS's more than that are only found in exotic compounds. Thus, if you get a, say, +9 OS, you should start doubting the route you took.

Determine the OS of W in $\ce{H4W2O13}$.

Three possible starting points. We rule out tungsten because it's the nearest to the middle. Of the other two, hydrogen would lose 1 electron, and oxygen would tend to gain two. Right?
Well, if you solve it for tungsten, considering the neutral overall nature of the compound, you'll get an OS of +11! That's definitely not right, since the highest observed OS is +10 (See Further Reading). This could only mean one thing, since hydrogen can't adapt another OS or tungsten would have an even higher OS. This means that some of the oxygens are in the form of peroxides, superoxides etc.
Had we known that the structure of the compound, more elaborately written, is $\ce{(H2O)(O)(O2)2WOW(O2)2(O)(H2O)}$, we wouldn't have made the mistake of thinking all the oxygens have the normal OS of −2.
Hence, it becomes necessary to be able to deduce OS from structures.
##OS Assignment Using the Lewis Structure
At times you need to determine OS in an electron dot diagram, or Lewis structure. This is sometimes useful/needed over determining from the molecular formula because

either the molecular formula doesn't give us the whole picture (see below), or
it gives us impossible answers or no way to go further, like the tungsten compound's case, or
it's already what the examiners gave us!

Determining OS from Lewis structure is even easier than deducing it from the molecular formula, because you already see the bonds. It's the same process in the IUPAC definition above: Ionic approximation

The electrons in a bond go count as the more electronegative atom's. (There are exceptions to this, see Further Reading)
The electrons in a bond between the same atoms are shared equally. So in a $\ce{C-C}$ bond, each C atom gets one electron from the bond.
The OS of each element is the number of valence electrons minus the sum of lone pairs and electrons it gains from bonds.

A good example used to illustrate this is acetone.

Determine the OS of all the elements in acetone, $\ce{C3H6O}$.

The answer is in the spoiler below (no peeking ಠ_ಠ):

 $\mathrm{OS}_\ce{O} = -2, \mathrm{OS}_\ce{C} = \frac {-4}3, \mathrm{OS}_\ce{H} = +1$

There's one oxygen in acetone, and it's bonded to the carbon:

Assigning the rules, we get


$\ce{C1}$ has four valence electrons, but there are &quot;seven electrons around it&quot;. Both electrons from the $\ce{C-H}$ bond belong to carbon. Thus, $4 - 7 = -3$.
$\ce{C2}$ has four valence electrons, but only two electrons are around it. One from of each of the two $\ce{C-C}$ bonds. That makes $4 - 2 = +2$.
$\ce{C3}$ is just like $\ce{C1}$, $\mathrm{OS} = -3$.

##Fractional OS's
Didn't we say earlier that OS assignment is some kind of counting electrons? Then how come we encounter fractional OS?
Now you know the answer. Some elements in some compounds show two different oxidation states, and when computing the OS from the molecular formula, you actually compute the average OS. None of the carbons in acetone have an OS of $\frac {-4}3$.
Familiar examples of this 'average' OS are carbon in acetic acid, which is computed to be zero but is in fact −3 and +3, and iron magnetite, which is $\frac 83$.
##Further Reading
The school lessons are over, but the fun is actually just about to start. This is the part where, you know, you see what you've been taught isn't accurate. Read on if you're interested. It might get confusing for first-timers.
###Be Liberal in Thinking
OS is a useful concept. Unfortunately, it's hypothetical. There's this mindset that there should only be one OS for each element in a compound out there. That's simply not the case.
$\ce{S2O3^2-}$, thiosulfate anion, is one such compound where the two approaches we just introduced produce conflicting results. The average $\mathrm{OS}_\ce{S}$ is +2 for sure, but is it +5 and −1, or +6 and −2?
Turns out, studies are conflicting on this matter. The final say here is provided by IUPAC recommendations linked above:

###5.3 Nominal OS
In systematic descriptive chemistry, OS is used to sort out compounds of an element; in electrochemistry, it represents the electrochemically relevant compound or ion in Latimer and Frost diagrams of standard (reduction) potentials. Such purpose-oriented OS may differ from the OS per definition and are termed nominal, or more specifically “systematic” or “electrochemical”.


Consider thiosulfate, the $\ce{S2O3^2−}$ anion: The sulfur–sulfur
bond is practically a single bond, which yields OS = +5 for the central S and −1 for the terminal S atom by both algorithms. The electrochemical OS of sulfur in thiosulfate is their average, +2. On the other hand, a systematic OS of +6 may be chosen for the central S atom, as if the sulfur–sulfur bond were approximated ionic, to emphasize the similarity of the peripheral O and S atoms obtaining OS = −2 as in sulfate.

##Exceptions
These are the cases where the methods above don't reliably work in determining OS:

The most glaring example is when the more electronegative atom is bonded reversibly as a Lewis acid.
We originally introduced electronegativity as the basis to decide OS. Truth is, the real basis is the energy level of molecular orbitals, and this, in most of the cases, corresponds to the more electronegative atom getting all the fish. It's difficult and/or impractical to use complicated MO schemes to determine OS, so we stick to electronegativities.
In the case of Lewis-acid ligands, however, this backfires and gives us the opposite of the correct answer.
Non-innocent ligands are ligands whose OS is ambiguous because they're very redox-active. This article does a nice job of explaining $\ce{H2}$ and nitrosyl non-innocent ligand briefly (§ 10 &amp; 11).
Nominal OS's; like thiosulfate above.
Metallic compounds; there are some obvious cases such as TiO, but it gets more complicated – Source
Intermetallic compounds, such as Zintl phases, where it's safe to assume an OS of 0 for redox purposes or compounds with delocalization over different atoms  – Source (§ 13)
Compounds with a close electronegativity such as Se and C in $\ce{Se-C}$ bonds or H and P in $\ce{H3PO3}$. – Source

##Exotic OS
These are compounds whose certain elements demonstrate unusual OS's:

Alkalides, which are salts containing alkali metal anions with an OS of −1. Lithides are currently not known, but some kalides and natrides are stable in room temperature.
The highest known OS belongs to Ir in $\ce{[IrO4]+}$ which is +9, and potentially +10 for Pt in $\ce{[PtO4]^2+}$. The lowest known OS is −5 for boron in Zintl phases. – Wikipedia
Platinum hexafluoride is a strong oxidizing agent that can oxidize $\ce{O2}$, giving dioxygenyl, with an unusual OS of $+\frac 12$ for O.
Alkaline earth metals are observed to show unusual +1 OS in some complexes. – This article reports the synthesis of complexes with Mg–Mg bonds.

##Useful Links
[1]: List of Oxidation States of Elements
[2]: High-valent Iron
[3]: Using OS to analyze redox reactions; a tutorial
[4]: ChemGuide OS tutorial
&lt;Under construction . . . Probably&gt;
&lt;......&gt;