How does confirmation exactly work? When user A sends Bitcoins to user B, user A signs the transaction with his private key. This signed transaction is being sent to the Bitcoin network and all the nodes collect, confirm and pack these transactions to blocks by mining. Is that right so far? But what exactly happens at the confirmation. What are the nodes doing? I can't imagine what confirmation means technically. Does the transaction contain the public key and the nodes look if they can decrypt the transaction with this public key or what?

And what does it mean to wait 6 confirmations or more? (see http://bitcoin.org/en/vocabulary#confirmation). Why should one wait for a confirmation and how can one decide how many confirmations to wait? This is very unclear to me (Bitcoin newbie). The tooltip here tells me "the more confirmations a transaction has, the more likely that it will remain in the chain permanently". Why do I want my transaction to remain in the chain?
Each node checks that a transaction is valid when they learn about it. Nodes check that the used funds exist, and that they have been correctly signed for. You can think of the address as locking the funds to a specific private key. The owner authenticates themselves by using this private key to generate a signature. Private Key and address form an asymmetric key pair, so everyone that knows the address that the funds were previously sent to can verify the authenticity of a signature. Miners then collect transactions, and include them in blocks. When a transaction appears in a valid block, the transaction is considered to be confirmed.

When additional blocks are found, they build upon the longest chain that is known to the mining node. As long as there are only very few blocks stacked on top of the block in chain A that confirmed our observed transaction, there might still exist a competing chain B that could overtake and obsolete those blocks. If B contains a transaction that is at odds with our observed transaction, the observed transaction might yet be invalidated.

Each block, after the observed transaction has been confirmed, significantly decreases the chance of the block being invalidated, because a competing chain has to mine all the blocks since our observed transaction was confirmed, i.e. has to do multiple times the work of the whole network in order to catch up.

When your transaction has been confirmed six times, i.e. five
additional blocks have been found since your transaction was featured
in a block, the probability of a miner with 30% mining power overtaking the current chain tip is less
than 1%, and some consider the transaction to be reliable at this point.

Also see: Is there actual consensus on the blockchain&#39;s tip or only until the next block?