Neither is better than the other, they do exactly the same thing. However, using .encode() and .decode() is the more common way to do it. It is also compatible with Python 2.

Answer from Lennart Regebro on Stack Overflow
Top answer
1 of 3
74

Neither is better than the other, they do exactly the same thing. However, using .encode() and .decode() is the more common way to do it. It is also compatible with Python 2.

2 of 3
19

To add to Lennart Regebro's answer There is even the third way that can be used:

encoded3 = str.encode(original, 'utf-8')
print(encoded3)

Anyway, it is actually exactly the same as the first approach. It may also look that the second way is a syntactic sugar for the third approach.


A programming language is a means to express abstract ideas formally, to be executed by the machine. A programming language is considered good if it contains constructs that one needs. Python is a hybrid language -- i.e. more natural and more versatile than pure OO or pure procedural languages. Sometimes functions are more appropriate than the object methods, sometimes the reverse is true. It depends on mental picture of the solved problem.

Anyway, the feature mentioned in the question is probably a by-product of the language implementation/design. In my opinion, this is a nice example that show the alternative thinking about technically the same thing.

In other words, calling an object method means thinking in terms "let the object gives me the wanted result". Calling a function as the alternative means "let the outer code processes the passed argument and extracts the wanted value".

The first approach emphasizes the ability of the object to do the task on its own, the second approach emphasizes the ability of an separate algoritm to extract the data. Sometimes, the separate code may be that much special that it is not wise to add it as a general method to the class of the object.

🌐
Real Python
realpython.com › convert-python-bytes-to-strings
How to Convert Bytes to Strings in Python – Real Python
July 18, 2026 - In the example above, .decode() uses UTF-8 encoding automatically since no encoding was specified. When the code runs, it converts the raw bytes fetched from the website into a readable HTML string, which can then be displayed or parsed further. The b prefix seen in the earlier byte representation disappears, and the result becomes a standard string: ... $ python decode_bytes.py Bytes: b'<!doctype html><html lang="en"><head><title>Example Domain</title>… String: <!doctype html><html lang="en"><head><title>Example Domain</title>…
Discussions

Convert bytes to a string in Python 3 - Stack Overflow
I ran some microbenchmarks on random ... bytes.decode is an extremely hot routine, so has likely had a lot of optimization put into it. If you need to do my_bytes = bytes(my_integers) (why do you have integers :/) it cuts those factors down a bit, but if you're reading bytes, keep them as bytes... 2024-09-03T16:58:48.947Z+00:00 ... Save this answer. ... Show activity on this post. In Python 3, the default ... More on stackoverflow.com
🌐 stackoverflow.com
Why is encoding bytes to UTF-8 called decoding?
You are indeed confused: bytes.decode - encodes the bytes as UTF-8 No, it decodes a byte sequence to a string, interpreting it as an UTF-8 encoded string. Strings are a sequence of code points (or characters) in Unicode. Unicode and UTF-8 are not the same thing! UTF-8 is the most popular, but still only one of many encoding schemes for Unicode. Take the string ABCÄĀ. This is represented by the unicode code point sequence U+0041 U+0042 U+0043 U+00c4 U+0100. As you see, unicode code points are more than 8 bits, so we need a way to store them in 8-bit byte sequences. One way to do that is to use UTF-8, which turns it into the byte sequence 0x41 0x42 0x43 0xc3 0x84 0xc4 0x80. As another example, UTF-16 would encode this as 0xff 0xfe 0x00 0x41 0x00 0x42 0x00 0x43 0x00 0xc4 0x01 0x00. Notice that except for the 0xff 0xfe BOM (Byte Order Mark) at the beginning, it's simply storing the 16 bit value of the code point in sequence (code points can have more than 16 bits, so it only works this way below 32768, similar to how UTF-8 doesn't change the representation below 128). The BOM is needed to know which of the two bytes represents the most significant bits, as in, is 0x12 0x34 representing 0x1234 or 0x3412. (Some machines store 16 bit values in the first way ("big endian"), others, like x86, in the other ("little endian")) There are also other encoding schemes, for example, if every unicode code point is below 256, you can use latin-1, which will just use the lower 8 bits of the unicode code point. To summarize: bytes.decode decodes a byte sequence into a string, which is an abstract representation of code points. str.encode turns this abstract representation into a byte sequence. More on reddit.com
🌐 r/learnpython
7
21
March 30, 2022
string - Python 3.4 decode bytes - Stack Overflow
s is a str, so you can't decode it on Python 3, nor is encodeing the proper final step to convert to str. And error handler of "ignore" is basically saying "throw my data on the floor, I don't care". I can see why someone down-voted. You wrote incorrect Python 2 code, that can't even run on ... More on stackoverflow.com
🌐 stackoverflow.com
November 3, 2015
python 3.x - Python3 decode bytes - Stack Overflow
Trying to decode bytes 2k2P3PKIfViQ1L6TTc7kYks6bpeat6pPH9qRrNcj1S2195TYz\x88}\x88\x88JKgqzeXz96zKrTX05D9bkJf1yCf Is there a way to convert \x88 to letter or hide it. trying this s = b' More on stackoverflow.com
🌐 stackoverflow.com
🌐
Python documentation
docs.python.org › 3 › howto › unicode.html
Unicode HOWTO — Python 3.14.7 documentation
Unicode data is usually converted to a particular encoding before it gets written to disk or sent over a socket. It’s possible to do all the work yourself: open a file, read an 8-bit bytes object from it, and convert the bytes with bytes.decode(encoding).
🌐
Educative
educative.io › answers › what-is-bytesdecode-in-python
What is bytes.decode() in Python?
bytes.decode() is used to decode bytes to a string object. Decoding to a string object depends on the specified arguments. It also allows us to mention an error handling scheme to use for seconding errors.
🌐
Mimo
mimo.org › glossary › python › string-decode
Python string decode(): Syntax, Usage, and Examples
The decode() method in Python is used to convert byte data into a Unicode string. In Python 3, strings are Unicode by default, so decode() applies specifically to bytes objects.
🌐
Python for Network Engineers
pyneng.readthedocs.io › en › latest › book › 16_unicode › python_3_convert.html
Conversion between bytes and strings - Python for network engineers
And decode method is available in bytes class (like other methods): In [8]: hi_bytes Out[8]: b'\xd0\xbf\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82' In [9]: bytes.decode(hi_bytes, encoding='utf-8') Out[9]: 'привет'
🌐
Stack Abuse
stackabuse.com › convert-bytes-to-string-in-python
Convert Bytes to String in Python
November 27, 2020 - Bytestrings in Python 3 are officially called bytes, an immutable sequence of integers in the range 0 <= x < 256. Another bytes-like object added in 2.6 is the bytearray - similar to bytes, but mutable. Let's take a look at how we can convert bytes to a String, using the built-in decode() method for the bytes class:
Find elsewhere
🌐
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....
🌐
Google Sites
sites.google.com › site › pythonpasapas › methodes › bytes › bytes-decode
Mon Python pas à pas - bytes ( ).decode ( )
Par défaut code est "utf-8", (encoding = "utf-8") mais s'il est précisé il doit être un système d'encodage des caractères valide et gérable par Python.
🌐
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.
🌐
Net Informations
net-informations.com › python › iq › byte.htm
How to convert bytes to string in Python?
convert bytes to string in Python convert string to bytes in Python , We can convert bytes to String using bytes class decode() instance method, So you need to decode the bytes object to produce a string.
🌐
Python Central
pythoncentral.io › encoding-and-decoding-strings-in-python-3-x
Encoding and Decoding Strings (in Python 3.x) | Python Central
December 29, 2021 - For example, if we try to use UTF-8 to decode a UTF-16-encoded version of nonlat above: [python] # We can use the method directly on the bytes >>> b'\xff\xfeW['.decode('utf-8') Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte [/python]
🌐
Python
docs.python.org › 3 › library › codecs.html
codecs — Codec registry and base classes — Python 3.14.7 documentation
On encoding, use the hexadecimal form of Unicode code point with formats \xhh \uxxxx \Uxxxxxxxx. On decoding, use the hexadecimal form of byte value with format \xhh. Changed in version 3.5: Works with decoding and translating.
🌐
DataCamp
datacamp.com › tutorial › bytes-to-string-python
How to Convert Bytes to String in Python | DataCamp
June 12, 2024 - The .decode() method returns a string representing the bytes object. In this example, UTF-8 decoding is used. UTF-8 is the default encoding, so it's not required in the example above, but we can also use other encodings. Python has a built-in bytes data structure, which is an immutable sequence ...
🌐
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 ...
🌐
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 - How do you convert bytes to string? A. You can convert bytes to a string using .decode('utf-8') in Python, which decodes the byte object into a human-readable string using UTF-8 encoding.
🌐
Reddit
reddit.com › r/learnpython › why is encoding bytes to utf-8 called decoding?
r/learnpython on Reddit: Why is encoding bytes to UTF-8 called decoding?
March 30, 2022 -

This always confuses me every single time. I remember it by doing the opposite of what I intuitively think it should be. Perhaps I'm the only one?

bytes.decode - encodes the bytes as UTF-8

str.encode - decodes "removes" the UTF-8 encoding

There is also the abbreviation BADTIE: Bytes Are Decoded, Text Is Encoded. To help to remember it.

Top answer
1 of 4
25
You are indeed confused: bytes.decode - encodes the bytes as UTF-8 No, it decodes a byte sequence to a string, interpreting it as an UTF-8 encoded string. Strings are a sequence of code points (or characters) in Unicode. Unicode and UTF-8 are not the same thing! UTF-8 is the most popular, but still only one of many encoding schemes for Unicode. Take the string ABCÄĀ. This is represented by the unicode code point sequence U+0041 U+0042 U+0043 U+00c4 U+0100. As you see, unicode code points are more than 8 bits, so we need a way to store them in 8-bit byte sequences. One way to do that is to use UTF-8, which turns it into the byte sequence 0x41 0x42 0x43 0xc3 0x84 0xc4 0x80. As another example, UTF-16 would encode this as 0xff 0xfe 0x00 0x41 0x00 0x42 0x00 0x43 0x00 0xc4 0x01 0x00. Notice that except for the 0xff 0xfe BOM (Byte Order Mark) at the beginning, it's simply storing the 16 bit value of the code point in sequence (code points can have more than 16 bits, so it only works this way below 32768, similar to how UTF-8 doesn't change the representation below 128). The BOM is needed to know which of the two bytes represents the most significant bits, as in, is 0x12 0x34 representing 0x1234 or 0x3412. (Some machines store 16 bit values in the first way ("big endian"), others, like x86, in the other ("little endian")) There are also other encoding schemes, for example, if every unicode code point is below 256, you can use latin-1, which will just use the lower 8 bits of the unicode code point. To summarize: bytes.decode decodes a byte sequence into a string, which is an abstract representation of code points. str.encode turns this abstract representation into a byte sequence.
2 of 4
11
Because in Python 3 the strings are in unicode by default, and bytes are an optional encoding, if you want to deal with things on that level.