I used to struggle with the formal definition of a limit because I never really understood what it means. So, I will now try to explain what the definition means and what your goals should be when you are solving any formal definition problem.
Let $f$ be a function defined on some open interval around $a$, except possibly at $a$. We say that $\lim_{x \to a}f(x)=L$ if, for every $\varepsilon >0$, there exists a $\delta >0$ such that whenever $0<|x-a|<\delta$, we have $|f(x)-L|<\varepsilon$.
Here is a breakdown of each statement:
I recommend you revise the Graphs and functions page, and specifically the sub-section about functions being defined at a specific point.
In this statement, $f$ is just the name of any function.
Moreover, there is a requirement that it is defined around a specific point on the $x$-axis, and that point is given the variable $a$ for simplicity. It is not a requirement that the function is actually defined at $x=a$. $a$ can be any number found on the $x$-axis, such as $-10,\ -5,$ $0$, $1$, $\pi ,\ e$, etc.
For example, we know that $f(x)=\frac{1}{x}$ is not defined at $x=0$, because $\frac{1}{0}$ is not a real number. However, it is defined around $x=0$, because if you input any $x$ value near $x=0$ (like $x=0.000001\ or\ -0.0000001\ or\ 0.2\ etc.,$ you will always get a real number. Looking at the graph of the function can also help you decide whether it is defined around a specific value or not. Here, I remind you of $f(x)=\frac{1}{x}$.
Graph by desmos.
In this case, $f(x)=\frac{1}{x}$, and $a=0$. As you can see, the red line (the function) is defined around $x=0$. but it can never touch $x=0$ line since you can't divide by 0.
Here is another example. $f(x)=x$ and our $a$ is the red $3$. All we care about is that $f(x)$ is defined around 3, which is satisfied in this example (you can always input something like 2.999999999 or 3.0000001 and you will still get a real value from $f(x)$). Furthermore, $f(x)$ is defined at $x=3$, but that doesn't really change anything.
Here, $f(x)=x^{2}$, $a=-2$, and I have made it so that $f(x)$ is not defined at $x=-2$. This example still satisfies our definition requirement, since we only need $f(x)$ to be defined around $a$.
In this example, we have a piecewise function: $f(x)=4\ if\ x<=0\ \&\ -\frac{1}{2}x+4\ if\ x>0$, and our $a=0$. This still works because $f(x)$ is defined around $x=0$. For instance, if you input $x=0.000000001$, you would get $f(x)=3.9999999995$ (using the $-\frac{1}{2}x+4$ portion of the piecewise function), which is a real number. Also, if you input $x=-0.000000001$, you get $4$, which is also a real number.
This is also a piecewise function example, although there is a jump at our $a$. $f(x)=7\ if\ x<=-2\ \&\ x^{2}\ if\ x>-2$ and $a=-2$. Using the same logic we used previously, this disconnect between our graph lines doesn't affect our definition requirement at all because $f(x)$ is still defined around $x=-2$. (Question to think about: Based on the image and what you read on the What is a limit? page, does a limit exist?)
I recommend you revise the page about the general intuition of a limit, it will explain what $\lim_{x \to a}f(x)=L$ means.
In general, this sentence means that as $x$ gets closer and closer to our value $a$, our $f(x)$ gets closer and closer to the $y$ value: $L$. For example, in this image that we saw on the What is a limit? page, as $x$ gets closer and closer to $3$ (our $a$) from both the left and the right, $f(x)$ gets closer and closer to the $y$ value $3$. So, our $L=3$.
Here is another example. This is the upper portion of $f(x)=\cos x$ and $a=0$. As $x$ approaches $0$ from both the left and the right, $f(x)$ is approaching $1$. Hence, our $L=1$.
$\varepsilon$ and $\delta$ are simply variables for distance. $\varepsilon$ is some distance on the $y$-axis, and $\delta$ is some distance on the $x$-axis.
Whenever we are talking about limits, we usually use the word "approach," such as "as $x$ approaches $10$ (the $a$), $f(x)$ approaches $7$(the $L$)." This means that there will always be some distance between $x$ and $a$, and between $f(x)$ and $L$. $\varepsilon$ measures the distance between $f(x)$ and $L$, while $\delta$ measures the distance between $x$ and $a$.
$|f(x)-L|<\varepsilon$ means that the distance between $f(x)$ and $L$ must be less than $\varepsilon$. $0<|x-a|<\delta$ means that the distance between $x$ and $a$ must be less than $\delta$. We are using absolute values for both $|f(x)-L|$ and $|x-a|$ because distance can never be negative (absolute values make negative numbers become positive). Since distance can't be negative, this also means that $\varepsilon$ and $\delta$ can not be negative.
Example 1 - Just showing you how $|f(x)-L|$ and $|x-a|$ would be shaded on a typical graph, in addition to some distance calculations.
Let us look at this image carefully. Our $f(x)=x,\ a=3,\ and\ L=3$. For now, I chose to let both $\varepsilon$ and $\delta$ equal $1$. They don't have to be equal to $1$, and they don't even have to be equal to each other.
The yellow region displays the area represented by $|f(x)-L|<\varepsilon$. Our $f(x)$ can be up to 1 unit above $L$ (so our $f(x)$ can reach up to $y=4$, but not touch it) and 1 unit below $L$ (so as low as $y=2$, but not touch it). Let us assume that that our $f(x)=3.9$, then our distance from $L$ would be $|3.9-3|=|0.9|=0.9$, and $0.9$ is definitely less than 1 (our $\varepsilon$). Now, let's assume our $f(x)=2.4$, so our distance from $L$ is $|2.4-3|=|-0.6|=+0.6$ and $+0.6$ is still less than $1$.
The red region displays the area represented by $0<|x-a|<\delta$. It means that our $x$ is less than 1 unit away from $a$ (which is 3). So $x$ can be $2.3,\ \pi ,\ 3.9$, etc. The only thing to note is that $x\ne a$, because the distance between $x$ and $a$ must still be bigger than $0$ (the left hand side of the inequality: $0<|x-a|$).
Example 2 - Showing you an example where even though $\delta$ and $\varepsilon$ are equal, the shaded region is not.
Our $f(x)=x^{3}+3x^{2},\ L=2,\ a=-1,\ and\ \varepsilon \ \&\ \delta =1$. As you can see, our red and yellow shaded regions are not equal, even though the $\varepsilon$ and $\delta$ are equal. This is because $x$ has a greater effect on $y$ in comparison to $y$'s effect of $x$ (the rate of change of $y$ caused by changing $x$ is greater than the rate of change of $x$ caused by changing $y$).
This idea will become very important when I explain the final statement of the definition.
This statement will hopefully be easy to read now.
As we said previously, $\varepsilon$ and $\delta$ are both variables that display distance, so they must be greater than 0, since distance can only be positive.
$0<|x-a|<\delta$ is the red region in my diagrams and $|f(x)-L|<\varepsilon$ is the yellow region. In simple words: The definition's statement necessitates that the portion of the function (the blue line, the actual function) that sits above the red region must stay fully inside the yellow region. A more "mathematical" explanation: You are given an arbitrary $\varepsilon$ and your task is to find a $\delta$ that ensures whenever your distance between $x$ and $a$ is less than that $\delta$, then the distance between $f(x)$ and $L$ is less than $\varepsilon$. This means that you must find a way to relate $\varepsilon$ and $\delta$ together. The next section will be about how you can find such $\delta$.
I will use the $f(x)=x$ example (image in the explanation of "What does $\varepsilon$ (epsilon) and $\delta$ (delta) mean?" bullet point) to show you what that means.
This image satisfies the definition's requirement, since the part of the function that touches the red region is fully inside the yellow region.
This image also satisfies the definition's requirement, since the part of the function that touches the red region is fully inside the yellow region. It doesn't matter that the yellow region is bigger than the red region.
This image is an example of something that doesn't satisfy the definition's requirement: the part of the function that touches the red region is not fully inside the yellow region.
Now that we have explained the definition, let us see how it works.
These steps will help you solve problems and give you a template that you can hopefully follow throughout many of your problems. Just keep in mind that applying the formal definition of a limit requires you to split your work into 2 sections: scratch work and formal proof (you should write both on your exam paper). You will start with the scratch work and then the formal proof:
Let $\varepsilon >0$. Choose $\delta =\frac{\varepsilon }{\text{constant}}$. Note that $\delta >0$ since $\varepsilon >0$.
Suppose $0<|x-a|<\delta$.
Since $\delta =\frac{\varepsilon }{\text{constant}}$
We have $|x-a|<\frac{\varepsilon }{\text{constant}}$
$\text{constant}\cdot |x-a|<\varepsilon$,
and then you should be able to return the left side back to its $|f(x)-L|$ form, giving you $|f(x)-L|<\varepsilon$.
Therefore, by the formal definition of a limit, $\lim_{x \to a}f(x)=L$.
More on the constant mentioned in this step:
You can choose any constant as long as that constant doesn't push your $x$ to a value that it is undefined in.
Let us for example take $\lim_{x \to 2}\frac{1}{x+1}=\frac{1}{3}$ as the limit we are trying to prove. Remember that $\delta$ is the distance between $x$ and $a$. Looking at our function $\frac{1}{x+1}$, we can see that it is undefined at $x=-1$ (because $\frac{1}{-1+1}=\frac{1}{0}$ which is undefined). So, the maximum distance of $x$ from $a$ can not allow it to cross or equal $x=-1$ line, since that would allow the function to be undefined at a specific point. In this specific example, our $a=2$, so we can't allow $\delta$ to be equal to or greater than $3$, because that would allow $x$ to reach $-1$. We can however, let $\delta =1,\ 2,\ 2.1,\ 2.3,\ etc.$
Example 1: You have $a=4$ and you are left with $|x+6||x-4|$ (the $|x-4|$ is our $|x-a|$).
We will let $\delta =1$.
So,
$|x-4|<1$
$-1<x-4<1$. Our goal is to turn $x-4$ into $x+6$ (the expression that was multiplying with $|x-a|$). To do this, let's add $10$ to the inequalities.
$-1+10<x-4+10<1+10$
$9<x+6<11$
Example 2: You have $a=2$ and you are left with $|x+2||x-2|$ (the $|x-2|$ is our $|x-a|$)
We will let $\delta =1$.
So,
$|x-2|<1$
$-1<x-2<1$. Our goal is to turn $x-2$ into $x+2$ (the expression that was multiplying with $|x-a|$). To do this, let's add $4$ to the inequalities.
$-1+4<x-2+4<1+4$
$3<x+2<5$. Since we now have our
Example 3: You have $a=3$ and you are left with $|\frac{1}{3x}||x-3|$ (the $|x-3|\ is\ our\ |x-a|$).
We will let $\delta =1$.
So,
$|x-3|<1$
$-1<x-3<1$. Our goal is to turn $x-3$ into $\frac{1}{3x}$ (the expression that was multiplying with $|x-a|$). To do this, let us start by making the $x$ alone.
$-1+3<x-3+3<1+3$.
$2<x<4$.
Now, let's multiply everything by $3$.
$2\cdot 3<3x<4\cdot 3$
$6<3x<12$
Now, let's flip everything. Note that this will also flip the inequality signs.
$\frac{1}{6}>\frac{1}{3x}>\frac{1}{12}$, which is equal to $\frac{1}{12}<\frac{1}{3x}<\frac{1}{6}$.
Suppose step 9 gives me something like:
$-7<x-3<4$. I will first take the absolute values of the left and right numbers.
$|-7|=+7$ and $|4|=+4$. $+7$ is larger than $+4$, so $+7$ will be my upper bound and $|x-3|<7$.
Here is an image that summarizes all the rules I listed above which will hopefully help you as you solve: