Contacts in the film chamber touch the squares and read the code. Besides the speed, the code also carries the number of exposures and the film's exposure latitude.
Many point-and-shoot cameras have no manual ISO setting at all: they only read DX. Load a film without a DX code (some small brands and hand-rolled bulk film) and the camera falls back to a fixed speed, often ISO 100, which can be far off. The camera manual says which.
Cameras also differ in which speeds they can read. The Canon Sure Shot WP-1 manual, for example, gives ISO 25 to 3200, set in one-stop steps.
The barcode printed along the edge of the film itself is a different code, for labs and their printers.