Algebraic Definition of Absolute Value
Click here for a brief discussion of the algebraic definition of absolute value (printable version).
You may want to review some basic absolute value concepts:
 Simplifying Basic Absolute Value Expressions
 Determining the Sign (Positive or Negative) of Absolute Value Expressions
Sometimes we don't care if a number is positive (i.e., lies to the right of zero) or negative (i.e., lies to the left of zero). We just want to know its size—its distance from zero.
In these situations, the concept of absolute value comes to the rescue. The notation $\,x\,$ denotes the absolute value of $\,x\,.$
The number $\,x\,$ gives the distance between $\,x\,$ and $\,0\,.$ This definition of absolute value as distance from zero is often the easiest one to use.
Whenever you see those two vertical bars that denote absolute value, I like to have my students do two ‘karate chops’ on them, saying: $$ \cssId{s13}{\overset{\text{karate chop #1:}}{\overset{\text{DISTANCE}}{\overbrace{\ \ \ \ \ \ \ \ }}}} \cssId{s14}{\overset{\text{from}}{\ \ \ \ \ \strut\ \ \ \ \ }} \cssId{s15}{\overset{\text{karate chop #2:}}{\overset{\text{ZERO}}{\overbrace{\ \ \ \ \ \ \ \ }}}} $$
However, there is also an algebraic definition of absolute value. In particular, the algebraic definition is needed in the derivation of the quadratic formula.
PiecewiseDefined Functions
The algebraic definition of absolute value uses a piecewisedefined function. A piecewisedefined function is used whenever different output formulas are needed for different inputs; that is, more than one piece is needed to give a full description of what the function does!
Whenever you need one rule for one set of inputs, and another rule for a different set of inputs, then a piecewisedefined function comes to the rescue.
As you'll observe in the definition below, the following notation is used for piecewisedefined functions:

A single large left brace is used to gather together the different rules; there is no closing right brace.

To the right of this brace, each rule is given its own line: two ‘pieces’ result in two lines; three ‘pieces’ result in three lines, and so on.

Each line has this pattern:
 State the rule, followed by an optional comma;
 followed by the word ‘ if ’ or the word ‘ for ’;
 followed by the input(s) to which the rule applies;
 followed by an optional comma (for all except the last line).
I tend to prefer the simplest notation that clearly conveys meaning, so I opted for no commas in the definition below. However, some alternative presentations are offered following the definition.
Here are some alternative presentations of this piecewisedefined function:
Comments on the Algebraic Definition of Absolute Value
How to use the formula
Here's how you'll use the formula to find $\,x\,.$
Start by looking inside the absolute value, at the number $\,x\,.$

If $\,x\,$ is greater than or equal to zero, then use the first rule, $\,x = x\,.$
That is, if a number is nonnegative, then its absolute value is itself. For example, $\,3 = 3\,.$

If $\,x\,$ is less than zero, then use the second rule, $\,x = x\,.$
That is, if a number is negative, then its absolute value is its opposite. For example, $\,3 = (3) = 3\,.$
The second line is most troublesome
The second line of the rule is most troublesome: $$\cssId{s56}{x = x\,, \text{ if }\ x \lt 0}$$
One thing that leads to confusion is that people often read ‘$\,x\,$’ as ‘negative $\,x\,$’, which makes it sound like the result is negative. Not so!! If $\,x\,$ is negative, then its opposite, $\,x\,,$ is positive!
If you find yourself getting confused, just read ‘$\,x\,$’ as ‘the opposite of $\,x\,$’, and this may clear up any difficulty.
The absolute value makes a useful appearance in the following formula:
So, what is $\,\sqrt{x^2}\,$? There are two numbers which, when squared, give $\,x^2\,$: $\,x\,$ and $\,x\,.$
Which one do we want? Answer: Whichever one is nonnegative!
Unless we happen to know the sign of $\,x\,,$ then we won't know which one is nonnegative. Absolute value comes to the rescue! The number $\,x\,$ has the same size (distance from zero) as both $\,x\,$ and $\,x\,,$ and is always nonnegative.
Don't ever fall into a common trap and think that $\,\sqrt{x^2}\,$ is just $\,x\,.$ Sure, this ‘formula’ works if we know, ahead of time, that $\,x\,$ is nonnegative. But, usually we're in situations where $\,x\,$ is allowed to be any real number.
For example, let $\,x = 5\,.$ Then: $$\cssId{s83}{x^2 = (5)^2 = 25}$$
Is $\,\sqrt{x^2}\,$ equal to $\,x\,$ in this case? No! $$\cssId{s86}{\underbrace{\sqrt{25}}_{\sqrt{x^2}}\ne \underbrace{5\strut}_{x}}$$ However, it is true that: $$ \cssId{s88}{\sqrt{x^2}} \cssId{s89}{= \sqrt{(5)^2}} \cssId{s90}{= \overset{=\, x}{\overbrace{5}}} \cssId{s91}{= 5} $$