Skip to content

Guide

The year 2038 problem

On 19 January 2038, any system still counting Unix time in a signed 32-bit integer runs out of numbers. Most of the world has already moved on, but the bug survives in some surprising places, and some of them fail long before 2038.

By Mark Stoumann ·

The short answer: the largest number a signed 32-bit integer can hold is 2,147,483,647. Read as seconds since 1970, that number is 19 January 2038, 03:14:07 UTC. One second later a 32-bit counter overflows, and software that stores time that way jumps back to 1901. That is the year 2038 bug, also called Y2038, Y2K38 or the “Epochalypse”. A 64-bit timestamp in seconds has no practical limit, but one in nanoseconds ends in 2262, as the table further down shows.

The arithmetic

Unix time counts seconds since 1 January 1970, 00:00:00 UTC. For decades it was stored in a C time_t, which on most systems was a signed 32-bit integer: one bit for the sign, 31 for the number. The largest value that fits is 231 − 1.

ValueDate (UTC)What it is
214748364719 Jan 2038, 03:14:07Last second of signed 32-bit time
-214748364813 Dec 1901, 20:45:52What a 32-bit counter wraps to one second later
42949672957 Feb 2106, 06:28:15Last second of unsigned 32-bit time
8.64 × 1015 ms13 Sep 275760Latest date JavaScript’s Date can hold
263 − 14 Dec 292,277,026,596Last second of signed 64-bit time

The wrap is the dangerous part. Software doesn’t crash with a clear error; it suddenly believes it is 1901. Certificates look not yet valid, cache entries look 136 years old, scheduled jobs fire or never fire, and sorting by date goes wrong. You can check any of these numbers in the timestamp converter.

When does a 64-bit timestamp run out?

Moving to 64 bits is the fix for 2038, but how far it reaches depends on what you count. The same 64-bit integer that lasts for billions of years in seconds lasts only 292 years in nanoseconds:

Signed 64-bit count ofMaximum date (UTC)Earliest date
Seconds4 Dec 292,277,026,596, 15:30:07Long before the Big Bang
Milliseconds17 Aug 292,278,994, 07:12:55About 292 million years ago
Microseconds10 Jan 294247, 04:00:54About 292,000 years ago
Nanoseconds11 Apr 2262, 23:47:1621 Sep 1677, 00:12:43

The nanosecond row is the one to watch. Go’s time.UnixNano() documents that its result is undefined for dates before 1678 or after 2262, and the same 64-bit nanosecond count is common in tracing systems, metrics databases and data-analysis libraries. That is fine for “now”, but not for a birth date in 1650 or a lease that ends in 2300. Store such dates as seconds or as a date type, and keep nanoseconds for measuring durations.

What has already been fixed

On 64-bit operating systems, time_t has been 64 bits for years, so a modern laptop, phone or server is fine. The work since then has been on 32-bit systems, which are still common in routers, industrial controllers, cars and other embedded hardware:

  • The Linux kernel has 64-bit time system calls for 32-bit platforms; the GNU C Library uses them on kernels newer than 5.1.
  • glibc lets 32-bit programs opt into a 64-bit time_t by compiling with -D_TIME_BITS=64, which also requires -D_FILE_OFFSET_BITS=64.
  • Debian rebuilt its 32-bit ARM ports (armel and armhf) with 64-bit time for the Trixie release. It deliberately left 32-bit x86 (i386) alone, because that port mostly exists to run old binaries, which a changed ABI would break.

That last point shows the real difficulty. Recompiling fixes source code you control. It doesn’t fix a binary from a vendor that no longer exists, firmware nobody will update, or data already written to disk in a 32-bit field.

Where the bug still hides

For most developers, the 2038 problem isn’t in the operating system. It is in the data layer and in small shortcuts in application code:

  • MySQL TIMESTAMP columns. The MySQL 8.4 manual still gives their range as 1970-01-01 00:00:01 to 2038-01-19 03:14:07 UTC. DATETIME runs to the year 9999; use it for any date that may fall after 2038.
  • Epoch seconds in INT columns. A signed 32-bit integer column has exactly the same limit. Use BIGINT, or a proper date type.
  • JavaScript bitwise tricks. Date.now() / 1000 | 0 is a popular way to drop the decimals, but | converts to a signed 32-bit integer: 2147483648 | 0 is -2147483648. Use Math.floor().
  • Binary formats and protocols. Any 4-byte timestamp field, in a file header, a network packet or an Int32Array, has the limit built into the format. Changing it means a new format version, not just new code.
  • Casts in typed languages. (int) time(NULL) in C or (int) (System.currentTimeMillis() / 1000) in Java quietly truncates a 64-bit value.

Bugs that arrive before 2038

Anything that calculates dates in the future hits the limit early. A 15-year loan, warranty or certificate issued in 2026 already ends in 2041. A token, licence or cache entry with “no expiry” is often stored as “now plus 20 years”, which crossed 2038 back in 2018. Unit tests that freeze the clock to today don’t catch any of this.

To test, push the date past the limit on purpose: create a record that expires in 2040, read it back, and check the value round-trips; or run the code with a fake clock set to 19 January 2038, 03:14:00 UTC and let it tick past. Watch especially for values that come back negative or as 1901, and for exp claims in tokens. The JWT best practices guide has more on getting token expiry right.

Unix time and leap seconds

The other quirk of Unix time is that it isn’t quite a count of seconds. POSIX defines every day as exactly 86,400 seconds. But UTC, the time scale Unix time follows, has had leap seconds added to keep it in step with the Earth’s rotation: 37 seconds’ difference from atomic time by the most recent one, at the end of 31 December 2016.

So when a leap second happens, Unix time has nowhere to put it. Systems have handled that in different ways: repeating a second, so one timestamp means two moments; stopping the clock for a second; or “smearing” the extra second over a longer period. Google’s public time servers smear it over 24 hours, noon to noon UTC, running clocks about 11.6 parts per million slow, so no timestamp is ever repeated.

Leap seconds are on their way out. In 2022 the General Conference on Weights and Measures decided to raise the tolerance between atomic time and the Earth’s rotation in or before 2035, which in practice means no new leap seconds for a long time. Until then, two lessons hold:

  • Don’t measure durations with wall-clock time. The system clock can jump for leap seconds, NTP corrections or a user changing it. For timing code, use a monotonic clock: performance.now() in browsers, process.hrtime.bigint() in Node, time.monotonic() in Python.
  • Don’t assume a minute has 60 seconds in parsed input. RFC 3339, the internet’s profile of ISO 8601, allows 23:59:60, and a strict parser may reject it.

A short checklist

  • Store times as 64-bit integers, or in date types that run past 2038.
  • Replace MySQL TIMESTAMP with DATETIME for future dates.
  • Search code for | 0, >> 0 and int casts near timestamps.
  • Check every binary format and API field that carries a time: how many bytes?
  • Test with dates after 2038 and with a clock set just before the limit.
  • Ask hardware vendors directly whether embedded devices use 64-bit time.

Frequently asked questions

What exactly happens on 19 January 2038?

At 03:14:07 UTC the Unix time reaches 2,147,483,647, the largest value a signed 32-bit integer can hold. One second later, any system still storing time that way overflows to -2,147,483,648, which it reads as 13 December 1901, 20:45:52 UTC.

Is my computer affected by the year 2038 problem?

Almost certainly not the operating system: 64-bit Windows, macOS, Linux, iOS and Android use 64-bit time. The remaining risk is in 32-bit embedded devices, old binaries, file formats and database columns that store time in 32 bits, and in code that squeezes timestamps into 32-bit integers.

What is the 32-bit integer limit behind the 2038 bug?

A signed 32-bit integer holds at most 2,147,483,647 (2³¹ − 1). Counted as seconds since 1 January 1970, that is 19 January 2038, 03:14:07 UTC. An unsigned 32-bit integer goes to 4,294,967,295, which lasts until 7 February 2106.

What is the maximum date of a 64-bit timestamp?

It depends on the unit. Signed 64-bit seconds run to 4 December of the year 292,277,026,596, and milliseconds to 17 August 292,278,994. But 64-bit nanoseconds, used by Go’s UnixNano and many tracing and database tools, run out on 11 April 2262, 23:47:16 UTC.

Will 64-bit Unix time ever run out?

Not when it counts seconds: a signed 64-bit count of seconds lasts about 292 billion years, far longer than the age of the universe. JavaScript dates stop earlier, in the year 275760, which is still not a practical concern. Only nanosecond counts end soon enough to matter, in 2262.

Does the year 2038 problem affect JavaScript?

JavaScript’s Date uses 64-bit floating point milliseconds, so dates are fine. But bitwise operators convert numbers to signed 32-bit integers, so code like Date.now() / 1000 | 0 breaks in 2038, and so does writing a timestamp into an Int32Array or a 4-byte binary field.

Are leap seconds going away?

Effectively, yes. In 2022 the General Conference on Weights and Measures decided to raise the allowed difference between atomic time and Earth rotation time in or before 2035, which means no more leap seconds for a long time. The last one was added at the end of 2016.