Does ord() Return an ASCII Value? What You Actually Need to Know

The short answer is: yes, but with an important nuance. The ord() function in Python returns the Unicode code point of a character — and for any standard ASCII character, that code point is identical to its ASCII value. Understanding where those two things overlap, and where they diverge, is what separates a surface-level answer from a genuinely useful one.

What ord() Actually Does

The ord() function is a built-in Python function that takes a single character string as input and returns an integer representing that character's position in the Unicode standard.

ord('A') # Returns 65 ord('a') # Returns 97 ord('0') # Returns 48 ord(' ') # Returns 32 

These numbers will look familiar if you've ever glanced at an ASCII table — because they're the same values. That's not a coincidence.

Why ASCII and Unicode Overlap

ASCII (American Standard Code for Information Interchange) is a character encoding standard that assigns numeric values to 128 characters — uppercase and lowercase English letters, digits 0–9, punctuation marks, and a set of control characters. Its range spans 0 to 127.

Unicode was designed as a superset of ASCII. The first 128 code points in Unicode (U+0000 through U+007F) are identical to their ASCII equivalents. This was an intentional compatibility decision, made so that existing ASCII-based systems and software could transition to Unicode without breaking.

So when you run ord('A') and get 65, you're getting the Unicode code point for the letter A — which also happens to be the ASCII value for the letter A. Same number, two different systems, deliberately aligned.

Where the Two Systems Diverge

ASCII tops out at 127. Unicode, by contrast, currently defines over 140,000 characters spanning virtually every writing system on Earth, plus emoji, mathematical symbols, historic scripts, and more.

Characterord() ResultIn ASCII?
'A'65✅ Yes
'z'122✅ Yes
'é'233❌ No (Latin Extended)
'中'20013❌ No (CJK Unified)
'😀'128512❌ No (Emoji block)

For any character beyond the 0–127 range, ord() still works perfectly — it returns the Unicode code point — but there is no corresponding ASCII value. Those characters simply don't exist in ASCII.

The Reverse Function: chr()

🔁 ord() has a direct inverse: chr(). Where ord() takes a character and returns an integer, chr() takes an integer and returns the corresponding character.

chr(65) # Returns 'A' chr(128512) # Returns '😀' 

This pair of functions is commonly used when you need to shift characters (such as in Caesar cipher implementations), generate character ranges programmatically, or convert between numeric encodings and human-readable text.

Common Use Cases Where This Matters

Character comparison and sorting logic — Because ord() returns a consistent numeric value, developers use it to implement custom sorting rules, check whether a character falls within a certain range (e.g., ord('a') <= ord(c) <= ord('z')), or validate input types.

Encoding-aware text processing — If you're working only with standard English text, treating ord() output as ASCII values is effectively safe. But if your application handles international text, user-submitted content, or data from external APIs, you'll encounter characters beyond 127. In those cases, thinking of ord() as an "ASCII lookup" breaks down.

Low-level protocol and networking work — Some network protocols, file formats, and data serialization schemes are byte-oriented and closely tied to ASCII. When parsing or building those structures in Python, ord() is often used to inspect individual bytes or characters against expected ASCII code points.

Cryptography and obfuscation — Basic encoding schemes frequently use ord() and chr() to shift character values, XOR them against a key, or map them through a substitution table.

Python Version Note

In Python 2, strings were byte strings by default, and the behavior of ord() was more tightly coupled to ASCII and byte values. In Python 3, strings are Unicode by default, so ord() always operates against Unicode code points — even if the character you pass happens to be ASCII. This distinction matters if you're maintaining or reading older codebases.

Variables That Affect How This Plays Out in Practice

Whether treating ord() output as an ASCII value is appropriate depends on several factors:

  • What characters your data actually contains — Pure English text vs. international input vs. emoji vs. binary data all behave differently
  • The encoding of your source data — UTF-8, Latin-1, and ASCII-encoded files may look similar until they hit a non-ASCII byte
  • What you're comparing against — If your reference table or protocol specification is ASCII-based, values above 127 will produce unexpected results
  • Python version in use — Python 2 vs. Python 3 changes the underlying string model entirely

A developer working on a simple English-language text utility and a developer building a multilingual content platform will use ord() the same way syntactically — but the assumptions they can safely make about the output are quite different. Your own data, your application's scope, and what character ranges you realistically need to handle are what determine whether the ASCII-Unicode overlap is a useful shortcut or a potential blind spot. 🧠