$$
\begin{array}{rrrr}
&3&4&2\\
-& &5&8\\\hline
\end{array}
$$
We can't take 8 from 2, so we "borrow" one of the 4 tens from 342, and make it into 10 units instead, and add it to the 2 units we already have.
That leaves 3 tens in the tens' column, and 12 units in the units' column:
$$
\require{cancel}
\begin{array}{rrrr}
\quad &3&\color{darkred}{\cancelto{3}4}&\color{darkred}{{}^1}2\\
-& &5&8\\\hline
\end{array}
$$
What we did here is like making change: We had 4 dimes and 2 pennies, but that was not convenient because we wanted to take away 8 pennies. So we changed one of the dimes into pennies, and then we had 3 dimes and 12 pennies, and it was easy to take away 8 pennies. This "borrowing" trick is just like making change.
Then we take 8 units from 12 units, leaving 4 units:
$$
\require{cancel}
\begin{array}{rrrr}
\quad &3&{\cancelto{3}4}&{{}^1}2\\
-& &5&8\\\hline
&&&\color{darkred}{4}\end{array}
$$
So far, this is exactly what you did.
Now we want to subtract 5 tens from 3 tens, but, as you observed, we can't. So we do almost the same as before, but this time we "borrow" one of the hundreds from the 3 hundreds in the hundreds' column, and turn it into 10 tens, adding it to the 3 tens that are already in the tens' column:
$$
\require{cancel}
\begin{array}{rrrr}
\quad &\color{darkred}{\cancelto23}&\cancelto{\color{darkred}{1}3}4&{}^12\\
-& &5&8\\\hline
&&&4
\end{array}
$$
Again, this is like making change: we had 3 dollars and 3 dimes, and we changed one dollar into ten dimes, leaving 2 dollars and 13 dimes. That is allowed in arithmetic for the same reason it is allowed in money dealings: it doesn't change the actual amount!
Anyway subtracting 5 tens from 13 tens we have 8 tens:
$$
\require{cancel}
\begin{array}{rrrr}
\quad &\cancelto23&\cancelto{13}4&{}^12\\
-& &5&8\\\hline
&&\color{darkred}{8}&4
\end{array}
$$
and then 2 hundreds minus no hundreds is 2 hundreds:
$$
\require{cancel}
\begin{array}{rrrr}
\quad &\cancelto23&\cancelto{13}4&{}^12\\
-& &5&8\\\hline
&\color{darkred}{2}&8&4
\end{array}
$$
And the answer is 284.