With very few exceptions, the number on the front of a multiple unit will be six digits, the first three are the class number of that type of unit - googling "class xyz" based on that will invariably link you to a wikipedia page about that class, and they're mostly accurate and very informative. The latter three digits are the number of that unit within that class - e.g. unit number 5.
The first number of the second three can indicate a "sub class" - these days there are few classes which have more than 98 units. As an example on here you might see people say "class 319/2". This means a unit in class 319, which structurally are all identical, but sub classes can indicate differences, sometimes engine differences, unit length difference or even just interior layout. For example, 319204 is a class 319, subclass 319/2, and nominally the third of that subclass.
For locomotives it's similar, but the number will be 5 digits - the first 2 are the class, and the 3rd could be a subclass.