Recently I was solving a math problem and I came across the following ( Only part of the problem ):

$$\sqrt{3 - \sqrt{8}}$$

Here's is what I did to simplify the above:

$$(a-b)^2=a^2+b^2-2ab$$
$$\sqrt{1+2-2\sqrt{2}}$$
$$\sqrt{(1-\sqrt{2})^2}$$
$$=1-\sqrt{2}$$

When you expand $(1-\sqrt{2})^2$ you do get $3 - \sqrt{8}$. However, I found that upon the expansion of $(\sqrt{2}-1)^2$ I also arrive at the same answer as before $3 - \sqrt{8}$.

Yet the in the solution of the problem I was doing it required me to use the latter $(\sqrt{2}-1)^2$ to find the correct answer. $(1-\sqrt{2})^2$ did not help to solve the problem. Why is this the case? Why does the latter only hold true?

I suspect this might have something to do with the square root function only returning a positive value. Might this be the case? If so, could someone explain why a square root function can only return a positive value. My working above seems to give a negative answer ( As $\sqrt{2}>1 )$ in the square root function, but I can't seem to find what I'm doing wrong.