Decode the bytes object to produce a string:

>>> b"abcde".decode("utf-8")
'abcde'

The above example assumes that the bytes object is in UTF-8, because it is a common encoding. However, you should use the encoding your data is actually in!

Answer from Aaron Maenpaa on Stack Overflow
🌐
JanBask Training
janbasktraining.com › community › python-python › convert-bytes-to-a-string-in-python-3
Convert bytes to a string in Python 3 | JanBask Training Community
May 25, 2025 - Use .decode('encoding') to convert bytes to string. UTF-8 is the most common and default encoding. If you're not sure what encoding to use, try 'utf-8' first. If the bytes contain characters not compatible with the chosen encoding, Python will ...
Discussions

How To Convert Bytes To A String - Different Methods Explained
This article confuses more than it explains, I don't consider it very helpful to someone trying to understand the distinction between a character string and a byte string. You may want to look elsewhere for a good explanation. More on reddit.com
🌐 r/Python
2
0
April 29, 2023
How to convert string to bytes in Python 3 - Stack Overflow
TypeError: 'str' does not support the buffer interface suggests two possible methods to convert a string to bytes: b = bytes(mystring, 'utf-8') b = mystring.encode('utf-8') What are the More on stackoverflow.com
🌐 stackoverflow.com
How do i make a bytes object convert to a formatted string.
That's its representation. Print the string to see it formatted: >>> b = b"\tHello\nWorld" >>> s = b.decode() >>> s '\tHello\nWorld' >>> print(s) Hello World More on reddit.com
🌐 r/learnpython
5
1
February 14, 2025
How do I convert a string to bytes?
Or use the bytes() builtin function . An example: x = "abc☺xyz" print(x) y = bytes(x, encoding="utf-8") print(y) More on reddit.com
🌐 r/learnpython
15
6
August 8, 2023
🌐
FavTutor
favtutor.com › blogs › bytes-to-string-python
4 Methods to Convert Bytes to String in Python (with code)
February 8, 2023 - This function decodes different types of encoding of strings to a normal string. The decode() function in python can be used to take our data encoded in bytes format and decode it to convert the data to string format.
🌐
Real Python
realpython.com › convert-python-bytes-to-strings
How to Convert Bytes to Strings in Python – Real Python
November 26, 2025 - Turn Python bytes to strings, pick the right encoding, and validate results with clear error handling strategies.
🌐
Mimo
mimo.org › glossary › python › bytes
Mimo: The coding platform you need to learn Web Development, Python, and more.
This process is essential when sending data over a network or storing data in binary files. The opposite of this operation—bytes to string—requires decoding. If you skip specifying the encoding, Python 3 uses UTF-8 as the default encoding, which works for most unicode characters.
🌐
PythonHow
pythonhow.com › how › convert-bytes-to-a-string
Here is how to convert bytes to a string in Python
In Python, you can convert a byte string (a sequence of bytes) to a string by using the .decode() method.
Find elsewhere
🌐
KDnuggets
kdnuggets.com › convert-bytes-to-string-in-python-a-tutorial-for-beginners
Convert Bytes to String in Python: A Tutorial for Beginners - KDnuggets
July 15, 2024 - Use the str() constructor to convert a valid bytes object to a string. Use the decode() function from the codecs module that is built into the Python standard library to convert a valid bytes object to a string.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-convert-bytes-to-string-in-python
How to Convert Bytes to String in Python ? - GeeksforGeeks
This works opposite to the encode. ... It assumes the byte object is UTF-8 encoded unless specified otherwise. The str() function of Python returns the string version of the object.
Published   July 23, 2025
🌐
Reddit
reddit.com › r/python › how to convert bytes to a string - different methods explained
r/Python on Reddit: How To Convert Bytes To A String - Different Methods Explained
April 29, 2023 -

In Python, a byte string is a sequence of bytes, which are the fundamental building blocks of digital data such as images, audio and videos. Byte strings differ from regular strings in that they are made up of bytes rather than characters.

Sometimes we work on projects where we need to handle bytes, and we needed to convert them into Python strings in order to perform specific operations.

We'll learn to convert the byte string into a regular string using three methods which are as follows:

  • using the decode method

  • using the codecs.decode method

  • using the str method

Here's a detailed guide to converting the byte string into a regular string in Python👇👇

Convert Bytes To A String - Different Methods Explained

Top answer
1 of 5
894

If you look at the docs for bytes, it points you to bytearray:

bytearray([source[, encoding[, errors]]])

Return a new array of bytes. The bytearray type is a mutable sequence of integers in the range 0 <= x < 256. It has most of the usual methods of mutable sequences, described in Mutable Sequence Types, as well as most methods that the bytes type has, see Bytes and Byte Array Methods.

The optional source parameter can be used to initialize the array in a few different ways:

If it is a string, you must also give the encoding (and optionally, errors) parameters; bytearray() then converts the string to bytes using str.encode().

If it is an integer, the array will have that size and will be initialized with null bytes.

If it is an object conforming to the buffer interface, a read-only buffer of the object will be used to initialize the bytes array.

If it is an iterable, it must be an iterable of integers in the range 0 <= x < 256, which are used as the initial contents of the array.

Without an argument, an array of size 0 is created.

So bytes can do much more than just encode a string. It's Pythonic that it would allow you to call the constructor with any type of source parameter that makes sense.

For encoding a string, I think that some_string.encode(encoding) is more Pythonic than using the constructor, because it is the most self documenting -- "take this string and encode it with this encoding" is clearer than bytes(some_string, encoding) -- there is no explicit verb when you use the constructor.

I checked the Python source. If you pass a unicode string to bytes using CPython, it calls PyUnicode_AsEncodedString, which is the implementation of encode; so you're just skipping a level of indirection if you call encode yourself.

Also, see Serdalis' comment -- unicode_string.encode(encoding) is also more Pythonic because its inverse is byte_string.decode(encoding) and symmetry is nice.

2 of 5
735

It's easier than it is thought:

my_str = "hello world"
my_str_as_bytes = my_str.encode()
print(type(my_str_as_bytes)) # ensure it is byte representation
my_decoded_str = my_str_as_bytes.decode()
print(type(my_decoded_str)) # ensure it is string representation

you can verify by printing the types. Refer to output below.

<class 'bytes'>
<class 'str'>
🌐
Devace Technologies
devacetech.com › home › insights › string to bytes conversion in python-2025 manual
How to convert a string to bytes in Python
July 28, 2025 - In 2025, Python powers everything from IoT devices and secure APIs to AI systems; that’s why it’s essential to learn how to handle data efficiently. Out of many tasks for data management, one of the most important but often misunderstood is ‘how to convert a string to bytes in Python’. With Python, your applications directly depend on how to convert and manipulate byte data, no matter whether you are saving binary data, encrypting user credentials, or preparing payloads for a REST API.
🌐
Analytics Vidhya
analyticsvidhya.com › home › 3 ways to convert bytes to string in python
3 Ways to Convert Bytes to String in Python
March 26, 2025 - Discover how to convert bytes to strings in Python using three simple methods: decode(), str() constructor, & codecs module. Explore Now!
🌐
Python documentation
docs.python.org › 3 › library › stdtypes.html
Built-in Types — Python 3.14.4 documentation
Passing a bytes object to str() without the encoding or errors arguments falls under the first case of returning the informal string representation (see also the -b command-line option to Python).
🌐
Reddit
reddit.com › r/learnpython › how do i make a bytes object convert to a formatted string.
r/learnpython on Reddit: How do i make a bytes object convert to a formatted string.
February 14, 2025 -

I have a variable that is a bytes object that is a representation of formatted text.

 Byte_to_string = b”\tHello\nWorld”

I want to convert the object to a formatted string.

“      Hello
 World”

However what i am getting is ”\tHello\nWorld”.

What am i missing? How can i fix this?

🌐
freeCodeCamp
freecodecamp.org › news › python-bytes-to-string-how-to-convert-a-bytestring
Python Bytes to String – How to Convert a Bytestring
April 10, 2023 - Note that the decode() method can ... the decoder should expect more input. You can use the str() constructor in Python to convert a byte string (bytes object) to a string object....
🌐
Python documentation
docs.python.org › 3 › library › functions.html
Built-in Functions — Python 3.14.4 documentation
February 27, 2026 - It has most of the usual methods of mutable sequences, described in Mutable Sequence Types, as well as most methods that the bytes type has, see Bytes and Bytearray Operations. The optional source parameter can be used to initialize the array in a few different ways: If it is a string, you must also give the encoding (and optionally, errors) parameters; bytearray() then converts the string to bytes using str.encode().
🌐
Python Shiksha
python.shiksha › home › tips › 5 methods to convert bytes to string in python
5 methods to Convert Bytes to String in Python - Python Shiksha
August 1, 2022 - Eh! Python is so versatile that we can convert almost any data type to strings using the str() function. You may ask, then this would be applicable in this case as well. Yes, we can covert bytes to string using Python str() function, Let’s ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-convert-string-to-bytes
Convert String to bytes-Python - GeeksforGeeks
For example, given the string "Hello", these methods can convert it into a byte representation like b'Hello'. Let’s explore different methods to accomplish this efficiently. encode() method is a very straightforward way to convert a string ...
Published   July 11, 2025
🌐
Stack Abuse
stackabuse.com › convert-bytes-to-string-in-python
Convert Bytes to String in Python
November 27, 2020 - In this tutorial, we'll go over examples of how to convert bytes to a string in Python 2 and 3. We'll use the decode() function, str() function as well as the codecs module.