Useful information to know (complements the other answers) which applies to both NPN+PNP bipolar transistors and N-channel and P-channel MOSFETs:


TO92 transistors are almost always pinned-out as EBC (bipolar) / SGD (MOSFET) when you are facing the flat part of the transistor package and the leads are pointing down.
TO220/TO247/DPAK/D2PAK transistors are almost always pinned-out as BCE (bipolar) / GDS (MOSFET) when you are facing the front part of the transistor (tab on the back side) and the leads are pointing down. This is easy to remember by the mnemonic GDS = Gosh Darn Son-of-a-gun. (Or something like that. :-)
Transistors with metal tabs (TO220, TO247, DPAK, D2PAK, SOT-223, etc.) almost always have the tab as the collector or drain. This has to do more with the construction of the device than from any sort of convention; the collector/drain is the part of the die that is the most thermally coupled to the metal tab, so it's a natural point of electrical attachment.
Surface-mount transistors with two pins on one side and the third standing alone on the other side (SOT-23, SOT-323) almost always have the collector / drain standing alone. This is because the gate-source / base-emitter voltage differential is small, whereas the collector / drain may be tens or hundreds of volts different, so it provides a larger clearance for that voltage differential to have the collector / drain off on its own. The same holds true for DPAK / D2PAK transistors, where the middle pin is cut short and sticks up in the air; it's done to provide voltage clearance and you connect electrically through the collector / drain via the tab, which is (usually) the same piece of metal as the center pin.


I suppose there are certain transistor parts that are exceptions to these rules (most likely in the SOT-23 and SOT-323 packages) but I'm not aware of any -- still, always check the datasheet.

How do I know if which leg is the emitter or the collector? (Transistor)
Is it possible to distinguish a concave polyhedron from a convex one by mesurements made only on its surface, without a reference to the 3d space around it?
