DX codes are digital encodings present on modern 35 mm film cassettes. They were introduced by Kodak, but, as far as I can tell, all film manufacturers have adopted them.
The codes are "machine readable," that is to say, 35 mm cameras may contain digital electronic circuits that read and interpret them. Not all cameras read and interpret all DX codes available on the cassette. In fact, most do not. However, even among "the most," some do a better job at it than others.
The film cassette is typically made out of black light-proof plastic. The DX codes are implemented in thin metallic foil placed at a very specific location on the cassette, creating two rows of seven bits each. The cameras "read" the codes using metallic pins located in the film chamber in such a way that when the film is properly loaded, the pins are in contact with either the conductive foil (the bit is 1) or the non-conductive black plastic (the bit is 0).
Most cameras only have one vertical row of pins, which allows them to read the film speed, but not the rest of the information (which is the number of exposures, and exposure margins). However, some of these cameras have six pins (for five bits of data), while others only have four (for three bits). The four-pin ones assume their owner is a less sophisticated photographer than the six-pin ones. The DX encoding was designed carefully, so that three bits are enough for the most common speeds.
For the rest of this write-up I am going to assume you place the cassette in the left side of the camera (looking at the back of the camera). If your camera loads the film from the right, simply reverse the words "top" and "bottom", and "left" and "right", in the rest of this write-up.
The Common
Both rows use the bottom sixth as the electronic common. This section is always conductive. The camera will typically connect it to the common ground (usually the negative battery terminal). If it connects the rest to a more positive voltage source, it can then check whether electricity flows through. If so, the bit is 1, otherwise it is 0.
For the rest of this write-up we will refer to the sixth right above the common as bit 0, the sixth above that as bit 1, etc up to bit 4 on the top, for a total of 5 significant bits.
Film Speed
The bits of the left row encode the film speed. If a camera contains only one row (vertical), it reads the film speed as well.
As mentioned above, the bottom-most section is the common. As for the rest, it follows this code, with bit 0 being the most significant bit (note that not all possible combinations are used):
ISO DIN Bits
=====================
25 15 00010
32 16 00001
40 17 00011
---------------------
50 18 10010
64 19 10001
80 20 10011
---------------------
100 21 01010
125 22 01001
160 23 01011
---------------------
200 24 11010
250 25 11001
320 26 11011
---------------------
400 27 00110
500 28 00101
640 29 00111
---------------------
800 30 10110
1000 31 10101
1250 32 10111
---------------------
1600 33 01110
2000 34 01101
2500 35 01111
---------------------
3200 36 11110
4000 37 11101
5000 38 11111
As you can see, the last two bits allow the increase by one degree DIN. There are only three combinations of the last two bits since the increase of three degrees DIN means the doubling of film sensitivity to light (as well as the doubling of the ISO/ASA speed rating.
The cameras that only have four pins ignore these last two bits. Most people could not care less, but for me that is a good reason never to buy a camera with just four pins (though I might buy one with no pins since I prefer manual exposure control anyway).
Number of Exposures
If the camera has two vertical rows of pins, it can read the number of exposures from the right row (vertical). As usual, the bottom section is common, the section right above it is bit 0. Bits 0, 1, and 2, encode the number of exposures, with bit 0 being the most significant:
12 100
20 010
24 110
36 001
48 101
60 011
72 111
Exposure Margins
The remaining two bits (3 and 4) of the right (vertical) row encode exposure margins in stops:
-0.5 to +0.5 00
-1.0 to +1.0 10
-1.0 to +2.0 01
-1.0 to +3.0 11
Please remember to switch "left" and "right", and "bottom" and "right" if your camera holds the cassette in the right compartment.