just two lines could solve this problem:

import base64
base64_code = "VER30QHI30JFOIAIO3020085723F"  # this is just an example
 
img_data = base64_code.encode()
content = base64.b64decode(img_data)

with open('/path/to/your/image.jpg', 'wb') as fw:
    fw.write(content)
print(content)

then you could check the image bytes.

Answer from dongrixinyu on Stack Overflow
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ base64.html
base64 โ€” Base16, Base32, Base64, Base85 Data Encodings
Decode the Base64 encoded bytes-like object or ASCII string s and return the decoded bytes. Optional altchars must be a bytes-like object or ASCII string of length 2 which specifies the alternative alphabet used instead of the + and / characters. A binascii.Error exception is raised if s is incorrectly padded. If validate is False (the default), characters that are neither in the normal base-64 alphabet nor the alternative alphabet are discarded prior to the padding check.
Discussions

python - Decode Base64 string to byte array - Stack Overflow
I would create a python script that decode a Base64 string to an array of byte (or array of Hex values). The embedded side of my project is a micro controller that creates a base64 string starting... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Convert byte[] to base64 and ASCII in Python - Stack Overflow
How do I to convert and array of byte to base64 string and/or ASCII. I can do this easily in C#, but can't seem to do this in Python More on stackoverflow.com
๐ŸŒ stackoverflow.com
Why does base64.b64encode() in python3 return a bytes object, not a string object? Isn't converting to string the point?
A bytes object is not "a byte array". It is a sequence, the elements of which are byte values. The encoding produces bytes because the original purpose of encoding things that way was to be able to transmit binary data over ASCII protocols that might reserve the high bit of each byte for other uses, randomly insert line breaks, etc. (The expected input is also a bytes object, not a string.) A lot of this is the result of a legacy of pretending that we can treat strings as being made up of bytes. It turns out that this doesn't actually work; a usable conception of a string in the modern world needs to a) be more abstract and b) allow for more than 256 possibilities for each element. But fundamentally everything we store in memory or on disk (or transmit over the Internet) boils down to a sequence of bytes at some level. Encodings (such as ASCII, UTF-8, etc.) determine how to interpret bytes as text. I was confusing bytes with binary. Programmers use the word "binary" in a few related but subtly different ways - be careful. More on reddit.com
๐ŸŒ r/learnpython
5
2
July 29, 2017
PDF Response from base64
I am trying to build a flask Response object from a base64 pdf but I am really just trying random stuff at this point. This is what I have pdf_data =โ€ฆ More on reddit.com
๐ŸŒ r/flask
4
7
November 28, 2021
๐ŸŒ
Rip Tutorial
riptutorial.com โ€บ encoding and decoding base64
Python Language Tutorial => Encoding and Decoding Base64
# Encoding the string into bytes b = s.encode("UTF-8") # Base64 Encode the bytes e = base64.b64encode(b) # Decoding the Base64 bytes to string s1 = e.decode("UTF-8") # Printing Base64 encoded string print("Base64 Encoded:", s1) # Encoding the ...
๐ŸŒ
Medium
medium.com โ€บ @ume.cooray โ€บ understanding-base64-encoding-in-python-5b31f23dd007
Understanding Base64 Encoding and Decoding in Python | by Umayangana Cooray | Medium
March 18, 2025 - Letโ€™s walk through the following ... json_bytes = json_token.encode('utf-8') # Step 2: Encode the bytes using Base64 base64_bytes = base64.b64encode(json_bytes) # Step 3: Convert the encoded bytes back to a string (optional) ...
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ encoding-and-decoding-base64-strings-in-python
Encoding and Decoding Base64 Strings in Python
September 4, 2023 - In the code above, we first imported the base64 module. The message variable stores our input string to be encoded. We convert that to a bytes-like object using the string's encode method and store it in message_bytes. We then Base64 encode message_bytes and store the result in base64_bytes ...
๐ŸŒ
Python Module of the Week
pymotw.com โ€บ 2 โ€บ base64
base64 โ€“ Encode binary data into ASCII characters - Python Module of the Week
A basic example of encoding some text looks like this: import base64 # Load this source file and strip the header. initial_data = open(__file__, 'rt').read().split('#end_pymotw_header')[1] encoded_data = base64.b64encode(initial_data) num_initial = len(initial_data) padding = { 0:0, 1:2, 2:1 ...
๐ŸŒ
Python Engineer
python-engineer.com โ€บ posts โ€บ base64-module
The base64 Module in Python - Python Engineer
June 21, 2022 - Let's see how to use this function. ... language ยท In the above example, first we convert the base64 strings into unencoded data bytes and then decode those bytes to get the original string....
Find elsewhere
๐ŸŒ
iO Flood
ioflood.com โ€บ blog โ€บ python-base64-encode
Python Base64 Encode | b64encode() Function Guide
February 1, 2024 - In Python, the base64 module provides the b64encode() function, which is a simple way to perform base64 encoding. This function accepts binary data as input and returns a base64 encoded byte string.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ encoding-and-decoding-base64-strings-in-python
Encoding and Decoding Base64 Strings in Python - GeeksforGeeks
August 7, 2024 - Decoding Base64 string is exactly opposite to that of encoding. First we convert the Base64 strings into unencoded data bytes followed by conversion into bytes-like object into a string. The below example depicts the decoding of the above example encode string output.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-use-base64b64decode-in-python
How to use base64.b64decode() in Python
The base64.b4() function in Python decodes strings or byte-like objects encoded in base64 and returns the decoded bytes.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-use-base64b64encode-in-python
How to use base64.b64encode() in Python
The base64.b64() function in Python encodes byte-like objects and returns the encoded bytes.
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ 5 best ways to convert python bytes to base64
5 Best Ways to Convert Python Bytes to Base64 - Be on the Right Side of Change
February 23, 2024 - ... # This is a simplified example and not recommended for production use. import base64 def custom_b64encode(data): return base64.b64encode(data).decode() data = b'Python bytes to base64' ...
๐ŸŒ
Bacancy Technology
bacancytechnology.com โ€บ qanda โ€บ python โ€บ decode-base64-data-in-python
How to Decode Base64 Data in Python Easily
June 24, 2025 - Example: Decoding Base64 Data Hereโ€™s how to decode a Base64 string using Python: import base64 # Your Base64-encoded string b64_data = 'ABCSSDURN' # Convert to bytes, if it's a string decoded_bytes = base64.b64decode(b64_data) # If the original ...
๐ŸŒ
MojoAuth
mojoauth.com โ€บ binary-encoding-decoding โ€บ base64-with-python
Base64 with Python | Binary Encoding Techniques Across Programming Languages
This process guarantees your text data is correctly represented for Base64 transformation. To convert Base64 encoded data back into its original form, Python's base64 module provides the b64decode() function.
๐ŸŒ
Base64
base64.dev โ€บ home โ€บ articles โ€บ base64 in python
Base64 Encoding & Decoding in Python โ€” base64.dev
May 28, 2026 - Try the Python encoder/decoder tool. import base64 # Encode: pass bytes, get bytes back encoded = base64.b64encode(b"Hello, world!") print(encoded) # b'SGVsbG8sIHdvcmxkIQ==' print(encoded.decode()) # 'SGVsbG8sIHdvcmxkIQ==' (as string) # Decode: ...
๐ŸŒ
DevTut
devtut.github.io โ€บ python โ€บ the-base64-module.html
Python - The base64 Module
January 6, 2018 - The base64 encode and decode functions both require a bytes-like object (opens new window). To get our string into bytes, we must encode it using Python's built in encode function. Most commonly, the UTF-8 encoding is used, however a full list of these standard encodings (including languages with different characters) can be found here (opens new window) in the official Python Documentation. Below is an example ...
๐ŸŒ
AskPython
askpython.com โ€บ python โ€บ examples โ€บ decoding-base64-data
Decoding Base64 Data in Python - AskPython
April 29, 2026 - Here is the simplest way to decode a base64 string in Python. I start with a variable holding the encoded text as a string, encode it to bytes using ASCII, then pass those bytes to b64decode.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ why does base64.b64encode() in python3 return a bytes object, not a string object? isn't converting to string the point?
r/learnpython on Reddit: Why does base64.b64encode() in python3 return a bytes object, not a string object? Isn't converting to string the point?
July 29, 2017 -

The question is pretty much in the title. I was working on porting some code to Python3 that talks to an old API at work - there is a bunch of base64 encoding and hmac creation, which when going from Python 2 to 3 means being explicit about what is a string and what is a byte array. But the b64encode returning a byte array tripped me up, because it doesn't make sense (unless I'm missing something).

Shouldn't b64encode take bytes and return string, and b64decode take string and return bytes?