OK, so here is how it works :
When you lose troops, 30% are lost forever, and 70% are put in the infirmary for revival. They then disappear from there after 7 days if you don't revive them before.
When your troops get killed defending your city, 10% of the previously quoted 70% are eligible for free revival. 10% is for a level 6 infirmary of course, so here use your actual free revival percentage instead.
WARNING : all the numbers are always rounded to the neareast integer value for each step, so sometimes, they can get rounded down to 0.
This also works for your losses : since the quantity of your troops that are killed is proportional to the attacker's offense to your defense ratio, your losses can sometimes get rounded down to 0 and you can lose none of some units.
Example :
You lose 10 units of the same kind (it's a very important point : each of them is treated separately, so take the roundings in account).
7 of them will end up in your infirmary.
If your free revival percentage is 9%, then it means 9% of 7 = 0.63 rounded up to 1 will be available for free revival (you do have to enter the infirmary and click on them, it's not automatic !), and 6 will be available for revival at 50% of their market cost. The 3 other ones are dead for good in the battle.
Now if your 10 units are actually 5 each of two different kinds, then roundings will disadvantage you instead of advantaging you :
70% of 5 is 3.5, rounded up to 4 in the infirmary (here you're advantaged by the numbers), then 9% of 4 is 3.6, rounded down to 0 -> you have no free revival for any of your two kinds of troops.
Is that clear now ? :)