Try it Live
Run Base64 examples in the interactive playground
Decoding
Methods for decoding base64 strings to binary data and UTF-8 strings.Standard Base64 Decoding
- TypeScript
Base64.decode(encoded)
Decodes standard base64 string to bytes. Accepts strings encoded with RFC 4648 alphabet (A-Z, a-z, 0-9, +, /) with padding.encoded: string- Base64 string to decode
Uint8Array - Decoded binary dataThrows:Error- If input is invalid base64 format
Base64.decodeToString(encoded)
Decodes base64 string directly to UTF-8 string. Combines base64 decoding with TextDecoder for convenience.
encoded: string- Base64 string to decode
string - Decoded UTF-8 string
Throws:
Error- If input is invalid base64 format
URL-Safe Base64 Decoding
- TypeScript
Base64.decodeUrlSafe(encoded)
Decodes URL-safe base64 string to bytes. Accepts strings encoded with URL-safe alphabet (A-Z, a-z, 0-9, -, _) without padding.Automatically handles:- Missing padding characters
- URL-safe character substitutions (- → +, _ → /)
encoded: string- URL-safe base64 string (without padding)
Uint8Array - Decoded binary dataThrows:Error- If input is invalid base64 format
Base64.decodeUrlSafeToString(encoded)
Decodes URL-safe base64 string directly to UTF-8 string. Combines URL-safe decoding with TextDecoder.
encoded: string- URL-safe base64 string
string - Decoded UTF-8 string
Throws:
Error- If input is invalid
Usage Patterns
Safe Decoding with Validation
Decoding with Size Calculation
Auto-detecting Format
Streaming Decoding
JSON Decoding
Error Handling
Decoding Binary Types
Decoding Algorithm
Standard base64 decoding process:- Validate format: Check for valid base64 characters and padding
- Remove padding: Strip trailing
=characters - Convert from base64: Each 4 base64 characters become 3 bytes
- Return bytes: Construct
Uint8Arrayfrom decoded data
Visual: 4 Characters → 3 Bytes
Complete Example: “SGVsbG8=” → “Hello”
==(2 padding): Lost 2 bits, actual length -2 bytes=(1 padding): Lost 1 bit, actual length -1 byte- No padding: Complete 3-byte group
- Output length =
floor(input.length * 3 / 4) - padding_count
Related
- Encoding - Encoding to base64 format
- Validation - Validating base64 strings
- Utilities - Size calculations
- BrandedBase64 - Tree-shakeable API

