Python 3 strings contain Unicode code points, not "UTF-8 characters". You can use ord() to get the Unicode code point value, and .encode() to convert it to UTF-8 bytes. Then format each byte as 8-digit binary text, and .join() them together. Example:

# starting and ending code points for 1-, 2-, 3- and 4-byte UTF-8.
s1 = '\x00\x7f\x80\u07ff\u0800\uffff\U00010000\U0010FFFF'

# some printable characters in each range
s2 = 'Aü马🎂'

def utf8_bin(u):
    # format as 8-digit binary, join each byte with space
    return ' '.join([f'{i:08b}' for i in u.encode()])

for u in s1:
    col1 = f'U+{ord(u):04X}' # format Unicode codepoint, leading zeros if <4 digits.
    print(f'{col1:8} {utf8_bin(u)}')

print()

for u in s2:
    col1 = f'U+{ord(u):04X}'
    print(f'{col1:8} {u} {utf8_bin(u)}')

Output:

U+0000   00000000
U+007F   01111111
U+0080   11000010 10000000
U+07FF   11011111 10111111
U+0800   11100000 10100000 10000000
U+FFFF   11101111 10111111 10111111
U+10000  11110000 10010000 10000000 10000000
U+10FFFF 11110100 10001111 10111111 10111111

U+0041   A 01000001
U+00FC   ü 11000011 10111100
U+9A6C   马 11101001 10101001 10101100
U+1F382  🎂 11110000 10011111 10001110 10000010
Answer from Mark Tolonen on Stack Overflow
Discussions

utf 8 - How to convert utf8 into binary - Stack Overflow
Recently I am studying about binary code, and I want to know how do I convert text that has been encoded by UTF-8 and then into binary? More on stackoverflow.com
🌐 stackoverflow.com
writing unicode to binary file in python - Stack Overflow
I'm wondering how to write unicode (utf-8) to a binary file. Here's the background: I've got a 40 byte header (10 ints), and a table with a variable number of triple-int structs. Writing these wa... More on stackoverflow.com
🌐 stackoverflow.com
March 23, 2021
python - Convert UTF-8 as string of binary 0 and 1s to code point - Stack Overflow
If you have a string of bits, how do you convert that into the correct code point if that string of 0s and 1s is in utf-8 encoding. For example: accented_a_part1 = "100001" accented_a_par... More on stackoverflow.com
🌐 stackoverflow.com
June 4, 2017
utf 8 - python - convert binary data to utf-8 - Stack Overflow
import base64 encoded = base64.b64encode(image_binary_data) ... Encoding means converting strings to storable bytes. And Decoding means converting bytes to readable strings. The data in your code is already encoded. ... Image cannot be converted into something like charters in utf8. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... 1 How to convert a string representation of 'bytes' to its corresponding 'utf-8' in Python... More on stackoverflow.com
🌐 stackoverflow.com
🌐
AskPython
askpython.com › python › examples › binary-to-utf8-conversion
How to Convert Binary Data to UTF-8 in Python - AskPython
April 10, 2025 - For binary data with unknown encoding, you can first decode it as Latin-1. This will map each byte to a corresponding Unicode code point. ... data = b"\x12\xab" # Binary data with unknown encoding text = data.decode("latin-1").encode("utf-8") ...
🌐
Real Python
realpython.com › python-encodings-guide
Unicode & Character Encodings in Python: A Painless Guide – Real Python
May 20, 2019 - Python 3 source code is assumed to be UTF-8 by default. This means that you don’t need # -*- coding: UTF-8 -*- at the top of .py files in Python 3. All text (str) is Unicode by default. Encoded Unicode text is represented as binary data (bytes).
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-convert-string-to-binary
Convert String to Binary - Python - GeeksforGeeks
July 12, 2025 - format() convert each byte to 8-bit ... 010001110110011001100111 · Explanation: converts each character in txt to its 8-bit binary form using bytearray() and format() then joins them into one binary string....
Find elsewhere
🌐
Learning Python
learning-python.com › strings30.html
Python 3.X Strings Tutorial by Mark Lutz
C:\misc>c:\python30\python.exe >>> F = open('data.bin', 'wb') # open binary output file >>> import struct >>> data = struct.pack('>i4sh', 7, b'spam', 8) # create packed binary data >>> data # bytes in 3.0, not str b'\x00\x00\x00\x07spam\x00\x08' >>> F.write(data) # write to the file 10 >>> F.close() >>> F = open('data.bin', 'rb') # open binary input file >>> data = F.read() # read bytes >>> data b'\x00\x00\x00\x07spam\x00\x08' >>> values = struct.unpack('>i4sh', data) # extract packed binary data >>> values # back to Python objects (7, b'spam', 8) Update: Python 3.2 changed the struct.pack() call to require a bytes (or bytearray) object for its "s" conversion code; using a str is an error. In 3.0 and 3.1 a str is allowed and automatically encoded to bytes as UTF-8 text—arguably too large an assumption, but 3.2 changes working and documented behavior.
🌐
Delft Stack
delftstack.com › home › howto › python › string to binary python
How to Convert a String to Binary in Python | Delft Stack
February 2, 2024 - string = "Python" binary_converted = " ".join(map(bin, bytearray(string, "utf-8"))) print("The Binary Represntation is:", binary_converted)
🌐
UW PCE
uwpce-pythoncert.github.io › ProgrammingInPython › modules › Files.html
File Reading and Writing — Programming in Python 7.0 documentation
But this too is complicated – there are multiple ways that binary data can be mapped to Unicode text, known as “encodings”. In Python, text files are by default opened with the “utf-8” encoding.
🌐
Easyprotools
easyprotools.com › home › utf-8 tools › utf-8 to binary converter
UTF-8 to Binary Converter — Free Online Text Encoding Tool
For older browsers or edge cases, a custom fallback encoder implements the full UTF-8 encoding algorithm from scratch, handling all Unicode code points correctly including surrogate pairs for characters above U+FFFF. The tool has been tested against the official Unicode Consortium test data and produces identical results to reference implementations in Python, Java, and C++. Every character from U+0000 (null) to U+10FFFF (the maximum valid Unicode code point) is handled correctly.
🌐
GeeksforGeeks
geeksforgeeks.org › python-convert-string-to-binary
Python | Convert String to Binary - GeeksforGeeks
May 3, 2023 - # Python3 code to demonstrate working ... + format() # Converting String to binary res = ''.join(format(i, '08b') for i in bytearray(test_str, encoding ='utf-8')) # printing result print(&quot;The string after binary conversion ...
🌐
SSOJet
ssojet.com › character-encoding-decoding › utf-8-in-python
UTF-8 in Python | Encoding Standards for Programming Languages
For instance, my_string = "你好, world!" becomes b'\xe4\xbd\xa0\xe5\xa5\xbd, world!' when encoded to UTF-8. Decoding this bytes object with utf-8 will perfectly restore the original string. A common pitfall is attempting to write a Python string directly to a file opened in binary mode ('wb') ...
🌐
Online Tools
onlinetools.com › unicode › convert-unicode-to-binary
Convert Unicode to Binary – Online Unicode Tools
If the output encoding is UTF16 ... bits). If the output encoding is UTF8, then the binary will be one to four bytes in length (variable length 8 to 32 bits)....
🌐
The Python Coding Stack
thepythoncodingstack.com › the python coding stack › `bytes`: the lesser-known python built-in sequence • and understanding utf-8 encoding
`bytes`: The Lesser-Known Python Built-In Sequence • And Understanding UTF-8 Encoding
July 15, 2025 - You can get a free trial at The Python Coding Place and you also get access to a members-only forum. ... So, back to 1's and 0's. The accented letter é is represented by two bytes. The value of the first of these bytes is c3 in hexadecimal, which is 195 in decimal. Let's convert this to binary: ... Here's how to understand a byte in a UTF-8 encoded number.
🌐
Stack Overflow
stackoverflow.com › q › 36021218
Newest Questions - Stack Overflow
Stack Overflow | The World’s Largest Online Community for Developers