Make use of the zfill() helper method to left-pad any string, integer or float with zeros; it's valid for both Python 2.x and Python 3.x.
It important to note that Python 2 is no longer supported.
Sample usage:
print(str(1).zfill(3))
# Expected output: 001
Description:
When applied to a value, zfill() returns a value left-padded with zeros when the length of the initial string value less than that of the applied width value, otherwise, the initial string value as is.
Syntax:
str(string).zfill(width)
# Where string represents a string, an integer or a float, and
# width, the desired length to left-pad.
Answer from nyedidikeke on Stack OverflowGetting ArcGIS to include leading zeros in text field - Geographic Information Systems Stack Exchange
Problem with leading zeros disappearing when reading an Excel file
How would you add zeros to the beginning of an Integer, such that there are 4 total digits in the number?
pandas question: how can I preserve leading zeros after saving to a CSV?
How do I add leading zeros in Python?
Does zfill change the original string?
Should I use zfill or an f-string?
Make use of the zfill() helper method to left-pad any string, integer or float with zeros; it's valid for both Python 2.x and Python 3.x.
It important to note that Python 2 is no longer supported.
Sample usage:
print(str(1).zfill(3))
# Expected output: 001
Description:
When applied to a value, zfill() returns a value left-padded with zeros when the length of the initial string value less than that of the applied width value, otherwise, the initial string value as is.
Syntax:
str(string).zfill(width)
# Where string represents a string, an integer or a float, and
# width, the desired length to left-pad.
Since python 3.6 you can use f-string :
>>> length = "1"
>>> print(f'length = {length:03}')
length = 100
>>> print(f'length = {length:>03}')
length = 001
Python has a built-in for leading zeros. Use str.zfill() to add leading zeros into a text field.
my_string = "1"
print my_string.zfill(2) # Prints 01
my_string = "1000"
print my_string.zfill(2) # Prints 1000
(example from https://stackoverflow.com/a/21620624/5754917)
So in the field calculator you just need to specify the name of the field with your ID and then fill with zeros
str(!myfield!).zfill(5)

And the end result:

Remember to switch the field calculator to "Python Parser"
Just put your text in quotes. Double quotes if you are in VB Script mode, and double or single if in Python mode.
To explain: When you just enter the numbers, you are giving Field Calculator a value in integer form, which it will convert to a string for you in order to enter it into the string type field. For integers, the leading zeros have no value and no meaning, so they are omitted. If you put it in quotes, you are instead passing it a string, which is already the correct data type, so it gets left alone.
This also assumes that this field is actually of type "Text". Maybe it was set to Long or Short Integer, that would also cause this behavior.