Usually, only the models in a unit's front rank can shoot. There are, however, exceptions:
Shooting from a Hill
A unit on a hill is in an ideal position to fire, so can fire with one additional rank compared to a unit on flat ground. For example, a unit armed with crossbows can shoot with its first two ranks when standing on a hill.
Volley Fire
Some units are armed with weapons that have the Volley Fire special rule. This special rule allows half of the models in each rank other than the front rank (or front two ranks if the unit is on a hill) to fire over the heads of those in front.
In either case, if there is ever any question over how many models can fire, always round up, not down.
Note that when shooting with a unit you must determine range for each model individually.