A transistor can be considered as two P-N junctions that are placed back to back. One of these junctions is a base-emitter junction which is forward biased and the other base-collector junction is reverse biased. Here, considering the working of NPN transistor, the emitter and collector is n-type semiconductor material and the base is p-type.
The voltage of the base must be more positive than emitter and the voltage of collector must be more positive than the base. The batteries are connected in the circuit to supply the required voltages at different ends of the transistor. The emitter gives out the electrons and base pulls in these electrons because it has more positive voltage than the emitter. This transfer of electron creates a flow of electricity within the transistor.
The current passes from emitter to collector through the base. The voltage of base varies to change the number of electrons in it and this modifies the flow of current. This small change makes a large change in the current flowing out of the collector.
A PNP transistor also works on the same principle as an NPN transistor. But it has one difference; the main flow of current in PNP transistor is controlled by changing the number of holes rather than the number of electrons in the base. Moreover, this transistor works well when the negative and positive connections are opposite of those in the NPN transistor.