The formula for gain starts from the basic equations for the circuit.
Using that link's drawing, V2 is the inverting terminal and V1 is the
non inverting terminal, and Vout is the output voltage and RF is the
feedback resistor and Rin is the input resistor and Vin is the input
voltage.
Writing the equation for the voltages of the op amp we get:
Vout=(V1-V2)*AOL
where
AOL is the open loop gain of the op amp (typically 1000 or more).
Now writing the equation for V2 we get:
V2=(Vout-Vin)*Rin/(Rin+RF)+Vin
Now substitute V2 into the equation for Vout and we get:
Vout=(V1-((Vout-Vin)*Rin/(Rin+RF)+Vin))*AOL
Now eliminate the inside parens by distributing the minus sign and we get:
Vout=(V1-(Vout-Vin)*Rin/(Rin+RF)-Vin)*AOL
Now distribute the leftmost minus sign and we get:
Vout=(V1+(Vin-Vout)*Rin/(Rin+RF)-Vin)*AOL
Now distribute the Rin/(Rin+RF) factor and eliminate those parens:
Vout=(V1+Vin*Rin/(Rin+RF)-Vout*Rin/(Rin+RF)-Vin)*AOL
Now distribute the AOL and eliminate those parens:
Vout=AOL*V1+AOL*Vin*Rin/(Rin+RF)-AOL*Vout*Rin/(Rin+RF)-AOL*Vin
Now to explicitly solve for Vout get all terms with Vout to the left side:
Vout+AOL*Vout*Rin/(Rin+RF)=AOL*V1+AOL*Vin*Rin/(Rin+RF)-AOL*Vin
Now isolate Vout:
Vout(1+AOL*Rin/(Rin+RF))=AOL*V1+AOL*Vin*Rin/(Rin+RF)-AOL*Vin
Now divide both sides to get Vout alone on the left side:
Vout=(AOL*V1+AOL*Vin*Rin/(Rin+RF)-AOL*Vin)/(1+AOL*Rin/(Rin+RF))
Now we simplify that equation a little and we get:
Vout=(AOL*RF*V1+Rin*AOL*V1-Vin*AOL*RF)/(RF+Rin*AOL+Rin)
And now we have the equation for Vout, but that is the exact expression
and many times we want to deal with the approximate expression because
it simplifies the math and it still works out ok in practice. To get the
approximate expression we assume that the open loop gain AOL is infinite,
so we take the limit of Vout as AOL approaches plus infinity:
Vout(approximate) = limit [AOL --> +inf]((AOL*RF*V1+Rin*AOL*V1-Vin*AOL*RF)/(RF+Rin*AOL+Rin))
and after taking the limit we get:
Vout(approx)=(RF+Rin)*V1/Rin-Vin*RF/Rin
That's the general approximate equation for Vout, but since for this application
V1 happens to be zero, we can substitute zero for V1:
Vout(approx)=(RF+Rin)*0/Rin-Vin*RF/Rin
and since that eliminates one term that leaves us with the last term only:
Vout(approx)= -Vin*RF/Rin
To get the gain alone we simply divide both sides by Vin and we get:
Vout/Vin= -RF/Rin