Class (locomotive) refers to a group of locomotives built to a common design for a single railroad. Often members of a particular class had detail variations between individual examples, and these could lead to subclasses. Sometimes technical alterations (especially rebuilding, superheating, re-engining, etc.) move a locomotive from one class to another. Different railways had different systems, and sometimes one railway (or its successors) used different systems at different times and for different purposes, or applied those classifications inconsistently. Sometimes therefore it is not clear where one class begins and another ends. The result is a classic example of the Lumper splitter problem.
As locomotives became more numerous the need arose to deal with them in groups of similar engines rather than as named or numbered individuals. These groups were named "classes" and at first tended to reflect capability rather than design. For example, the Baltimore and Ohio Railroad grouped its roster into four classes before the Civil War, though they had by that point dozens of different designs.
Later classes were based on design. A group of locomotives built off the same blueprints constituted a class, and if some of the locomotives in the class were sufficiently modified, a new class might be established for the modified examples. When electric locomotives were introduced, the same scheme was applied to them.
Since steam and early electric locomotives were usually custom built, classes were assigned by the railroad, and each railroad had its own system. Mergers of lines and sales of locomotives brought about changes of class. Early diesels were often fitted into the locomotive class system, but since they were generally not custom built the use of manufacturer model designations overtook the class system and made it irrelevant, except for historical discussion.
Usually the class system for a railroad was built on a simply hierarchy which assigned each class a code.
The first level was usually for the wheel arrangement and was usually coded by a letter of the alphabet. Different railroads used different codes, so that "J" on the New York Central Railroad meant a 4-6-4 (Hudson), while on the Norfolk and Western Railway it mean a 4-8-4 (Northern), and on the Baltimore and Ohio Railroad it denoted a 4-4-0 with a Wootten firebox.