Rusting on an iron material
Rust consists of hydrated iron(III) oxides Fe2O3·nH2O, iron(III) oxide-hydroxide (FeO(OH), Fe(OH)3.

The rusting of iron is an electrochemical process that begins with the transfer of electrons from iron to oxygen. The rate of corrosion is affected by water and accelerated by electrolytes. The key reaction is the reduction of oxygen:

$$\ce{O2 + 4 e- + 2H2O -&gt; 4OH-}$$

The following redox reaction also occurs in the  presence of water and is crucial to the formation of rust:

$$\ce{2Fe2+ + 0.5 O2 &lt;=&gt; 2 Fe3+ + O2−}$$

Additionally, the following multistep acid-base reactions affect the course of rust formation:

$$\ce{Fe2+ + 2 H2O &lt;=&gt; Fe(OH)2 + 2H+}$$

$$\ce{Fe3+ + 3 H2O &lt;=&gt; Fe(OH)3 + 3 H+}$$

as do the following dehydration equilibria:

$$\ce{Fe(OH)2 &lt;=&gt; FeO + H2O}$$

$$\ce{Fe(OH)3 &lt;=&gt; FeO(OH) + H2O}$$
$$\ce{2 FeO(OH)  &lt;=&gt; Fe2O3 + H2O}$$

From the above equations, it is also seen that the corrosion products are dictated by the availability of water and oxygen. With limited dissolved oxygen, iron(II)-containing materials are favoured, including FeO and black lodestone (Fe3O4). High oxygen concentrations favour ferric materials with the nominal formulae Fe(OH)3-xOx/2. 

Thus you can actually calculate the value of x (water of hydration) in the compound. Hope this works

Credits: Chemical formula of rust