Inpainting is the AI equivalent of photo retouching: you select an area — a distracting object, a flawed detail, an element you want swapped — and the model redraws only that part, fitting it to its surroundings. The rest of the pixels stay untouched, which is why the light and the perspective match.
The same idea comes back in two other operations. Outpainting continues the picture beyond its own edges, and background replacement uses the selection the other way round: the subject stays, everything behind it is swapped. If you understand the principle, you can use all three.
The most common misconception is that the accuracy of the selection is what matters. In practice it counts at least as much what you write into the mask — the model expects a prompt for the selected area too, and "empty space" is not a good instruction. The other limit is that the seam tends to show at repeating patterns and at the edges of text.
How the three operations work in practice is covered in inpainting, outpainting and background replacement, a separate article. The directly related terms: image-to-image, in-context editing and layout control.