Base64 relies on an encoding algorithm that describes some simple steps of converting data to Base64. And of course, since this is a reversible algorithm, you can decode Base64 into original data by simply reversing these steps. I think I’m not mistaken if I say that the simplicity of the algorithm was one of the reasons why Base64 became so popular and now it is used almost everywhere.
Of course, to get everything working properly, everyone must follow the algorithm steps given in a strict order. Therefore, if you want to know how Base64 works, I recommend reading these articles: