Why are Bitcoin transactions sometimes confirmed instantly if blocks are mined every 10 minutes? I have a basic question on Bitcoin and blockchain:

Sometimes transactions are confirmed almost instantly, but there should be a new block every 10 minutes, so how is it possible? A transaction can be confirmed only after being included in a block, right?

thanks!
A little more information is necessary to tell you exactly what happened to your transactions that were confirmed "almost instantly" but what you've said is correct:


The bitcoin protocol is such that new blocks should be mined, on average, every 10 minutes. 
A transaction is "confirmed" (has 1+ confirmation) only after being included in a block. Before this, the transaction is "pending". Some merchants require more than one confirmation for the transaction to be final, many choosing to wait for 3 confirmations before being deemed complete. 


However, the situation can arise where after publishing your transaction a block is then mined a few seconds later that has your transaction in it. This could give the appearance that your transaction was confirmed "almost instantly". 

Possible source of confusion: Blocks aren't mined 10 minutes after your transaction, they're mined 10 minutes (on average) since the previous block was mined.