Pokemon GO Battles - Attack and Defense Damage Formula and Mechanics

How damage is calculated in Pokemon GO

In Pokemon GO battles, the aim of a battle is to defeat the opponent (in gyms or raids). You do so by dealing damage. 


Damage is affected by the attacking Pokemon's attack, which is calculated with this formula:
Attack = (BaseAttack + AttackIV) ∗ CPM
where CPM is the CP Multiplier which is a fixed number corresponding to the Pokemon level.

Damage is affected by the defending Pokemon's defense, which is calculated with this formula:
Defense = (BaseDefense + DefenseIV) ∗ CPM
where CPM is the same as above.

Amount of damage taken before fainting is the HP shown on the Pokemon info screen which is calculated with this formula:
HP = Floor((BaseStamina + StaminaIV) ∗ CpM)
where CPM is the same as above, and Floor is to round down.

And finally, the amount of damage is calculated as such:
Floor(½ ∗ Power ∗ (Att/Def) ∗ STAB ∗ Effectiveness) + 1

Power is power of the attacking move used.
Att and Def are calculated above.
STAB is the Same Type Attack Bonus (of 1.2) which is awarded when the attacking Pokemon is of the same type as the type of the move used. Eg. A Vaporeon (water Pokemon) using Hydro Pump (a water move).
Effectiveness is the bonus (or penalty) dependent on the type of move used and the type of the defending Pokemon. It can range from 0.36 to 1.96. See chart below.
Floor would round down and +1 would ensure that the minimum damage is 1.

Type Effectiveness

Type effectiveness plays a huge role in battle since a super effective move can effectively double your damage output. Type effectiveness can stack on Pokemon with dual types.

Type effectiveness stacking:
"Immune" Ineffective Neutral Effective
x0.51 x0.714 x1.0 x1.4
"Immune" x0.51 x0.51² x0.36414 x0.51 x0.714
Ineffective x0.714 x0.36414 x0.714² x0.714 x1.0
Neutral x1.0 x0.51 x0.714 x1.0 x1.4
Effective x1.4 x0.714 x1.0 x1.4 x1.4²

Type effectiveness chart:

For single type defending Pokemon, it is straight forward to just use the second chart.
For dual type, find the value for each of the type and multiply them.

Attack enough times and deal enough damage to remove all the HP from the defending Pokemon and you have won the battle.