The term “firearm” refers to any sort of portable device that uses a barrel to fire a projectile, and they come in many forms.
A German Walther P99 handgun
As its name suggests, a handgun is designed to be held only in the hand, without the use of shoulder support. They come in two basic types: pistols, like the Walther P99 above, which have the chamber that holds the bullet integrated into the barrel, and revolvers which separate the barrel and chamber (usually possessing six or more separate chambers).
Handguns are usually semi-automatic, which means that each time the trigger is depressed one round is fired. Some fully automatic handguns (usually referred to as machine pistols) do exist, in which the gun will continue to fire for as long as the trigger is held down until all the ammunition is expended, but these are rare.
A rifle is a firearm with a long rifled barrel; the long barrel and the rifling give the weapon increased range and accuracy.
A Swiss SIG SG 550 assault rifle
An assault rifle is a selective fire rifle; this means that the weapon can fire in both semi-automatic and fully-automatic modes, and many assault rifles also offer a burst mode (usually a three-round burst) in which multiple rounds are fired each time the trigger is depressed. Assault rifles fire rounds that are between pistol and rifle rounds in terms of power, and use detachable magazines which hold around thirty rounds.
Assault rifles are the primary weapon issued to most armed forces, though most also issue a handgun as a backup side arm. Assault rifles were created when it was realised that most engagements occurred at ranges below the maximum range of battle rifles, and that a weapon in between the handgun and the battle rifle was required.
A Belgian FN FAL battle rifle
Battle Rifles fire full-powered rifle rounds, and thus have greater range than assault rifles, but because they are higher-powered they are more difficult to control in fully-automatic mode.
A carbine is a shorter and lighter version of an assault rifle (the H&K G36C carbine shown above is a version of the H&K G36 assault rifle). Because they are lighter and more manoeuvrable they are favoured where space is restricted (e.g. for use by helicopter pilots or armoured personnel vehicle drivers) or where high mobility is key, e.g. by special forces or hostage-rescue teams.