A pattern is a template with slots. The difference of squares, a2−b2=(a+b)(a−b), has two slots, a and b, and anything with the shape "something squared minus something else squared" can be dropped in. 9x2−16 fits with a=3x and b=4, because (3x)2=9x2 and 42=16. So 9x2−16=(3x+4)(3x−4), found without trial and error.
Why does the template always work? Expand the right side: (a+b)(a−b)=a2−ab+ab−b2=a2−b2. The middle terms cancel for every a and b, so the identity holds whatever goes in the slots, whether 3x, y+1 or 50. That is also why 49x2−25 factors as (7x+5)(7x−5): the coefficient 49 is itself a square, 72, which is easy to miss.
Fitting the template exactly is the whole skill. 9x2+16 looks almost the same as 9x2−16, but the plus sign means it does not fit a2−b2, and no product of real linear factors gives a sum of two squares like this. Cubes have their own templates, each with a sign rule: a3−b3=(a−b)(a2+ab+b2) and a3+b3=(a+b)(a2−ab+b2).
Think of it like this. A pattern is like a cookie cutter: press it onto dough of any colour and you get the same shape. a2−b2 cuts out (a+b)(a−b) whether the dough is x, 3x or y+1. The cutter only works if the dough fits under it; a sum of squares is the wrong shape, however similar it looks.
Core idea. An algebraic pattern is a recurring identity like a2−b2 that you match-and-fill instead of re-deriving.