 # 🔐 Base64 Encoder/Decoder

Encode or decode Base64 strings with URL-safe support and code examples in multiple languages

 

 

   What is Base64? 

 Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format. Each Base64 digit represents exactly 6 bits of data. It's commonly used in web development for encoding images, authentication tokens, and data transmission. 

 

 ###  Encode / Decode

 ####  Input

 0 chars 

  

 

 ####  Output

 0 chars 

    

 

 

 

    **URL-Safe Encoding**Replace '+' with '-' and '/' with '_' (recommended for URLs and APIs)

  

   **Remove Padding**Remove '=' padding characters from the end (some APIs require this)

  

 

      

 

 ###  Quick Examples

     

 

 ###  Code Examples - URL-Safe Base64

       

 #### Base64 in Python

  

##### Encode URL-Safe

 ```
import base64

encoded = base64.urlsafe_b64encode(b'Hello, World!')
print(encoded)  # b'SGVsbG8sIFdvcmxkIQ=='
```

 

   

 

 

##### Decode URL-Safe

 ```
import base64

decoded = base64.urlsafe_b64decode(b'SGVsbG8sIFdvcmxkIQ==')
print(decoded)  # b'Hello, World!'
```

 

   

 

 

 

 

 #### Base64 in PHP

  

##### Encode URL-Safe

 ```
function urlsafeEncode(string $input) {
    return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
}
```

 

   

 

 

##### Decode URL-Safe

 ```
function urlsafeDecode(string $input) {
    $remainder = strlen($input) % 4;
    if ($remainder) {
        $padlen = 4 - $remainder;
        $input .= str_repeat('=', $padlen);
    }
    return base64_decode(strtr($input, '-_', '+/'));
}
```

 

   

 

 

 

 

 #### Base64 in JavaScript (Node.js)

  

##### Encode URL-Safe

 ```
const encoded = Buffer.from('Hello, World!').toString('base64url');
console.log(encoded);
```

 

   

 

 

##### Decode URL-Safe

 ```
const decoded = Buffer.from(encoded, 'base64url').toString('utf-8');
console.log(decoded);
```

 

   

 

 

 

 

 #### Base64 in Go

  

##### Encode URL-Safe

 ```
encoded := base64.RawURLEncoding.EncodeToString([]byte("Hello, World!"))
```

 

   

 

 

##### Decode URL-Safe

 ```
decoded, err := base64.RawURLEncoding.DecodeString(encoded)
```

 

   

 

 

 

 

 #### Base64 in C#

  

##### Encode URL-Safe

 ```
string encoded = Base64UrlEncoder.Encode("Hello, World!");
```

 

   

 

 

##### Decode URL-Safe

 ```
string decoded = Base64UrlEncoder.Decode(encoded);
```

 

   

 

 

 

 

 #### Base64 in Rust

  

##### Encode URL-Safe

 ```
let encoded = base64_url::encode("Hello, World!");
```

 

   

 

 

##### Decode URL-Safe

 ```
let decoded = base64_url::decode(&encoded).unwrap();
```

 

   

 

 

 

 

 

 

 ###  Need Help?

 Found a bug or something missing? [Contact our support team](https://scrapfly.io/docs/support#contact) or [contribute on GitHub](https://github.com/scrapfly).