The output voltage is the difference between the input voltages times the gain. This is the aim of the configuration shown in figure bellow.
Formula:
Subtraction:
Vout = (R2 / R1) x (V2 - V1)
Where:
Vout is the output voltage in volts (V)
V1 and V2 are the input voltages in volts (V)
R1 and R2 are the resistances in ohm (Ω)
Note: the output voltage must be less than the power supply voltage.