-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase64-encoder.html
More file actions
984 lines (876 loc) · 56 KB
/
Copy pathbase64-encoder.html
File metadata and controls
984 lines (876 loc) · 56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Base64 Encoder & Decoder — Text & File | FreeDevTool</title>
<meta name="description" content="Free Base64 encoder and decoder. Standard & URL-safe modes, text + file (image, PDF) support, RFC 4648 compliant. Runs in browser, no upload.">
<meta name="robots" content="index, follow">
<meta name="author" content="Anees Ur Rehman">
<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","datePublished":"2026-05-02","dateModified":"2026-05-19","inLanguage":"en-US","isPartOf":{"@type":"WebSite","name":"FreeDevTool","url":"https://freedevtool.org"}}</script>
<script type="application/ld+json">{"@context":"https://schema.org","@type":"Person","name":"Anees Ur Rehman","url":"https://freedevtool.org/about","jobTitle":"Full-stack developer","worksFor":{"@type":"Organization","name":"FreeDevTool","url":"https://freedevtool.org"}}</script>
<link rel="canonical" href="https://freedevtool.org/base64-encoder">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="preload" href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&family=DM+Sans:wght@300;400;500;600&display=swap" as="style">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&family=DM+Sans:wght@300;400;500;600&display=swap">
<link rel="preload" href="style.css?v=20260502-cards" as="style">
<link rel="stylesheet" href="style.css?v=20260502-cards">
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/favicon.svg">
<meta property="og:image" content="https://freedevtool.org/og-image.svg">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:alt" content="FreeDevTool — 50+ free, fast, privacy-first developer tools">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://freedevtool.org/og-image.svg">
<meta name="twitter:title" content="Base64 Encoder & Decoder Online — Free | FreeDevTool">
<meta name="twitter:description" content="Encode/decode text & files to Base64. Standard & URL-safe variants, runs in browser, no uploads, no signup.">
<!-- Google Analytics 4 -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-3L0CMH3X36"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-3L0CMH3X36');
</script>
<meta property="og:title" content="Base64 Encoder & Decoder — FreeDevTool">
<meta property="og:description" content="Free online Base64 encoder and decoder. Instant results, no sign-up.">
<meta property="og:url" content="https://freedevtool.org/base64-encoder">
<meta property="og:type" content="website">
<meta property="og:site_name" content="FreeDevTool">
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "SoftwareApplication",
"name": "Base64 Encoder Decoder",
"applicationCategory": "DeveloperApplication",
"operatingSystem": "Web Browser",
"offers": { "@type": "Offer", "price": "0", "priceCurrency": "USD" },
"description": "Free online Base64 encoder and decoder tool"
}
</script>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
{
"@type": "Question",
"name": "What is Base64 encoding?",
"acceptedAnswer": { "@type": "Answer", "text": "Base64 is a binary-to-text encoding scheme that converts binary data into a string of ASCII characters using 64 printable characters (A-Z, a-z, 0-9, +, /). It is used to safely transmit binary data over text-based protocols like HTTP, email (MIME), or embed binary files in JSON and XML." }
},
{
"@type": "Question",
"name": "When should I use Base64 encoding?",
"acceptedAnswer": { "@type": "Answer", "text": "Use Base64 when you need to embed binary data (images, files, certificates) in a text format, send binary data over email or HTTP, store binary data in JSON, HTML, or CSS, or when working with Basic Auth headers in HTTP (username:password encoded as Base64)." }
},
{
"@type": "Question",
"name": "Does Base64 encoding encrypt my data?",
"acceptedAnswer": { "@type": "Answer", "text": "No. Base64 is encoding, not encryption. It is trivially reversible and provides no security. Anyone can decode a Base64 string without a key. Do not use Base64 to secure sensitive data — use proper encryption (AES, RSA) for that purpose." }
},
{
"@type": "Question",
"name": "Why does Base64 output end with = or ==?",
"acceptedAnswer": { "@type": "Answer", "text": "Base64 encodes every 3 bytes of input into 4 characters. If the input length is not divisible by 3, padding characters (=) are added to make the output length a multiple of 4. One = means 1 byte of padding was added, == means 2 bytes." }
},
{
"@type": "Question",
"name": "What is URL-safe Base64?",
"acceptedAnswer": { "@type": "Answer", "text": "Standard Base64 uses + and / which are reserved characters in URLs. URL-safe Base64 replaces + with - and / with _, making the output safe to use in URLs and filenames without percent-encoding." }
},{"@type":"Question","name":"Is Base64 encoding safe for sensitive data?","acceptedAnswer":{"@type":"Answer","text":"Base64 is encoding, not encryption — anyone can decode a Base64 string in seconds without a key. Do not treat Base64 as a privacy mechanism. Use proper encryption (AES, RSA) for confidentiality. Base64 is for binary-to-text conversion only."}},{"@type":"Question","name":"How much does Base64 increase file size?","acceptedAnswer":{"@type":"Answer","text":"Base64 increases size by approximately 33% (3 input bytes become 4 output characters). A 1 MB binary becomes about 1.33 MB Base64 text. After gzip the overhead largely disappears, but uncompressed network and memory size is still 33% larger."}},{"@type":"Question","name":"What is the difference between Base64 and Base64URL?","acceptedAnswer":{"@type":"Answer","text":"Standard Base64 (RFC 4648 section 4) uses plus and slash which are reserved in URLs. URL-safe Base64 (section 5) replaces plus with hyphen and slash with underscore, making the output safe in URL paths and query strings without percent-encoding. JWTs always use Base64URL."}}
]
}
</script>
<style>
.file-drop {
border: 2px dashed var(--border2);
border-radius: var(--radius);
padding: 28px 20px;
text-align: center;
cursor: pointer;
transition: border-color .2s, background .2s;
position: relative;
}
.file-drop:hover, .file-drop.dragover {
border-color: var(--accent2);
background: var(--accent-dim);
}
.file-drop input[type="file"] {
position: absolute; inset: 0; opacity: 0; cursor: pointer;
}
.file-drop-icon { font-size: 28px; margin-bottom: 8px; }
.file-drop p { font-size: 13px; color: var(--text2); }
.file-drop strong { color: var(--accent); }
.char-count {
font-family: var(--mono); font-size: 11px;
color: var(--text3); text-align: right; margin-top: 4px;
}
</style>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"position": 1,
"name": "Home",
"item": "https://freedevtool.org/"
},
{
"@type": "ListItem",
"position": 2,
"name": "All Tools",
"item": "https://freedevtool.org/all-tools"
},
{
"@type": "ListItem",
"position": 3,
"name": "Base64 Encoder / Decoder",
"item": "https://freedevtool.org/base64-encoder"
}
]
}
</script>
<script src="/ga4-events.js" defer></script>
</head>
<body>
<nav>
<a class="nav-logo" href="/" aria-label="FreeDevTool home"><svg class="logo-mark" width="22" height="22" viewBox="0 0 24 24" aria-hidden="true" fill="none"><rect x="1" y="1" width="22" height="22" rx="6" fill="currentColor" opacity=".12"/><path d="M9.5 8.5L6 12l3.5 3.5M14.5 8.5L18 12l-3.5 3.5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>FreeDevTool</a>
<div class="nav-links">
<div class="nav-dropdown" id="tools-dropdown">
<a href="all-tools" onclick="event.preventDefault();this.parentElement.classList.toggle('open')" aria-haspopup="true">Tools <svg class="chev" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg></a>
<div class="nav-dropdown-menu">
<a href="encoding-tools">
<div class="dd-icon">b64</div>
<div class="dd-info"><div class="dd-name">Encoding & Conversion</div><div class="dd-count">11 tools · Base64, YAML, px→rem</div></div>
</a>
<a href="generation-tools">
<div class="dd-icon">{ }</div>
<div class="dd-info"><div class="dd-name">Generation & Formatting</div><div class="dd-count">16 tools · JSON, SQL, gradients</div></div>
</a>
<a href="security-tools">
<div class="dd-icon">#</div>
<div class="dd-info"><div class="dd-name">Security & Hashing</div><div class="dd-count">3 tools · JWT, MD5, SHA</div></div>
</a>
<a href="text-tools">
<div class="dd-icon">.*</div>
<div class="dd-info"><div class="dd-name">Code & Text Tools</div><div class="dd-count">9 tools · Regex, diff, tokens</div></div>
</a>
<a href="devops-tools">
<div class="dd-icon">JS</div>
<div class="dd-info"><div class="dd-name">Optimization & DevOps</div><div class="dd-count">7 tools · Minifiers, cURL, git</div></div>
</a>
<a href="network-tools">
<div class="dd-icon">IP</div>
<div class="dd-info"><div class="dd-name">Network & Time</div><div class="dd-count">4 tools · IP, DNS, timestamps</div></div>
</a>
<a href="seo-tools">
<div class="dd-icon">SEO</div>
<div class="dd-info"><div class="dd-name">SEO & Meta Tools</div><div class="dd-count">3 tools · OG, meta, slug</div></div>
</a>
<div class="nav-dropdown-divider"></div>
<a class="dd-all" href="all-tools">
<div class="dd-icon">All</div>
<div class="dd-info"><div class="dd-name">Browse all 50 tools</div><div class="dd-count">Searchable catalog & categories</div></div>
</a>
</div>
</div>
<a href="/guides">Guides</a>
<a href="about">About</a>
<a href="privacy">Privacy</a>
</div>
</nav>
<div id="copy-toast">Copied!</div>
<div class="wrapper">
<a class="tool-back" href="/" aria-label="Back to home">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M15 18l-6-6 6-6"/></svg>
Back
</a>
<div class="tool-header">
<div class="tool-badge">Encoding Tool</div>
<h1>Base64 Encoder & Decoder Online</h1>
<p class="tool-description">
Encode any text or file to Base64, or decode a Base64 string back to plain text instantly. This free Base64 encoder supports both standard and URL-safe variants per <a href="https://datatracker.ietf.org/doc/html/rfc4648" rel="noopener" style="color:var(--accent)">RFC 4648</a>. Paste text, drag-and-drop a file (image, PDF, anything binary), or switch to decode mode. All processing happens in your browser using the native <code>btoa</code>/<code>atob</code> and <code>FileReader</code> APIs — files are never uploaded to a server. Works offline, no signup required.
</p>
<div class="last-updated">Last updated: May 2026 · Written by <a href="/about">Anees Ur Rehman</a>, full-stack developer</div>
</div>
<div class="tool-card">
<div class="tool-card-header">
<div class="dot dot-red"></div>
<div class="dot dot-yellow"></div>
<div class="dot dot-green"></div>
<span class="tool-card-title">base64-encoder.tool</span>
</div>
<div class="tool-body">
<div class="tabs">
<button class="tab active" onclick="setMode('encode', this)">Encode</button>
<button class="tab" onclick="setMode('decode', this)">Decode</button>
<button class="tab" onclick="setMode('file', this)">File → Base64</button>
</div>
<!-- ENCODE -->
<div id="mode-encode">
<label>Plain text to encode</label>
<textarea id="encode-input" placeholder="Enter text to encode..." oninput="doEncode()" rows="5"></textarea>
<div class="char-count" id="encode-count">0 characters</div>
<div style="display:flex; align-items:center; gap:12px; margin-top:10px; flex-wrap:wrap">
<label style="margin:0; display:flex; align-items:center; gap:6px; font-size:12px; text-transform:none; letter-spacing:normal; cursor:pointer">
<input type="checkbox" id="url-safe-enc" onchange="doEncode()"> URL-safe Base64
</label>
</div>
<div class="divider"></div>
<div class="output-label">
<label style="margin:0">Base64 Output</label>
<button class="btn btn-ghost" onclick="copyOutput('encode-output')">Copy</button>
</div>
<div class="output-block" id="encode-output" style="color:var(--text2); font-style:italic">Output will appear here...</div>
<div class="char-count" id="encode-out-count"></div>
</div>
<!-- DECODE -->
<div id="mode-decode" style="display:none">
<label>Base64 string to decode</label>
<textarea id="decode-input" placeholder="Paste Base64 string here..." oninput="doDecode()" rows="5"></textarea>
<div class="char-count" id="decode-count">0 characters</div>
<div class="divider"></div>
<div class="output-label">
<label style="margin:0">Decoded Output</label>
<button class="btn btn-ghost" onclick="copyOutput('decode-output')">Copy</button>
</div>
<div class="output-block" id="decode-output" style="color:var(--text2); font-style:italic">Output will appear here...</div>
<div id="decode-status"></div>
</div>
<!-- FILE -->
<div id="mode-file" style="display:none">
<div class="file-drop" id="file-drop" ondragover="onDragOver(event)" ondragleave="onDragLeave(event)" ondrop="onDrop(event)">
<input type="file" id="file-input" onchange="onFileSelect(event)">
<div class="file-drop-icon">📁</div>
<p><strong>Click to select a file</strong> or drag and drop it here</p>
<p style="margin-top:4px; font-size:12px">Any file type · Max 5 MB</p>
</div>
<div id="file-info" style="display:none; margin-top:12px">
<div class="status status-ok" id="file-status">—</div>
<div class="divider"></div>
<div class="output-label">
<label style="margin:0">Base64 Output</label>
<button class="btn btn-ghost" onclick="copyOutput('file-output')">Copy</button>
</div>
<div class="output-block" id="file-output" style="max-height:160px; overflow:auto"></div>
<div class="btn-row" style="margin-top:12px">
<button class="btn btn-secondary" onclick="copyDataUri()">Copy as Data URI</button>
</div>
</div>
</div>
</div>
</div>
<!-- =============================================================
LONG-FORM ARTICLE — comprehensive guide for E-E-A-T + ranking.
============================================================= -->
<article>
<p class="aeo-lead" style="font-size:16px;line-height:1.7;color:var(--text);max-width:760px;margin:24px auto 18px;padding:0 4px">
<strong>Base64</strong> is a binary-to-text encoding scheme (RFC 4648) that represents binary data using 64 printable ASCII characters, with optional padding equals signs. It is used to safely embed images, certificates, and other binary payloads in JSON, HTML, email, and HTTP headers. This <strong>free Base64 encoder and decoder</strong> handles UTF-8 multi-byte input, URL-safe Base64 (with - and _ replacements), and binary files — entirely in your browser.
</p>
<section id="examples" style="max-width:760px;margin:24px auto 32px">
<h2 style="font-size:18px;margin-bottom:14px">Examples</h2>
<div style="background:var(--bg3);border:1px solid var(--border);border-radius:var(--radius);padding:16px;margin-bottom:12px">
<strong style="display:block;color:var(--accent);font-family:var(--mono);font-size:11px;text-transform:uppercase;letter-spacing:1px;margin-bottom:6px">Plain text to Base64§§Input: Hello, World!§§Base64: SGVsbG8sIFdvcmxkIQ==§§The trailing == is padding because the input is not a multiple of 3 bytes.</strong>
</div>
<div style="background:var(--bg3);border:1px solid var(--border);border-radius:var(--radius);padding:16px;margin-bottom:12px">
<strong style="display:block;color:var(--accent);font-family:var(--mono);font-size:11px;text-transform:uppercase;letter-spacing:1px;margin-bottom:6px">URL-safe variant§§Standard: abc+/123==§§URL-safe: abc-_123==§§The + becomes -, the / becomes _. Safe to put in URLs and filenames without percent-encoding.</strong>
</div>
<div style="background:var(--bg3);border:1px solid var(--border);border-radius:var(--radius);padding:16px;margin-bottom:12px">
<strong style="display:block;color:var(--accent);font-family:var(--mono);font-size:11px;text-transform:uppercase;letter-spacing:1px;margin-bottom:6px">Basic Auth header§§Username "alice" and password "s3cret" become Basic YWxpY2U6czNjcmV0 in an HTTP Authorization header — Base64 of "alice:s3cret".</strong>
</div>
</section>
<aside class="founder-note" style="max-width:760px;margin:24px auto 32px;padding:20px 24px;background:rgba(0,208,132,0.05);border-left:3px solid var(--accent);border-radius:6px;font-size:14px;line-height:1.7;color:var(--text2)">
<div style="font-family:var(--mono);font-size:11px;color:var(--accent);letter-spacing:1.5px;text-transform:uppercase;margin-bottom:10px;font-weight:600">💡 Why I built this</div>
<p style="margin:0 0 12px">I built this because base64decode.org and base64encode.org are functionally fine, but both load ads. I once pasted a Basic Auth header into one of them while debugging an API and immediately thought: those ads are running JavaScript on the same page where my credentials just rendered. Probably nothing happened. Probably. This encoder runs entirely client-side, no ads, no third-party scripts beyond anonymous Google Analytics for page views. Network tab in DevTools shows nothing fires when you encode or decode. Source is static HTML — you can read every line of JavaScript that touches your input.</p>
<p style="margin:0;font-size:13px;color:var(--text3)">— <a href="/about" style="color:var(--accent);text-decoration:none">Anees Ur Rehman</a>, full-stack developer</p>
</aside>
<section class="article-section">
<h2>What is Base64 encoding?</h2>
<p><strong>Base64</strong> is a binary-to-text encoding scheme that represents binary data using a 64-character alphabet of printable ASCII letters. The standard is defined in <a href="https://datatracker.ietf.org/doc/html/rfc4648" rel="noopener">RFC 4648</a>, which formalizes both the "standard" alphabet (used in MIME, PEM certificates, and most APIs) and a <strong>URL-safe</strong> variant. Base64 was created in 1987 to solve a specific problem: how to send 8-bit binary data — images, executables, certificates — through 7-bit ASCII channels like email and early text-based protocols that would corrupt anything outside the printable range.</p>
<p>The 64-character alphabet is the union of three groups: uppercase letters <code>A–Z</code> (26), lowercase letters <code>a–z</code> (26), digits <code>0–9</code> (10), plus two extras — <code>+</code> and <code>/</code> for standard Base64, or <code>-</code> and <code>_</code> for URL-safe Base64. Plus an optional <code>=</code> padding character (technically the 65th symbol, but never represents data). Every Base64 character encodes exactly 6 bits of input, so 3 bytes of binary input (24 bits) fit perfectly into 4 Base64 characters. This 3-to-4 ratio explains the famous <strong>33% size overhead</strong> — 1 KB of binary becomes 1.33 KB of Base64.</p>
<p>Despite being a simple encoding (not encryption), Base64 is everywhere: JSON Web Tokens (JWTs) use Base64URL for header, payload, and signature; HTTP Basic Auth wraps <code>username:password</code> in Base64; PEM-encoded certificates and SSH keys are Base64; email attachments use Base64 inside MIME; data URIs (<code>data:image/png;base64,...</code>) inline images in HTML and CSS. Knowing exactly when Base64 helps versus when it hurts (it's not encryption, it's not compression, it inflates payloads) is a core developer skill.</p>
</section>
<section class="article-section">
<h2>How Base64 encoding works under the hood</h2>
<p>The algorithm is a simple bit-regrouping. Imagine encoding the 3-byte ASCII string <code>"Sun"</code>:</p>
<table class="ref-table">
<thead><tr><th>Step</th><th>Value</th></tr></thead>
<tbody>
<tr><td>Input characters</td><td><code>S u n</code></td></tr>
<tr><td>ASCII / byte values</td><td><code>83 117 110</code></td></tr>
<tr><td>Binary (3 × 8 bits = 24 bits)</td><td><code>01010011 01110101 01101110</code></td></tr>
<tr><td>Re-grouped into 6-bit chunks</td><td><code>010100 110111 010101 101110</code></td></tr>
<tr><td>Decimal values of each 6-bit chunk</td><td><code>20 55 21 46</code></td></tr>
<tr><td>Map to Base64 alphabet</td><td><code>U 3 V u</code></td></tr>
<tr><td>Final Base64 output</td><td><code>U3Vu</code></td></tr>
</tbody>
</table>
<h3>Padding rules — why you see <code>=</code> at the end</h3>
<p>Base64 always emits multiples of 4 characters. If your input length isn't divisible by 3, the encoder pads the missing bytes with zero bits and signals the padding with <code>=</code> characters at the end:</p>
<ul>
<li><strong>1 byte input</strong> → 2 Base64 chars + <code>==</code> (e.g. <code>"M"</code> → <code>"TQ=="</code>)</li>
<li><strong>2 byte input</strong> → 3 Base64 chars + <code>=</code> (e.g. <code>"Ma"</code> → <code>"TWE="</code>)</li>
<li><strong>3 byte input</strong> → 4 Base64 chars, no padding (e.g. <code>"Man"</code> → <code>"TWFu"</code>)</li>
</ul>
<p>Some implementations omit padding (RFC 4648 §3.2 allows it). When decoding, modern libraries handle both padded and unpadded inputs; older implementations may require <code>=</code>. If you see a "Invalid base64" error, try adding <code>=</code> to round the length up to a multiple of 4.</p>
</section>
<section class="article-section">
<h2>Standard vs URL-safe Base64 — the two variants</h2>
<p>Standard Base64 uses <code>+</code> and <code>/</code> for the last two alphabet positions. Both are reserved characters in URLs, query strings, and filenames. So a Base64 string like <code>aGVsbG8/d29ybGQ+</code> embedded into a URL would be misinterpreted: <code>?</code> becomes a query delimiter, <code>+</code> becomes a space in form-encoded contexts. RFC 4648 §5 defines a URL-safe variant that swaps these with URL-friendly substitutes:</p>
<table class="ref-table">
<thead><tr><th>Position</th><th>Standard (RFC 4648 §4)</th><th>URL-safe (RFC 4648 §5)</th></tr></thead>
<tbody>
<tr><td>62 (0x3E)</td><td><code>+</code></td><td><code>-</code></td></tr>
<tr><td>63 (0x3F)</td><td><code>/</code></td><td><code>_</code></td></tr>
<tr><td>Padding</td><td><code>=</code> (required by some, optional by others)</td><td><code>=</code> usually omitted</td></tr>
</tbody>
</table>
<p><strong>When to use which:</strong></p>
<ul>
<li><strong>Standard Base64</strong> — email attachments (MIME), PEM certificates, HTTP Basic Auth, traditional APIs, anywhere the output isn't going into a URL or filename.</li>
<li><strong>URL-safe Base64</strong> — JWTs (mandatory per RFC 7515), URL parameters, OAuth flows, filenames, cookies, form fields.</li>
</ul>
<div class="article-aside">
<strong>Conversion tip:</strong> if you have a standard Base64 string and need it URL-safe, just substitute <code>+ → -</code>, <code>/ → _</code>, and strip trailing <code>=</code>. The reverse works to decode URL-safe Base64 with a standard decoder. This tool's "URL-safe" toggle does the substitution automatically.
</div>
</section>
<section class="article-section">
<h2>When to use Base64 — and when not to</h2>
<h3>Good fits for Base64</h3>
<ul>
<li><strong>JWT (JSON Web Tokens)</strong> — header and payload are JSON objects, Base64URL-encoded so they survive transport in HTTP headers, cookies, and URL query parameters.</li>
<li><strong>HTTP Basic Auth</strong> — the <code>Authorization: Basic ...</code> header carries <code>username:password</code> Base64-encoded. Not encryption, just encoding for HTTP-safe transport. Use HTTPS to actually protect the credentials.</li>
<li><strong>PEM certificates & keys</strong> — <code>-----BEGIN CERTIFICATE-----</code> wraps Base64-encoded DER bytes. The text format makes them paste-friendly across systems.</li>
<li><strong>MIME email attachments</strong> — SMTP was designed for 7-bit text; Base64 lets binary attachments survive intact.</li>
<li><strong>Tiny inline images (data URIs)</strong> — for icons under 4 KB, a <code>data:image/svg+xml;base64,...</code> URL eliminates an HTTP request. Use sparingly: the 33% overhead and lack of caching make this counterproductive at larger sizes.</li>
<li><strong>Embedding binary in JSON or XML</strong> — when you can't use multipart upload and absolutely must put binary in a structured text field.</li>
<li><strong>QR code data</strong> — when encoding binary payloads (digital business cards, encrypted handshakes).</li>
</ul>
<h3>Bad fits for Base64</h3>
<ul>
<li><strong>Encryption substitute.</strong> Base64 is reversible by anyone in 1 millisecond. Encoding API keys or passwords in Base64 is security theater.</li>
<li><strong>Compression.</strong> Base64 <em>increases</em> size by 33%. If size matters, gzip the binary first, then Base64 the gzipped output.</li>
<li><strong>Large file uploads.</strong> Inflating a 10 MB image to 13.3 MB Base64 string just to put it in JSON wastes bandwidth and parser memory. Use multipart/form-data uploads instead.</li>
<li><strong>Long-term storage of large blobs.</strong> Database columns of Base64 BLOBs cost ~33% more storage and slow scans. Store raw bytes (BLOB / BYTEA) and encode at the API edge if needed.</li>
</ul>
</section>
<section class="article-section">
<h2>Base64 in 8 programming languages</h2>
<h3>JavaScript / Browser</h3>
<div class="lang-block">
<div class="lang-block-header">javascript</div>
<pre><code>// ASCII / Latin-1 only — for full Unicode see below
btoa("hello world"); // → "aGVsbG8gd29ybGQ="
atob("aGVsbG8gd29ybGQ="); // → "hello world"
// Unicode-safe encode (modern browsers)
const utf8 = new TextEncoder().encode("café 中文");
const b64 = btoa(String.fromCharCode(...utf8));
// URL-safe Base64
const urlSafe = b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
// File → Base64 (FileReader, async)
const reader = new FileReader();
reader.onload = () => console.log(reader.result.split(',')[1]);
reader.readAsDataURL(file); // produces "data:...;base64,XXXXXX"
</code></pre>
</div>
<h3>Node.js</h3>
<div class="lang-block">
<div class="lang-block-header">node.js</div>
<pre><code>// Buffer — Unicode-safe by default
const b64 = Buffer.from("hello world").toString('base64'); // "aGVsbG8gd29ybGQ="
const dec = Buffer.from(b64, 'base64').toString(); // "hello world"
// URL-safe variant (Node 16+)
const urlSafe = Buffer.from(data).toString('base64url');
// Encode a file
import { readFile } from 'node:fs/promises';
const b64File = (await readFile('image.png')).toString('base64');
</code></pre>
</div>
<h3>Python</h3>
<div class="lang-block">
<div class="lang-block-header">python</div>
<pre><code>import base64
# Standard
encoded = base64.b64encode(b"hello world").decode() # 'aGVsbG8gd29ybGQ='
decoded = base64.b64decode("aGVsbG8gd29ybGQ=").decode() # 'hello world'
# URL-safe (no padding by convention; add back for decode if needed)
url_safe = base64.urlsafe_b64encode(b"hello").rstrip(b'=').decode()
# 'aGVsbG8' (5-byte input = 1 padding char stripped)
# Encode a file
with open('image.png', 'rb') as f:
b64_file = base64.b64encode(f.read()).decode()
</code></pre>
</div>
<h3>PHP</h3>
<div class="lang-block">
<div class="lang-block-header">php</div>
<pre><code>// Standard Base64
$encoded = base64_encode("hello world"); // "aGVsbG8gd29ybGQ="
$decoded = base64_decode("aGVsbG8gd29ybGQ="); // "hello world"
// URL-safe (manual swap — PHP has no built-in)
function base64UrlEncode(string $data): string {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
function base64UrlDecode(string $data): string {
return base64_decode(strtr($data, '-_', '+/'));
}
// Encode a file
$b64File = base64_encode(file_get_contents('image.png'));
</code></pre>
</div>
<h3>Java</h3>
<div class="lang-block">
<div class="lang-block-header">java</div>
<pre><code>import java.util.Base64;
// Standard
String encoded = Base64.getEncoder().encodeToString("hello world".getBytes());
byte[] decoded = Base64.getDecoder().decode(encoded);
// URL-safe (no padding)
String urlSafe = Base64.getUrlEncoder().withoutPadding().encodeToString(data);
byte[] back = Base64.getUrlDecoder().decode(urlSafe);
// File → Base64
byte[] bytes = Files.readAllBytes(Paths.get("image.png"));
String b64 = Base64.getEncoder().encodeToString(bytes);
</code></pre>
</div>
<h3>Go</h3>
<div class="lang-block">
<div class="lang-block-header">go</div>
<pre><code>import "encoding/base64"
// Standard
encoded := base64.StdEncoding.EncodeToString([]byte("hello world"))
decoded, _ := base64.StdEncoding.DecodeString(encoded)
// URL-safe (no padding)
urlSafe := base64.RawURLEncoding.EncodeToString([]byte("hello"))
decoded, _ = base64.RawURLEncoding.DecodeString(urlSafe)
</code></pre>
</div>
<h3>Rust</h3>
<div class="lang-block">
<div class="lang-block-header">rust</div>
<pre><code>use base64::{engine::general_purpose, Engine as _};
// Standard
let encoded = general_purpose::STANDARD.encode(b"hello world");
let decoded = general_purpose::STANDARD.decode(encoded)?;
// URL-safe, no padding
let url_safe = general_purpose::URL_SAFE_NO_PAD.encode(b"hello");
</code></pre>
</div>
<h3>Bash</h3>
<div class="lang-block">
<div class="lang-block-header">bash</div>
<pre><code># Standard encode / decode
echo -n "hello world" | base64 # "aGVsbG8gd29ybGQ="
echo -n "aGVsbG8gd29ybGQ=" | base64 -d # "hello world"
# Encode a file (single line, no wrapping)
base64 -w 0 image.png > image.b64
# Decode back to a file
base64 -d image.b64 > image.png
# URL-safe variant via tr
echo -n "data" | base64 | tr '+/' '-_' | tr -d '='
</code></pre>
</div>
</section>
<section class="article-section">
<h2>Data URIs — embedding files inline</h2>
<p>A <strong>data URI</strong> packs a small file directly into a URL using Base64. Browsers, mail clients, and most image renderers treat it like a normal URL but read the bytes inline instead of fetching them. The format:</p>
<div class="lang-block">
<div class="lang-block-header">data-uri-format</div>
<pre><code>data:[<mediatype>][;base64],<data>
// Example: 1×1 transparent PNG
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGNgAAIAAAUAAeImBZsAAAAASUVORK5CYII=
// SVG (often smaller without Base64)
data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'>...</svg>
</code></pre>
</div>
<h3>When data URIs make sense</h3>
<ul>
<li>Single-pixel tracking GIFs and 1×1 placeholders (under 100 bytes).</li>
<li>Small icons in CSS where avoiding an HTTP request matters more than caching (under 4 KB rule of thumb).</li>
<li>Email signatures with embedded logos that must work offline.</li>
<li>Generated previews (e.g. <code>FileReader.readAsDataURL</code> for image upload preview).</li>
</ul>
<h3>When NOT to use them</h3>
<ul>
<li>Anything larger than 4 KB — the 33% Base64 overhead plus the inability to cache the asset hurts more than it helps. Use a regular HTTP request.</li>
<li>Production images that appear on multiple pages — caching wins.</li>
<li>Anything that needs to be lazy-loaded or preloaded — data URIs can't be.</li>
</ul>
</section>
<section class="article-section">
<h2>Encode Base64 online — common queries answered</h2>
<p>Variations of "encode base64" all route to the same workflow: paste text or drop a file, copy the encoded string. The most common targeted use cases users land on this page for:</p>
<h3>Base64 encode an image (PNG, JPG, SVG, WebP)</h3>
<p>Drop any image file onto the upload zone above and the encoder reads it locally with <code>FileReader</code>, produces the standard Base64 string, and (optionally) wraps it in a <code>data:image/png;base64,</code> URI ready for inline use. The encoding happens in-browser — your image bytes never leave the device, which matters for screenshots that contain sensitive UI or unreleased designs. For the <em>resulting</em> data URI, embed it directly in CSS <code>background-image: url(data:image/png;base64,…)</code> or in HTML <code><img src="data:image/png;base64,…"></code>. Avoid this pattern for images larger than ~10 KB — Base64 inflates payload by ~33%, and inline images can't be cached separately by the browser.</p>
<h3>Base64 encoders — Standard (RFC 4648 §4) vs URL-safe (RFC 4648 §5)</h3>
<p>Two valid Base64 alphabets, and the choice matters: <strong>Standard</strong> uses <code>+</code> and <code>/</code> as the 63rd and 64th characters and pads with <code>=</code>; <strong>URL-safe</strong> swaps to <code>-</code> and <code>_</code> and often drops padding. Use Standard for HTTP body content, email MIME, and database <code>BLOB</code> columns. Use URL-safe in JWT segments, URL path/query parameters, and file names — anywhere a literal <code>+</code> or <code>/</code> would be reinterpreted by a parser. The toggle above switches between both alphabets without re-encoding the source bytes.</p>
<h3>Base64encoder vs base64encode — naming, not behavior</h3>
<p>The unified search query "base64encoder" (no space) and the imperative "base64 encode" map to the same intent. Some services brand themselves as "Base64Encoder", others as "Base64 encoder online", but the underlying operation is RFC 4648 §4. The encoder above accepts text or files, runs locally, and produces output identical to <code>base64</code> on macOS/Linux, <code>certutil -encode</code> on Windows, and <code>btoa()</code> in the browser console (for ASCII strings only — <code>btoa</code> chokes on Unicode without a UTF-8 pre-encode pass). For the inverse, paste any Base64 string in and switch to Decode mode.</p>
<h3>Decode Base64 to text or download as binary file</h3>
<p>The decoder accepts both alphabets and auto-detects which one it received. Plain text decodes to text; binary content (an image, PDF, ZIP) is restored to bytes and offered as a download with the correct MIME type when the input is a <code>data:</code> URI. Pair the decoder with the <a href="/hash-generator">hash generator</a> when you need to verify a Base64-encoded checksum (e.g. SRI integrity hashes are <code>sha384-{base64-encoded-sha384}</code>). To embed Base64 in URLs without the trailing <code>=</code> padding causing 404s in some routers, switch to URL-safe mode.</p>
<h2>Base64 best practices</h2>
<ul>
<li><strong>Don't confuse Base64 with encryption.</strong> Base64 is reversible without a key. If you need confidentiality, use AES-GCM or libsodium and Base64 the ciphertext if you need to embed it as text.</li>
<li><strong>Pick URL-safe Base64 by default for new APIs.</strong> It works in URLs, JSON, JWTs, cookies, and filenames without escaping. Standard Base64 needs additional URL encoding.</li>
<li><strong>Always decode in the same encoding as you encoded.</strong> Mixing standard with URL-safe is the #1 cause of "Invalid base64" errors. Most modern libraries auto-detect, but don't rely on it.</li>
<li><strong>For UTF-8 strings in JavaScript browsers</strong>, never use raw <code>btoa(string)</code> on Unicode — it throws on characters above 0xFF. Use <code>btoa(unescape(encodeURIComponent(s)))</code> or the modern <code>TextEncoder</code> approach.</li>
<li><strong>For files larger than ~5 MB in browsers</strong>, use <code>FileReader</code> with chunked processing. <code>readAsDataURL</code> on huge files freezes the UI thread.</li>
<li><strong>Validate decoded payloads before trusting them.</strong> Base64 will happily decode garbage into more garbage. After decoding a JWT, verify the signature; after decoding an image, check magic bytes.</li>
</ul>
</section>
</article>
<!-- How to use + mistakes -->
<section class="use-cases">
<h2>How to use the Base64 encoder</h2>
<p>Base64 lets you transport binary data through text-only channels — JSON payloads, JWT tokens, email attachments, data URIs in HTML/CSS. The tool runs entirely in your browser, so even sensitive payloads (API keys, certificates, customer files) never reach a server.</p>
<ul class="use-case-list">
<li><strong>1. Pick "Encode" or "Decode"</strong> mode at the top. The tool also auto-detects: paste a string and it'll guess.</li>
<li><strong>2. Paste or type your input</strong> — text, raw binary (via file upload), or an existing Base64 string.</li>
<li><strong>3. Output appears live.</strong> No "submit" needed. Errors (invalid Base64, malformed UTF-8) show inline.</li>
<li><strong>4. Toggle URL-safe Base64</strong> if your output goes into a URL or filename — replaces <code>+</code>/<code>/</code>/<code>=</code> with <code>-</code>/<code>_</code>/(none).</li>
<li><strong>5. Copy with one click</strong> or download as a text file for longer payloads.</li>
</ul>
<h3>Common Base64 mistakes to avoid</h3>
<ul class="mistakes-list">
<li><strong>Treating Base64 as encryption.</strong> It's encoding, not encryption — anyone with the string can decode it instantly. Use proper crypto for secrets.</li>
<li><strong>Forgetting the 33% size overhead.</strong> Every 3 bytes input = 4 bytes output. A 1MB image becomes ~1.33MB Base64 — bigger payload, slower transfer.</li>
<li><strong>Encoding twice.</strong> Re-encoding an already-Base64 string produces gibberish on decode. Verify your data layer before applying.</li>
<li><strong>Mixing standard and URL-safe variants.</strong> <code>+</code>/<code>/</code>/<code>=</code> vs <code>-</code>/<code>_</code>/(none). A URL-safe encoder can't decode standard Base64 without conversion.</li>
<li><strong>Missing padding.</strong> Standard Base64 requires <code>=</code> padding to multiple of 4. Some implementations strip it; some require it. When in doubt, add it back.</li>
<li><strong>Using Base64 for big files in <code>data:</code> URIs.</strong> Anything > 10KB is faster as a regular HTTP request. Inline encoding only for tiny icons and inline emails.</li>
</ul>
</section>
<!-- FAQ -->
<section class="faq-section">
<h2>Frequently Asked Questions</h2>
<div class="faq-item open">
<div class="faq-q" onclick="toggleFaq(this)">
What is Base64 encoding?
<svg class="chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg>
</div>
<div class="faq-a">
Base64 is a binary-to-text encoding scheme that converts binary data into a safe string of 64 printable ASCII characters (A-Z, a-z, 0-9, +, /). It's used to transmit binary data over text-based systems like email (MIME attachments), HTTP headers, JSON payloads, CSS <code>data:</code> URIs, and HTML <code>src</code> attributes for images. It inflates data size by about 33%.
</div>
</div>
<div class="faq-item">
<div class="faq-q" onclick="toggleFaq(this)">
Does Base64 encrypt my data?
<svg class="chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg>
</div>
<div class="faq-a">
No. Base64 is <strong>encoding</strong>, not encryption. It is trivially reversible by anyone without needing any key or password. Never use Base64 to "hide" sensitive information. Use proper encryption algorithms like AES-256 for security-sensitive data.
</div>
</div>
<div class="faq-item">
<div class="faq-q" onclick="toggleFaq(this)">
Why does my Base64 output end with = or ==?
<svg class="chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg>
</div>
<div class="faq-a">
Base64 encodes every 3 bytes of input into exactly 4 characters. If the input length isn't divisible by 3, padding characters (<code>=</code>) are appended to make the output length a multiple of 4. One <code>=</code> means 1 padding byte was added; <code>==</code> means 2 bytes. Padding is sometimes stripped in URL-safe variants.
</div>
</div>
<div class="faq-item">
<div class="faq-q" onclick="toggleFaq(this)">
What is the difference between standard and URL-safe Base64?
<svg class="chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg>
</div>
<div class="faq-a">
Standard Base64 uses <code>+</code> and <code>/</code>, which are reserved characters in URLs. URL-safe Base64 (RFC 4648) replaces <code>+</code> with <code>-</code> and <code>/</code> with <code>_</code>, making it safe to include in URLs and filenames without percent-encoding. JWT tokens use URL-safe Base64 without padding.
</div>
</div>
<div class="faq-item">
<div class="faq-q" onclick="toggleFaq(this)">
How do I encode a file to Base64 in JavaScript?
<svg class="chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg>
</div>
<div class="faq-a">
Use a <code>FileReader</code>: <code>const reader = new FileReader(); reader.onload = e => console.log(e.target.result); reader.readAsDataURL(file);</code> — this gives you a full data URI including the MIME type prefix. To get just the Base64 string, split on the comma: <code>e.target.result.split(',')[1]</code>.
</div>
</div>
<div class="faq-item">
<div class="faq-q" onclick="toggleFaq(this)">
Is my data safe when using this tool?
<svg class="chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg>
</div>
<div class="faq-a">
Yes. All encoding and decoding happens entirely in your browser using native JavaScript APIs (<code>btoa</code>, <code>atob</code>, and <code>FileReader</code>). No data, text, or files are ever uploaded to a server. The tool works fully offline once loaded.
</div>
</div>
</section>
<!-- Related Tools -->
<section class="related-section">
<h2>Related Tools</h2>
<div class="related-grid">
<a class="related-card" href="unix-timestamp-converter">
<div class="related-icon">⏱</div>
<div class="related-card-info">
<div class="related-card-name">UNIX Timestamp Converter</div>
<div class="related-card-desc">Convert epoch time to readable dates</div>
</div>
</a>
<a class="related-card" href="uuid-generator">
<div class="related-icon">uid</div>
<div class="related-card-info">
<div class="related-card-name">UUID Generator</div>
<div class="related-card-desc">Generate v4 UUIDs in bulk</div>
</div>
</a>
<a class="related-card" href="json-formatter">
<div class="related-icon">{ }</div>
<div class="related-card-info">
<div class="related-card-name">JSON Formatter</div>
<div class="related-card-desc">Pretty print and validate JSON</div>
</div>
</a>
</div>
</section>
<section class="all-tools-section" aria-label="Browse all FreeDevTool developer tools">
<h2>Browse all 50 free developer tools</h2>
<p class="atc-sub">All tools run in your browser, no signup required, nothing sent to a server.</p>
<div class="all-tools-grid">
<div class="atc-cat">
<div class="atc-cat-head">
<div class="atc-cat-icon">b64</div>
<div class="atc-cat-title"><h3>Encoding & Conversion</h3><span class="atc-cat-count">11 tools</span></div>
</div>
<ul class="atc-list">
<li><a href="/base64-encoder">Base64 Encoder / Decoder</a></li>
<li><a href="/base64-image">Image to Base64</a></li>
<li><a href="/byte-converter">Byte Converter (KB / MB / GB)</a></li>
<li><a href="/case-converter">Case Converter</a></li>
<li><a href="/hex-to-rgb">Hex to RGB / HSL</a></li>
<li><a href="/html-entity">HTML Entity Encoder</a></li>
<li><a href="/json-to-csv">JSON to CSV Converter</a></li>
<li><a href="/px-to-rem">PX to REM Converter</a></li>
<li><a href="/string-escape">String Escape / Unescape</a></li>
<li><a href="/url-encoder">URL Encoder / Decoder</a></li>
<li><a href="/yaml-to-json">YAML to JSON Converter</a></li>
</ul>
</div>
<div class="atc-cat">
<div class="atc-cat-head">
<div class="atc-cat-icon">{ }</div>
<div class="atc-cat-title"><h3>Formatting & Generators</h3><span class="atc-cat-count">13 tools</span></div>
</div>
<ul class="atc-list">
<li><a href="/color-name">Color Name from Hex</a></li>
<li><a href="/color-picker">Color Palette Picker</a></li>
<li><a href="/css-box-shadow">CSS Box Shadow</a></li>
<li><a href="/css-gradient">CSS Gradient Generator</a></li>
<li><a href="/json-formatter">JSON Formatter / Validator</a></li>
<li><a href="/lorem-ipsum">Lorem Ipsum Generator</a></li>
<li><a href="/markdown-preview">Markdown Preview</a></li>
<li><a href="/password-generator">Password Generator</a></li>
<li><a href="/qr-generator">QR Code Generator</a></li>
<li><a href="/sql-formatter">SQL Formatter</a></li>
<li><a href="/uuid-generator">UUID Generator</a></li>
<li><a href="/word-to-markdown">Word to Markdown</a></li>
<li><a href="/xml-formatter">XML Formatter</a></li>
</ul>
</div>
<div class="atc-cat">
<div class="atc-cat-head">
<div class="atc-cat-icon">JS</div>
<div class="atc-cat-title"><h3>Minifiers & DevOps</h3><span class="atc-cat-count">6 tools</span></div>
</div>
<ul class="atc-list">
<li><a href="/chmod-calculator">chmod Calculator</a></li>
<li><a href="/cron-parser">Cron Expression Parser</a></li>
<li><a href="/css-minifier">CSS Minifier</a></li>
<li><a href="/html-minifier">HTML Minifier</a></li>
<li><a href="/js-minifier">JavaScript Minifier</a></li>
<li><a href="/http-status">HTTP Status Codes</a></li>
</ul>
</div>
<div class="atc-cat">
<div class="atc-cat-head">
<div class="atc-cat-icon">#</div>
<div class="atc-cat-title"><h3>Security & Hashing</h3><span class="atc-cat-count">3 tools</span></div>
</div>
<ul class="atc-list">
<li><a href="/hash-generator">Hash Generator (MD5, SHA)</a></li>
<li><a href="/jwt-decoder">JWT Decoder</a></li>
<li><a href="/jwt-generator">JWT Generator</a></li>
</ul>
</div>
<div class="atc-cat">
<div class="atc-cat-head">
<div class="atc-cat-icon">.*</div>
<div class="atc-cat-title"><h3>Code & Text</h3><span class="atc-cat-count">8 tools</span></div>
</div>
<ul class="atc-list">
<li><a href="/ai-token-counter">AI Token Counter</a></li>
<li><a href="/char-counter">Character & Word Counter</a></li>
<li><a href="/git-cheatsheet">Git Commands Cheatsheet</a></li>
<li><a href="/number-base">Number Base Converter</a></li>
<li><a href="/regex-explainer">Regex Explainer</a></li>
<li><a href="/regex-tester">Regex Tester</a></li>
<li><a href="/text-diff">Text Diff Checker</a></li>
<li><a href="/wcag-contrast">WCAG Contrast Checker</a></li>
</ul>
</div>
<div class="atc-cat">
<div class="atc-cat-head">
<div class="atc-cat-icon">IP</div>
<div class="atc-cat-title"><h3>Network & APIs</h3><span class="atc-cat-count">3 tools</span></div>
</div>
<ul class="atc-list">
<li><a href="/dns-lookup">DNS Lookup</a></li>
<li><a href="/http-request-builder">HTTP Request Builder</a></li>
<li><a href="/ip-lookup">IP Address Lookup</a></li>
</ul>
</div>
<div class="atc-cat">
<div class="atc-cat-head">
<div class="atc-cat-icon">⏱</div>
<div class="atc-cat-title"><h3>Time & Dates</h3><span class="atc-cat-count">3 tools</span></div>
</div>
<ul class="atc-list">
<li><a href="/relative-time">Relative Time Calculator</a></li>
<li><a href="/timestamp-diff">Timestamp Diff</a></li>
<li><a href="/unix-timestamp-converter">Unix Timestamp Converter</a></li>
</ul>
</div>
<div class="atc-cat">
<div class="atc-cat-head">
<div class="atc-cat-icon">SEO</div>
<div class="atc-cat-title"><h3>SEO & Meta</h3><span class="atc-cat-count">3 tools</span></div>
</div>
<ul class="atc-list">
<li><a href="/meta-tag-generator">Meta Tag Generator</a></li>
<li><a href="/og-preview">Open Graph Preview</a></li>
<li><a href="/slug-generator">URL Slug Generator</a></li>
</ul>
</div>
</div>
</section>
</div>
<footer>
<div>© 2026 FreeDevTool — Base64 Encoder / Decoder</div>
<div class="footer-links">
<a href="/all-tools">All Tools</a>
<a href="/about">About</a>
<a href="/privacy">Privacy Policy</a>
<a href="/terms">Terms of Use</a>
</div>
</footer>
<script>
// Mode switching
function setMode(mode, btn) {
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
btn.classList.add('active');
['encode','decode','file'].forEach(m => {
document.getElementById('mode-' + m).style.display = m === mode ? '' : 'none';
});
}
// Encode
function doEncode() {
const input = document.getElementById('encode-input').value;
document.getElementById('encode-count').textContent = input.length + ' characters';
if (!input) {
document.getElementById('encode-output').textContent = '';
document.getElementById('encode-output').style.fontStyle = 'italic';
document.getElementById('encode-output').style.color = 'var(--text2)';
document.getElementById('encode-out-count').textContent = '';
return;
}
try {
const bytes = new TextEncoder().encode(input);
let binary = '';
bytes.forEach(b => binary += String.fromCharCode(b));
let b64 = btoa(binary);
if (document.getElementById('url-safe-enc').checked) {
b64 = b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
}
const out = document.getElementById('encode-output');
out.textContent = b64;
out.style.fontStyle = 'normal';
out.style.color = 'var(--text)';
document.getElementById('encode-out-count').textContent = b64.length + ' characters output';
} catch(e) {
document.getElementById('encode-output').textContent = 'Error: ' + e.message;
}
}
// Decode
function doDecode() {
const input = document.getElementById('decode-input').value.trim();
document.getElementById('decode-count').textContent = input.length + ' characters';
const status = document.getElementById('decode-status');
if (!input) {
document.getElementById('decode-output').textContent = '';
document.getElementById('decode-output').style.fontStyle = 'italic';
document.getElementById('decode-output').style.color = 'var(--text2)';
status.innerHTML = '';
return;
}
try {
// Normalize URL-safe
const normalized = input.replace(/-/g, '+').replace(/_/g, '/');
const padded = normalized + '=='.slice(0, (4 - normalized.length % 4) % 4);
const binary = atob(padded);
const bytes = new Uint8Array(binary.length);
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
const decoded = new TextDecoder().decode(bytes);
const out = document.getElementById('decode-output');
out.textContent = decoded;
out.style.fontStyle = 'normal';
out.style.color = 'var(--text)';
status.innerHTML = '<div class="status status-ok">✓ Valid Base64 — decoded successfully</div>';
} catch(e) {
document.getElementById('decode-output').textContent = '';
status.innerHTML = '<div class="status status-err">✗ Invalid Base64 string</div>';
}
}
// File encoding
let fileB64 = '', fileMime = '';
function onFileSelect(e) { processFile(e.target.files[0]); }
function onDragOver(e) { e.preventDefault(); document.getElementById('file-drop').classList.add('dragover'); }
function onDragLeave() { document.getElementById('file-drop').classList.remove('dragover'); }
function onDrop(e) {
e.preventDefault();
document.getElementById('file-drop').classList.remove('dragover');
if (e.dataTransfer.files[0]) processFile(e.dataTransfer.files[0]);
}
function processFile(file) {
if (!file) return;
if (file.size > 5 * 1024 * 1024) {
document.getElementById('file-info').style.display = '';
document.getElementById('file-status').className = 'status status-err';
document.getElementById('file-status').textContent = '✗ File too large (max 5 MB)';
return;
}
fileMime = file.type || 'application/octet-stream';
const reader = new FileReader();
reader.onload = e => {
const dataUri = e.target.result;
fileB64 = dataUri.split(',')[1];
document.getElementById('file-info').style.display = '';
document.getElementById('file-status').className = 'status status-ok';
document.getElementById('file-status').textContent = `✓ ${file.name} — ${(file.size/1024).toFixed(1)} KB — ${fileMime}`;
document.getElementById('file-output').textContent = fileB64;
};
reader.readAsDataURL(file);
}
function copyDataUri() {
navigator.clipboard.writeText(`data:${fileMime};base64,${fileB64}`);
showToast();
}
function copyOutput(id) {
const text = document.getElementById(id).textContent;
if (text) { navigator.clipboard.writeText(text); showToast(); }
}
function showToast() {
const t = document.getElementById('copy-toast');
t.classList.add('show');
setTimeout(() => t.classList.remove('show'), 1800);
}
function toggleFaq(el) { el.parentElement.classList.toggle('open'); }
</script>
<script>document.addEventListener('click',e=>{const dd=document.getElementById('tools-dropdown');if(dd&&!dd.contains(e.target))dd.classList.remove('open')});</script>
</body>
</html>