Explain the operation npn transistor when used as amplifier.. and explain the basic operation of NPN when used as switch?

The NPN transistor when used as an amplifier is operating in linear mode, and, when operating as a switch, in saturated mode.

In the following discussion, base currrent means base-emitter current, while the base is more positive than the emitter, and collector current means collector-emitter current, while the collector is more positive than the emitter. There is base-collector current, but we are going to ignore it for now - besides, we are going to discuss class A, common emitter, configuration.

The PNP transistor is very similar. Everything is backwards, including Vcc, which is now -Vcc, or appropriate reconfiguration. The rules are the same - just backward.

In switched or saturated mode, the ratio of base to collector current is far greater than beta-dc, or hFe, so the transistor is operating way out of its linear mode. We call that saturated mode, and the transistor is essentially either fully on or fully off, and therefore operating as an on-off switch.

The rest of this discussion will focus on linear or amplilfier mode.

If the ratio of base to collector current is less than beta-dc, or hFe and, if both base and collector voltage are greater than cutoff voltage, then the transistor is operating in linear mode. Well, sort of, for best linear mode, we look at the data sheet, or make empirical observations, and we pick the base and collector currents that are centered between the base knee and the collector knee, i.e. "in the middle of" the linear region.

In this mode, a very small base current can control a much larger collector current, and, most importantly, a very small change in base current can create a much larger change in collector current.

In the theoretical case, for example, where the emitter is grounded and where hFe is 100, then 1 mA of base current translates to 100 mA of collector current, and 2 mA of base current translates to 200 mA of collector current. Problem is, that hFe varies amongst even so called identical transistors, and hFe varies as a function of temperature as well.

So, in the practical case, an emitter resistor is added to stabilize the transistor and place limits on the need for hFe of a particular value. Done properly, this will yield predictable gain for various transistors and for various temperatures.

Now, lets look at how gain works in the practical sense. The base voltage is also a known delta above emitter voltage. Yes, temperature will affect this, but proper design can make this a negligable factor. The emitter current times the emitter voltage results in a known voltage. By Norton's current law, the base current and the collector current add up to be the emitter current, but by hFe, the base current is very much smaller than collector current, meaning that the really important part is that collector and emitter current are the same for all practical purposes.

So, now add a collector resistor. Ignoring base current, the collector/emitter circuit is a series circuit, and Norton's current law, reinterpreted for series circuits, says the two resistors have the same current. Think about what that means; if the current in both resistors is the same, then the ratio of the voltage across the two resistors is proportional to their value. The gain of the amplifier is collector resistor divided by emitter resistor. That is critical knowledge. Again, base current enters into the equation but, if hFe is high enough, it does not matter.

All that is left, then, is to bias the base. You want to pick a base voltage (current) that places the collector current in the center (or in an appropriate point) of the linear region. Choose a nominal hFe, divide by collector current, and you get an approximation of what base current bias should be. Choose a resistor divider to match, keeping in mind that the two resistors (base to Vcc and base to Gnd) in parallel will reflect your effective input impedance.

Review everything, particularly your power levels. To calculate the power through the collector/emitter junction subtract collector resistor voltage from emitter resistor voltage from Vcc, and you get collector/emitter voltage. Multiply that by collector current, and you get power dissipated by the transistor in nomial bias condition.

Play with the values until you have what you want. You could even set this up in a spreadsheet.

Last, but not least, there is a base bias voltage. If you are going to amplify something, you need to maintain that nominal bias voltage. Connect a series capacitor between the base and the input point and you will be able to operate from an AC signal that is zero referenced. Just pick the RC time constant appropropriate for your application.

Similarly, there is a collector bias, so, if you want an AC output zero referenced, use a series capacitor also in between the collector and the ouput.

This is an AC coupled, inverting amplifier. There are DC coupled non-inverting versions, but they are more complicated, requiring more than one transistor, and this answer does not address them. Good luck!