Need to encode data to Base32 format in your application? This guide covers everything you need to know about Base32 encoding via API, including how it works, when to use it over Base64, and implementation examples.
What is Base32 Encoding?
Base32 encoding represents binary data using a 32-character alphabet (A-Z and 2-7). Defined in RFC 4648, it's designed to be human-readable, case-insensitive, and safe for use in URLs and file names.
Example: Hello becomes JBSWY3DP
How Base32 Encoding Works
Base32 encoding process:
Group into 5-bit chunks
Input bytes are combined and split into 5-bit groups.
Map to Alphabet
Each 5-bit value (0-31) maps to a character: A-Z (0-25) and 2-7 (26-31).
Padding
The = character is used as padding to make the output a multiple of 8 characters.
Using the Base32 Encode API
TinyFn provides a simple endpoint to encode data to Base32:
POST https://api.tinyfn.io/v1/encode/base32
Headers: X-API-Key: your-api-key
Content-Type: application/json
{
"data": "Hello, World!"
}
{
"encoded": "JBSWY3DPFQQFO33SNRSCC===",
"original_length": 13,
"encoded_length": 24
}
Parameters
| Parameter | Type | Description |
|---|---|---|
data |
string | Data to encode (required) |
padding |
boolean | Include padding characters (default: true) |
Code Examples
JavaScript / Node.js
const response = await fetch('https://api.tinyfn.io/v1/encode/base32', {
method: 'POST',
headers: {
'X-API-Key': 'your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({ data: 'Hello, World!' })
});
const result = await response.json();
console.log(result.encoded); // "JBSWY3DPFQQFO33SNRSCC==="
Python
import requests
response = requests.post(
'https://api.tinyfn.io/v1/encode/base32',
json={'data': 'Hello, World!'},
headers={'X-API-Key': 'your-api-key'}
)
result = response.json()
print(result['encoded']) # "JBSWY3DPFQQFO33SNRSCC==="
cURL
curl -X POST "https://api.tinyfn.io/v1/encode/base32" \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"data": "Hello, World!"}'
Common Use Cases
- TOTP/2FA: Encoding secrets for authenticator apps
- File Names: Creating URL-safe, case-insensitive names
- Human Entry: Encoding data users need to type manually
- DNS Records: Encoding binary data in TXT records
- Onion Addresses: Tor hidden service addresses use Base32
Best Practices
- Use for human input: Base32 is easier to read and type than Base64
- Consider efficiency: Use Base64 when size matters more than readability
- Handle padding: Some systems may not require padding characters
- Validate decoding: Always handle potential decoding errors
Use via MCP
Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:
{
"mcpServers": {
"tinyfn-encode": {
"url": "https://api.tinyfn.io/mcp/encode/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
See all encoding tools available via MCP in our Encoding MCP Tools for AI Agents guide.
Try the Base32 Encode API
Get your free API key and start encoding data in seconds.
Get Free API Key