The transfer function of the differential amplifier, also known as difference amplifier, can be found in articles, websites, formula tables, but where is it coming from? Why is the differential amplifier transfer function as in the following mathematical relation?

(1) 
where the resistors are those shown in Figure 1.
Figure 1
First, an important remark: This formula applies only for an ideal operational amplifier. This means that the amplifier has a large gain, so large that it can be considered infinity, and the input offset sufficiently small, so that it can be considered zero. Also, the input bias currents are sufficiently small so that they can be considered zero. I was once asked “but what is sufficiently small?” A voltage or current in electronics is considered sufficiently small, when its numerical value is 1/100 or less versus the dominant voltages or currents in the circuit. For example, if the input voltage levels, in the circuit in Figure 1, are around a few volts, and the operational amplifier input offset is millivolts or submillivolts, then we can neglect the input offset and consider it zero.
Having said that, do we need to know this formula by heart? Of course not. All we need to know is how to derive it. This is not difficult at all.
The transfer function can be derived with the help of the Superposition Theorem. This theorem says that the effect of all sources in a linear circuit is the algebraic sum of all of the effects of each source taken separately, in the same circuit. In other words (back at Figure 1), if we remove V1, and replace it with a short circuit to ground and calculate the output voltage, and then we do the same with V2, the output voltage of the differential amplifier is the sum of both output voltages as they were calculated with each source separately.
Let’s first remove V1. R1 cannot be left unconnected, because in the initial circuit there was current flowing through it. Therefore, let’s ground R1 (see Figure 2).
Figure 2
We can see that our amplifier becomes an inverter, which has its noninverting input connected to ground through R1 and R2. Vout2 is given in equation (2).
Read MasteringElectronicsDesign.com: How to Derive the Inverting Amplifier Transfer Function for a proof of this function.
Now let’s remove V2 and ground R3 (see Figure 3).
Figure 3
This is a noninverting amplifier. For an ideal operational amplifier, Vout1 is a function of V, which is the voltage referred to ground at the noninverting input of the operational amplifier.
The resistors R1 and R2 are an attenuator for V1, so that V can be determined as in the following relation.
By replacing V in equation (3), Vout1 becomes:
Now that we have Vout1 and Vout2, and using the Superposition Theorem, Vout is the algebraic sum of Vout1 and Vout2,
which is the differential amplifier transfer function. (Q.E.D.)