I am trying to understand the calculations in the following solved exercise:
Let $X$ and $Y$ two independent random variables with pdf $f(x)=2x, x\in (0,1); f(x)=0, \text{otherwise}$. Determine the pdf of $Z=X+Y$.
For $z\in (0,1)$: $$f_Z(z)=\int_{\mathbb{R}}2x 1_{(0,1)}(x) 2(z-x)1_{(z-1,z)}(x)dx=\int_{0}^{z}2x2(z-x)=\frac{2}{3}z^3.$$
For $z\in (1,2)$: $$f_Z(z)=\int_{\mathbb{R}}2x 1_{(0,1)}(x) 2(z-x)1_{(z-1,z)}(x)dx=\int_{z-1}^{1} 2x2(z-x)dx=\frac{2}{3}(6z-z^3-4).$$
I know the definition of convolution and I get why we are using it to compute the pdf of the sum of two random variables but I don't get why are the endpoints of the integral in the first case $0$ and $z$ and why are they in the second case $z-1$ and $1$?
In short, it is simply because
for $z\in(0,1)$, $$ 1_{(0,1)}(x)1_{(z-1,z)}(x)=1_{\color{red}{(0,z)}}(x) $$
for $z\in(1,2)$, $$ 1_{(0,1)}(x)1_{(z-1,z)}(x)=1_{\color{red}{(z-1,1)}}(x) $$
Notes.
Since $X$ and $Y$ are i.i.d, the joint density is $$ f_{X,Y}(x,y)=f(x)f(y) $$ and the pdf of $Z$ is given by $$ f_Z(z)=\int_{-\infty}^\infty f_{XY}(x,z-x)dx= \int_{-\infty}^\infty f(x)f(z-x)dx $$
For any given $z\in\mathbb{R}$, the integrand $f(x)f(z-x)$ is nonzero if and only if $$ 0<x<1\quad\textrm{and }\quad 0<z-x<1 $$ or equivalently, $$ 0<x<1\quad\textrm{and }\quad z-1<x<z\tag{1} $$
If the constraint (1) is nonempty, then necessarily $$ z-1<1\quad \textrm{and }\quad z>0 $$
That is why $f_Z(z)$ is only possibly nonzero for $0<z<2$.
If $z\in(0,1)$, then $z-1<1$ and thus the constraint (1) is the same as $$ 0<x<z $$
If $z\in (1,2)$, then $z>1$ and thus the constraint (1) is the same as $$ z-1<x<1 $$