Beginning in approximately 1970, the UIC (Union Internationale des Chemins de Fer, or International Railway Association -- the European equivalent of the American AAR, setting international standards for railway equipment interchange) introduced a standard numbering scheme for rolling stock so that cars could be tracked by computer, among other things. Before long, almost all railway rolling stock in Europe was numbered in this scheme.
Note that locomotives and other powered equipment are not covered by this scheme, although most railway systems renumbered their locomotives into a computer-compatible system at about this time.
The UIC numbering did not take on in the United Kingdom: British Rail introduced its own numbering scheme generally known as TOPS (although this was more properly the name for the computer system that issued these numbers and kept track of rolling stock). A code for British Rail exists in the UIC numbering scheme, though. The primary reason for it not taking off is that few British cars, freight or passenger, are built to interchange standards; nor do foreign cars make it very often onto British rails, thanks to the restricted British loading gauge.
Numbers are also assigned for railway systems stretching as far afield as China and Japan and even Cuba, although I'm pretty sure the latter, at least, has never been used. Apart from Cuba, Japan and the United Kingdom, all the other railway systems covered are linked by land, covering Europe, Asia, the Arabian peninsula and Africa, and interchange between them is possible. The United Kingdom is linked via ferry and tunnel, of course.
The numbers themselves are twelve digits long. Freight car numbers are written like:
31 80 472-3 011-1
or vertically, like so:
537 6 111-1
In the latter case, the first two pairs of digits, for the type of car and the owner respectively, are spelled out in text as well as the number, for clarity.
Passenger cars are numbered like:
52 20 70-80 476-3
The meanings of the digits:
Digits 1 and 2: type of car.
Digits 3 and 4: Owning railway system or company.
Digits 5 and 6: Further information on subtype of car, going into more detail.
Digit 7: freight sub-type
Digits 8-11: 4 digit serial number 0000-9999
Digits 7 and 8: Passenger car speed rating and heating type
Digits 9-11: 3 digit serial number 000-999
Digit 12: check digit
Thanks to Tobias Köhler for help with the digits