Unicode 0x0 Character: What U+0000 (NULL) Is and How to Find It

What the Unicode 0x0 character (U+0000 NULL) does to your text, how to detect it step by step, how to tell it apart from look-alikes, and how to remove it safely and verify the result.

What the Unicode 0x0 character is

The Unicode 0x0 character, written U+0000 and named NULL, is the first code point in Unicode. It is a control character, not a letter or symbol. It belongs to the C0 control range inherited from ASCII, where the same value is called NUL. It has no visible shape, so in most text it is completely invisible. Its job is to signal something to software, not to be read by a person.

Property | Value
Code point | U+0000
Name | NULL (ASCII abbreviation: NUL)
General category | Cc (control)
UTF-8 bytes | 00
UTF-16 bytes | 00 00
UTF-32 bytes | 00 00 00 00
Common visible stand-ins | ^@ (caret notation), \0 (od -c), ␀ (U+2400 SYMBOL FOR NULL, a separate printable character)

What U+0000 does to your text

The null character has no meaning as content, but software reacts to it in ways that can change or break your text. What happens depends on the program reading it, so the same file can look normal in one tool and fail in another.

  • Truncation: C and many C-based libraries use the zero byte to mark the end of a string, so anything after U+0000 can be silently dropped.
  • Rejection: XML 1.0 does not allow U+0000 at all, not even as a character reference, and PostgreSQL text types do not accept it, so imports and inserts can fail.
  • Replacement: HTML parsers treat it as a parse error and in many contexts substitute U+FFFD REPLACEMENT CHARACTER (�).
  • Binary detection: tools such as GNU grep may decide a file containing zero bytes is binary and report only that it matches instead of showing lines.
  • Hidden mismatches: two strings that look identical on screen compare as different if one contains an invisible U+0000.

Characters that are easy to confuse with it

  • The digit 0 is U+0030, byte 30 in UTF-8. It is visible and is ordinary content.
  • The text 0x0 is three printable characters (0, x, 0), a notation for the number zero, not the null character itself.
  • The text \0 typed into a document is two characters, a backslash and a zero. It only becomes U+0000 when a programming language interprets it as an escape.
  • U+2400 (␀) is a printable symbol that represents NULL; it is not NULL.
  • U+200B ZERO WIDTH SPACE and U+FEFF (byte order mark) are also invisible but are different characters with different bytes.
  • A regular space is U+0020, byte 20.

How to find the null character step by step

Step 1: Look at the raw bytes. Because U+0000 is invisible, the reliable way to see it is a hex view, where it appears as 00. The example below is illustrative: it builds a short string containing one null character and shows the kind of output xxd produces.

# Illustrative example: "abc", NULL, "def"
printf 'abc\0def' | xxd
# 00000000: 6162 6300 6465 66      abc.def
#                 ^^ the 00 byte is U+0000; the text column shows it as "."

Step 2: Count and locate the zero bytes. Counting tells you whether the problem exists; locating tells you where. Deleting every byte except 00 and counting what remains is a dependable way to count in a shell. Python can report exact positions.

# Count U+0000 bytes in a file
tr -cd '\000' < file.txt | wc -c

# Show line numbers of lines containing NULL (GNU grep; -a forces text mode)
grep -n -a -P '\x00' file.txt
# Python: find every U+0000 in a text file
with open('file.txt', encoding='utf-8', newline='') as f:
    text = f.read()

positions = [i for i, ch in enumerate(text) if ch == '\x00']
print(len(positions), positions[:20])

If you prefer an editor or a pager, several common tools make the character visible: Vim displays it as ^@, cat -v prints ^@, and od -c prints \0. In JavaScript, text.indexOf('\u0000') returns its first position, or -1 if it is absent.

Step 3: Work out why the null characters are there before removing them. A very common cause is a UTF-16 file opened as if it were UTF-8 or ASCII. In UTF-16, every basic Latin character takes two bytes, one of which is 00, so the hex view shows a regular pattern of 00 after (or before) each letter. A file that starts with FF FE or FE FF (a byte order mark) is another strong sign of UTF-16.

# Illustrative example: "Hi" saved as UTF-16LE with a byte order mark
FF FE 48 00 69 00
#     H  ^^ i  ^^   each 00 is part of the character, not stray NULL

If the pattern matches UTF-16, convert the encoding instead of deleting the zero bytes; deleting them by hand can corrupt characters outside basic Latin. A typical conversion is iconv -f UTF-16 -t UTF-8 input.txt > output.txt. If the null characters are scattered irregularly, they usually come from padding, binary data mixed into text, or a faulty export, and removing them is normally safe.

Removing U+0000 without touching other content

# Shell: delete only NULL bytes, write to a new file
tr -d '\000' < input.txt > cleaned.txt

# Python: delete only U+0000
cleaned = text.replace('\x00', '')

Step 4: Verify the result. Write the cleaned text to a new file so the original stays available. Then confirm three things: the null count in the new file is 0; in UTF-8, the file is smaller by exactly the number of null bytes you counted in Step 2, because each U+0000 is one byte; and a comparison of the two files shows no changes other than the removed characters.

tr -cd '\000' < cleaned.txt | wc -c     # expect 0
wc -c < input.txt                       # original size in bytes
wc -c < cleaned.txt                     # should be original size minus the NULL count

How the null character is written in code and formats

  • JSON, JavaScript, Java and Python: \u0000
  • Python and many regular expression engines: \x00
  • C and C++: \0 inside a character or string literal
  • Shell printf: \0 or \000
  • URL percent-encoding: %00
  • HTML numeric reference �: a parse error, typically turned into U+FFFD
  • Java modified UTF-8 (used in serialization and class files): encoded as the two bytes C0 80 instead of 00

Limits of this guide

No tool-specific test results were supplied for this article. The commands and outputs above are illustrative examples based on the documented behavior of common tools, not verified output from your system. Options such as grep -P and the exact way a program displays or rejects U+0000 can differ between versions and platforms, so run the counting and verification steps on your own files to confirm the result.