Formula
Base64: 3 bytes → 4 characters (33% size increase)
Base64 takes 3 bytes (24 bits) and divides them into 4 groups of 6 bits. Each 6-bit value (0-63) maps to a character from the 64-character alphabet. Padding with '=' is added when input length isn't divisible by 3.
Worked Examples
Example 1: Encode Credentials for API
Problem: Create Basic Auth header: username 'admin' and password 'secret123'.
Solution: Combine with colon: admin:secret123\n\nBase64 encode:\nInput: admin:secret123\nOutput: YWRtaW46c2VjcmV0MTIz\n\nHTTP Header:\nAuthorization: Basic YWRtaW46c2VjcmV0MTIz\n\nNote: This is encoding, NOT encryption. Use HTTPS for security!
Result: YWRtaW46c2VjcmV0MTIz
Example 2: Create Data URL for Small Image
Problem: Embed a tiny 1x1 transparent PNG directly in CSS.
Solution: 1x1 transparent PNG Base64:\niVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=\n\nCSS usage:\n.element {\n background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=');\n}
Result: Data URL ready for CSS
Example 3: Decode Unknown Base64
Problem: Received Base64 string: SGVsbG8gV29ybGQh — what does it say?
Solution: Input (Base64): SGVsbG8gV29ybGQh\n\nClick 'Decode from Base64'\n\nOutput: Hello World!\n\nAnalysis:\n- 18 input characters\n- Decodes to 12 characters\n- Standard ASCII text\n- No padding needed (divisible by 4)
Result: Hello World!
Frequently Asked Questions
Why does Base64 make data larger?
Base64 increases size by approximately 33%. Every 3 bytes of input becomes 4 characters of output because you're representing 8-bit bytes with 6-bit characters. Additionally, padding ('=' characters) is added when input length isn't divisible by 3. A 1MB file becomes ~1.37MB when Base64 encoded.
When should I use Base64 encoding?
Use Base64 for: embedding images in HTML/CSS (data URLs), including binary data in JSON, sending attachments via email (MIME), storing binary in text-only databases, encoding credentials in HTTP Basic Auth, and transmitting data through text-only protocols. Don't use it for encryption—it's encoding, not security.
What is the difference between Base64 and encryption?
Base64 is encoding—it transforms data format but provides NO security. Anyone can decode Base64 instantly. Encryption scrambles data using a key, making it unreadable without the key. Never use Base64 to 'hide' sensitive data; use proper encryption (AES, RSA) for security. Base64 is for compatibility, not confidentiality.
What are Base64 URL-safe variants?
Standard Base64 uses + and / which have special meanings in URLs. URL-safe Base64 (Base64URL) replaces + with - and / with _ to avoid URL encoding issues. Some variants also omit padding (=). Use URL-safe Base64 for: query parameters, file names, JWT tokens, and anywhere URL encoding would cause problems.
Why do I get errors when decoding Base64?
Common decode errors: 1) Invalid characters (not in Base64 alphabet), 2) Incorrect padding (wrong number of = signs), 3) Truncated data (incomplete encoding), 4) Wrong variant (URL-safe vs standard), 5) Extra whitespace or line breaks. Our tool shows specific error messages to help diagnose issues.
How do I encode images as Base64?
Convert image to Base64 for use in data URLs: 1) Read image as binary, 2) Base64 encode the binary, 3) Create data URL: 'data:image/png;base64,<encoded-data>'. This embeds the image directly in HTML/CSS, reducing HTTP requests but increasing page size. Best for small images (icons, thumbnails) under 10KB.
Background & Theory
The Base64 Encoder & Decoder applies the following established principles and formulas.
Unit conversion is the process of expressing a quantity in a different unit of measurement while preserving its physical meaning. At the foundation of modern measurement lies the International System of Units (SI), which defines seven base units: the meter for length, kilogram for mass, second for time, ampere for electric current, kelvin for thermodynamic temperature, mole for amount of substance, and candela for luminous intensity. All other units, called derived units, are defined as algebraic combinations of these seven.
Dimensional analysis is the principal method for performing unit conversions. By treating units as algebraic quantities that can be multiplied, divided, and cancelled, a conversion factor chain allows a value expressed in one unit to be rewritten in another without altering its physical magnitude. For example, to convert 60 miles per hour to meters per second, one multiplies by a chain of conversion factors each equal to one: (1609.34 m / 1 mile) × (1 hour / 3600 s).
Metric prefixes enable compact expression of quantities across extreme ranges of magnitude. Standard prefixes span from nano (10^-9) through micro (10^-6) and milli (10^-3) up through kilo (10^3), mega (10^6), and giga (10^9), and beyond in both directions. These prefixes are strictly multiplicative and apply consistently to any SI base or derived unit.
Temperature conversions require affine transformations rather than simple scaling. To convert Celsius to Fahrenheit the formula is °F = (°C × 9/5) + 32, while the conversion to the absolute Kelvin scale is K = °C + 273.15. These formulas reflect the different zero points and degree-size conventions of each scale.
Significant figures govern how precision is preserved through calculations. A result should not express more precision than the least precise input value permits. In digital storage, IEEE and IEC standards distinguish between decimal prefixes (kilobyte = 1000 bytes) and binary prefixes (kibibyte = 1024 bytes), a distinction that has practical consequences for how storage capacity is reported by manufacturers versus operating systems. Unit coherence — ensuring that all quantities in an equation share a consistent unit system — is essential for obtaining correct results.
History
The history behind the Base64 Encoder & Decoder traces back through the following developments.
Human beings have been measuring and comparing quantities since before recorded history. The earliest known measurement units were body-based: the cubit (the distance from elbow to fingertip), the foot, the hand, and the digit. The furlong originated as the length of a furrow a team of oxen could plow without resting. These anthropomorphic standards were practical for local use but differed between regions and kingdoms, creating persistent difficulties in trade and construction.
The ancient Egyptians standardized the royal cubit at approximately 52.4 centimeters and distributed calibrated granite rods to ensure consistency across building projects, including the pyramids. Roman engineers used the mile (mille passuum, one thousand double paces) and spread these standards throughout their empire via road networks. Despite these efforts, measurement diversity persisted across medieval Europe, hampering commerce.
The French Revolution created political will for radical standardization. In 1795 France officially adopted the metric system, defining the meter as one ten-millionth of the distance from the equator to the North Pole along the Paris meridian. This gave the world its first fully decimal, rationally constructed measurement system. The Metre Convention of 1875 established the International Bureau of Weights and Measures (BIPM) in Sevres, France, creating a permanent international body to maintain physical artifact standards and coordinate global metrology.
For over a century, the kilogram was defined by a platinum-iridium cylinder locked in a vault near Paris. In 1999, a stark demonstration of what unit inconsistency costs occurred when NASA's Mars Climate Orbiter was lost because one engineering team used pound-force seconds while another used newton seconds. The spacecraft entered the Martian atmosphere at the wrong angle and was destroyed, at a cost of 327 million dollars.
In 2019 the SI underwent its most significant revision, redefining all seven base units in terms of fixed numerical values of fundamental physical constants such as the speed of light, Planck's constant, and the elementary charge. This eliminated any reliance on physical artifacts and made the measurement system permanently stable and universally reproducible.