Start with numbers. Writing 12 as 3×4 is factoring: you replace a total with pieces that multiply to it. Algebra does the same with expressions. Take algebra tiles: one x-by-x square, five x-by-1 strips and six unit squares. They fit together exactly into a rectangle x+2 wide and x+3 tall, so x2+5x+6=(x+2)(x+3). The sum lists the pieces; the product gives the rectangle's sides.
For a trinomial x2+bx+c, you need two numbers that multiply to c and add to b, because (x+p)(x+q)=x2+(p+q)x+pq. For x2−5x+6, the product 6 is positive, so both numbers have the same sign, and the sum −5 is negative, so both are negative: −2 and −3, giving (x−2)(x−3). Some shapes have shortcuts: x2−49=(x+7)(x−7) is a difference of squares, and x2+10x+25=(x+5)2 is a perfect square. Take out any common factor first: 4x2+20x+24=4(x2+5x+6).
Expanding looks similar because it uses the same equation read the other way: expanding turns a product into a sum, factoring turns a sum into a product. Collecting like terms, as in 3x2+2x+x2=4x2+2x, is neither; it shortens a sum without creating factors. And some expressions don't factor over the integers. The only integer pairs with product −1 are 1 and −1, which sum to 0, not 1, so x2+x−1 stays as it is; to solve x2+x−1=0, reach for the quadratic formula.
Think of it like this. Picture a pile of tiles, one big square, some strips and some small squares, that you must arrange into a single rectangle. Expanding goes forward, multiplying a rectangle's sides to get its area; factoring goes backward, from the pile to the side lengths. The picture strains with negative terms, which no real tile can show.
Core idea. Factoring rewrites an expression as a product of simpler factors that multiply back to the original.