Bells have been used on most locomotives and trains since around the 1840's, but have almost always been used on most North American locomotives as opposed to European, Asian, South American, Australian, and African locomotives.
They've also been used on several different types of rollingstock, such as cabcars and BUDD diesel railcars.
Bells are most commonly used whenever a train is approaching a railroad crossing, grade crossing, or level crossing, as well as approaching a station, or moving at slow speeds. They're also used to alert crews and engineers of a departing train, which is used as a warning to "move" or "board".
The main way of distinguishing a locomotive or train's bell, is the unique "ding" sound that they make whenever they're rung or sounded.
Bells are commonly placed on the front or middle of an average steam locomotive (mainly North American), and are usually placed below the frame or beside the fueltanks on a diesel locomotive. On electric locomotives, they're often placed near the cab, or on the front of the cab of the locomotive like with most Canadian-built EMD, ALCO, and GE diesel locomotives.
Modern electric locomotives use automated bells, as well as with modern EMD and GE diesel locomotives.
The C&NW (Also sometimes the SL-SF/"Frisco") used a unique type of bell known as a "gong" bell, which was practically just a modified mechanical railroad crossing bell, and was commonly used on most of their locomotives.