How does the web app http://20q.net work? Can I write a similar program, in a smaller scale, and if yes how?
Sure, this is called an "expert system" and can be represented by a binary tree (in the case of yes/no questions only). Each non-leaf node in your tree is a question (e.g. Is it a mammal?). Each leaf is a final answer (e.g. Giraffe) with an implied question Is it a giraffe?. If the answer to this final question is yes, the user guessed the answer. If the answer is no, then the user should be prompted to input a new question (added to the database) where the answer is yes for the new answer (e.g. wombat) and no for the old answer (giraffe). The system grows in "intelligence" the more it is used.