In closed loop (negative feedback) configuration of a OP AMP the input voltages are same that means the differential voltage is zero Vd=(V1-V2)=0 ,then how we obtain the gain? where the output is come from?
The differential voltage is only zero in an ideal world. It is a useful approximation in modeling operational amplifier circuits. Consider, for example, a simple operational amplifier circuit with a gain of 100. If the input voltage is 10 millivolts, the output voltage will be 100 times greater or 1 volt. Assume that the open loop gain of the operational amplifier is 100,000. That means that the voltage across its inputs would be 1 volt/100,000 or 10 microvolts which is 1000 times smaller than the input voltage. Under those conditions, it is reasonable to model the differential voltage as zero.
"Inputs are equal voltage" is only an approximation.
As we often make opamp circuits with gains in the 10s, and the opamp itself has a gain in the 100,000s, we tend to approximate the opamp gain to "infinite", which makes the inputs "equal".
If we do an exact analysis (as sometimes we have to do), then a finite (but still very large) opamp gain yields finite differences between the input voltages, even if they are in the micro-volts.
As @Mattman944 says, we guess an answer to your question. This answer addresses where the output comes from.
The most simple equivalent of an opamp is a voltage-controlled voltage source - a two-port model having two input terminals, and two output terminals. For a high-gain opamp, the output terminal voltage is many thousands of times larger than input terminal voltage. LTSpice simulator includes such a device:
However, a real opamp requires at least one DC power source, sometimes two:a +DC and a -DC voltage source. The simple "E" model has no power source.
A proper opamp output pin can swing almost to the limit of the DC voltage(s) of the power source and no more, unlike the simplest "E" model, whose swing is unlimited.
Most opamp circuits must deliver current from the output pin that will flow into a load, and into the feedback resistors. Of course current flows in a loop, part of which is inside the opamp. The DC power source(s) is part of this current loop. Any current delivered from the opamp output pin also flows through one (or the other) DC power source.
When Vin is applied the output matches the current to drive Vin- towards 0 differential input as fast as the slew rate allows.
The result is a gain of the resistor ratios sharing the same current through R1,R2 as the input is much higher impedance so we ignore input current to Op Amp unless the resistors are mismatch then compute input offset voltage when needed.
Above is shown for a single supply with Vref on Vin+, half the supply. But for a split supply, it can be 0V.
Your question is a little vague, people are guessing where your lack of understanding is. My guess and therefore my answer is different.
An op-amp by itself isn't that useful, it usually needs additional peripheral components. These components determine the operational characteristics.
For an ideal op-amp analysis, assume that zero current flows into the inputs, and assume that the output adjusts itself so that the inputs are at the same voltage. With these constraints, use circuit analysis to determine the behavior.
Long time ago I had the same dilemma. If the V2-V1=0, then how the op-amp generates its output? Input diff is ZERO, so the op-amp should know nothing and shouldn't be able to output any varying signal, right?
There are three flaws in this, all come from various oversimplifications.
1) as others said, input difference is never really zero. It's always a bit less or a bit more than zero. This small real difference allow the op-amp to know whever to swing its output up or down, pretty important thing.
2) the op-amp is never alone. In the problem description I just wrote, it looks like the op-amp gets the input and it's the whole story, but in reality, we have at least the feedback resistors, and that changes A LOT
3) the problem description I just wrote silently considers everything to be stable and ideal, inputs are zero because math&op-amp say so, op-amp has infinite own gain, op-amp has infinitely fast response time, etc. reality is not stable. gain is not infinite and response takes time.
So what do we get if we drop those assumptions?
See image from glen_geek in the other answer.
disclaimer: Description below may have some minor flaws. I don't intend to be 100% perfect..
First of all, let's start with real zero on the inputs, and outputs. Ok. So far, stable, easy, obvious.
Now, imagine the '+' input rises a little (not really important how much), and remember, the circuit has some lag, it's response time is not infinitely fast. Op-amp sees imbalance on inputs. '+' is > than '-', so the op-amp has to output something. Gain is not infinite, so it outputs some signal N times input difference. But its own the response time is not infinitely fast. Output starts rising from initial 0, up to that N*input, but it all takes time. Ok, so far we see what op-amp does. Slowly.
What happens elsewhere?
That now-rising output signal is seen at output line of the whole circuit (or the load, etc). Ok, we see some output forming. It rises from 0 to ... somewhere. Maybe N*input.
That now-rising output signal ALSO starts flowing back via feedback resistors (op-amp is never alone!), back to the input. To the '-' input. '-' input so far saw only voltage equal to the old input voltage, but it now gets additional (rising) signal coming from output. It means that the effective value at '-' is now rising as well. Situation on the input side now is changing.
What happens elsewhere?
Of course, op-amp sees the difference. Inputs were imbalanced, but the imbalance now is getting smaller ('+' rised initially, but now '-' is rising due to feedback from output). As the imbalance gets lower, the op-amp keeps the output Ninput. Now the input difference is smaller, so op-amp will take a correction. Back then, I've said that the op-amp's output "started rising from 0 to Ninput". Now, when it sees the '-' rising due to the feedback. So far the op-amp's output only started to rise from 0 to xxx, probably has not reached it yet. It was rising with some non-infinite speed, and now the input signal is effectively smaller, so now it will still be rising, just slower.
At the same time, all those changes are also seen on the output line of the whole circuit (or load, etc), so there we'll also see that the signal now rises, but a bit slower than before.
What happens ...after sometime?
Now-rising effective signal on '-' will at some point reach the same value as it's on '+'. For the whole time so far, '-' was rising, and op-amp's output signal was slowly rising, but slower and slower all the time. When '-' finally reaches the level of '+', op-amp will notice that and its output will stop rising. This will cause '-' to stop rising. It will STOP, not fall to zero. Falling to zero means moving in opposite direction, and the input difference is now zero. Everything will stop moving and we'll be in a steady-state again. Unless there's some new imbalance on + or -, the output won't move.
1) At first: input differences are zero. Output was constant and stable. 2) Then, an imbalance at inputs occurred. Output started moving (due to GAIN), and via feedback it started affecting the inputs. Influence was not immediate, it grew over time. 3) At some point of time, that feedback influence was so large, that it cancelled the imbalance and it forced input difference to be zero again. 4) At that moment output does not fall to back zero. At that moment, output stops rising/falling and holds its value, and we're again in steady-state.
If you look at the op-amp just by its steady-state description (1)+(4), it may be hard to "feel" where the output comes from if inputs are "aways at the same level". The magic is the intermediate state when all the rising/falling occurs: (2)+(3).
There's one more thing worth noticing. Since all we got boils down to achieving that '-' is again equal to '+', so the op-amp is happily having its 0V again, and the '-' got its feedback from the output, then it may look like the output is also equal to '-' and '+', and that we have no effective gain. That was another conceptual problem I had with this.
That's not true, because we have resistors in the feedback loop. Current flows through them and causes voltage drops. With resistors in feedback look the output swings have to be larger to cancel the input imbalance than in case without resistors. This impacts the effective gain of the circuit.