How does Ubuntu know what file type a file without extension is?

Via "magic"

The file(1) command identifies the type of a file using, among other tests, a test for whether the file contains certain ''magic patterns''. The file /usr/share/misc/magic specifies what patterns are to be tested for, what message or MIME type to print if a particular pattern is found, and additional information to extract from the file.

http://linux.die.net/man/5/magic

http://linux.die.net/man/1/file