In a nutshell
Q-learning learns good behaviour without ever being told how the world works. It keeps a Q-value for each state-and-action pair — an estimate of the total future reward that move is worth — and refines it from experience using the Bellman update: nudge the old estimate toward the reward just received plus the discounted best value of the next state. To keep discovering, the agent sometimes acts at random (exploration) and otherwise takes its best-known move (exploitation). Given enough episodes the Q-values settle and the best move everywhere becomes the optimal policy.