Start from the product rule, (uv)′=u′v+uv′. Integrate both sides and rearrange, and you get ∫udv=uv−∫vdu. The formula does not finish an integral. It swaps one integral for another, and the swap pays off when differentiating u makes it simpler while integrating dv does not make it worse.
Take ∫xexdx. Choose u=x, because its derivative is 1, and dv=exdx, because ex integrates to itself. Then uv−∫vdu=xex−∫exdx=xex−ex+C. The power of x dropped from 1 to 0, and the leftover integral was basic. For x2ex you apply parts twice, lowering the power each time. Choose the other way, u=ex and dv=xdx, and the new integral is ∫2x2exdx, which is harder than the one you started with. The order LIATE (logarithm, inverse trig, algebraic, trig, exponential) suggests which factor to call u: whichever comes first in that list.
Not every product calls for parts. ∫2xex2dx is also a product, but 2x is the derivative of the exponent x2, so the substitution u=x2 finishes it in one line. Check for an inner derivative first, and use parts when the two factors are unrelated.
Think of it like this. Parts is a trade at a market: you hand over one integral and receive uv plus a different integral. A good trade gets you an easier integral back, which happens when the factor you differentiate gets simpler, as x becomes 1. A bad trade, differentiating ex while integrating x, leaves you holding something harder than before. You may trade again as often as needed.
Core idea. Integration by parts uses ∫udv=uv−∫vdu to transfer the derivative from one factor to the other.