the transistor as a switch
The simplest job a transistor does is to be an electrically controlled on/off switch — a relay with no moving parts. A weak signal (from a microcontroller pin, a sensor, a logic gate) goes into the base, and a much bigger current to a load (an LED, a motor, a relay coil, a buzzer) flows through the collector. You are not amplifying a smooth signal here; you are slamming the transistor fully ON or fully OFF, nothing in between.
To turn an NPN switch fully on, you drive enough base current that the transistor SATURATES: the collector is pulled down to almost the emitter voltage (about 0.1 to 0.2 V), so the load sees nearly the full supply. The trick is to over-drive the base on purpose. Suppose you switch a 100 mA load and the worst-case beta is 50; you would need at least 100/50 = 2 mA of base current, so you provide 5 mA or more for margin — engineers call this the "forced beta" or overdrive. The base resistor sets that current: from a 5 V logic pin through the 0.7 V base-emitter drop, R = (5 - 0.7)/0.005 = about 860 ohm, so you would pick 680 ohm. To turn it OFF, you simply pull the base to 0 V (cutoff) — no base current, no collector current.
Why bother, when a mechanical switch exists? Because the transistor switches in nanoseconds, millions of times, silently, with no contacts to wear out, and it is controlled by a signal far too weak to throw a real switch. That is how every digital chip drives the real world. The honest caveats: when saturated the transistor still drops about 0.2 V, so it dissipates a little heat (P = 0.2 V times the load current); for an inductive load like a relay or motor you MUST add a flyback diode across the coil or the collapsing magnetic field will spike hundreds of volts and destroy the transistor.
Arduino driving a 5 V relay: the 5 V pin can only source 20 mA, but the relay coil needs 70 mA. Put an NPN (say 2N2222) as a low-side switch — coil from +5 V to the collector, emitter to ground — with a 1 kohm base resistor and a flyback diode across the coil. Now a 5 V high turns the relay on; a 0 V low turns it off.
A weak logic pin commands a heavy load — and the diode protects against the coil's kickback.
A saturated switch is great for on/off but lousy for amplifying: in saturation the collector current no longer follows the base. Switching and amplifying are opposite uses of the same device.