Base 64 encoding is the process of converting bytes (8 bits) to readable, printable characters. To do this, 64 possible characters are used (6 bits), and every 3 bytes translates into 4 characters.
SQL Server generally shouldn’t need to do this. - storing binary in the database is just fine - but if you need it, here’s one way to do it.
There’s another XML function you could do, something like xs:base64Binary - or you could also use a CLR function - but this is a pretty easy way to go.