QouratR&D centreContact

Is SHA-256 random, how is it calculated, and can it be reversed?

SHA-256 is deterministic and one-way by design, giving the same 256 bits for the same message with no inverse equation to recover the original.

Its output looks random. Flipping one input bit changed 127.95294 of 256 output bits on average across 100,000 messages.

Our calculation matched all 129 byte-oriented NIST short- and long-message cases we checked. Our machine evaluated 1,159,383 short messages per second.

Even at that rate, the usual work estimate for matching a given digest exceeds the age of the universe by a factor of about 10⁵³.

On this page

Question

Why use a calculation that looks like a coin toss to check a file? A hash is a fingerprint of its exact bytes. Anyone with the file can calculate it again. When we read the billion fractional digits of koppa back from disk, their SHA-256 matched the fingerprint recorded when the series calculation wrote them. That checks the stored digits against that run. Establishing their mathematical accuracy takes an independent calculation. How the koppa digits were calculated.

Does the fingerprint give the file away? A digest can confirm a familiar message. Recovering an unknown original from its fingerprint alone is a different question.

Data

On 29 November 2026 we generated 100,000 public 32-byte messages from a fixed seed. For each message we chose one of its 256 bits and changed just that bit. This gave 100,000 pairs for the change experiment. The original digests alone supplied 3,200,000 bytes, or 25,600,000 bits, for the balance tests. Using a seed lets anyone recreate the sample. It provides no evidence of physical randomness.

Method

From a message to a fingerprint

Imagine hashing the five letters of koppa. In ASCII they take 40 bits. Append one 1 bit, then 407 zero bits, then the original length 40 written in 64 bits, most significant bit first. That fills one 512-bit block. For any length L below 2⁶⁴ bits, choose the smallest nonnegative number of zeros that brings L + 1 + zeros to 448 modulo 512, then append the length. A 56-byte message already needs a second block. Secure Hash Standard, §§5–6.

Two padded message blocks feed two successive compression steps, carrying the first state into the second
A longer message repeats the same step. Each block supplies new data while the eight-word state carries everything accumulated so far.Open full-size figure

Where the numbers come from. A word is 32 bits. Take the square roots of the first eight primes, discard the integer parts and keep the first 32 binary fraction bits of each. These are the eight starting words. For example, floor((√2 − 1) × 2³²) gives 6a09e667 in hexadecimal. The 64 round constants use cube roots of the first 64 primes. The same calculation with ∛2 gives K[0] = 428a2f98, and with ∛3 gives K[1] = 71374491. The reference code derives them with exact integer roots.

Prepare a block. Read its bytes left to right into sixteen big-endian words W[0] through W[15]. Expand those to 64 words. Every addition of words below keeps only the low 32 bits, which is addition modulo 2³².

W[t] = σ₁(W[t−2]) + W[t−7] + σ₀(W[t−15]) + W[t−16], for t = 16 through 63.

Rₙ rotates a word right by n bits, wrapping the bits at the edge back to the front. Sₙ shifts right and fills with zeros. XOR (⊕) gives 1 where two bits differ. The two schedule functions are:

  • σ₀(x) = R₇(x) ⊕ R₁₈(x) ⊕ S₃(x).
  • σ₁(x) = R₁₇(x) ⊕ R₁₉(x) ⊕ S₁₀(x).

Mix for 64 rounds. Copy the incoming state into eight working words a through h. In each round t from 0 through 63, Ch uses each bit of e to choose the corresponding bit of f or g. Maj takes the majority of three bits. Here ∧ means bitwise AND and ¬ flips every bit of a word.

  • Ch(e,f,g) = (e ∧ f) ⊕ ((¬e) ∧ g).
  • Maj(a,b,c) = (a ∧ b) ⊕ (a ∧ c) ⊕ (b ∧ c).
  • Σ₁(e) = R₆(e) ⊕ R₁₁(e) ⊕ R₂₅(e).
  • Σ₀(a) = R₂(a) ⊕ R₁₃(a) ⊕ R₂₂(a).
  • T1 = h + Σ₁(e) + Ch(e,f,g) + K[t] + W[t].
  • T2 = Σ₀(a) + Maj(a,b,c).

Replace (a, b, c, d, e, f, g, h) together with (T1 + T2, a, b, c, d + T1, e, f, g), using the old values on the right.

Combine the blocks. After round 64, add each working word back to its corresponding incoming word. Those eight sums start the next block. This chaining is called the Merkle–Damgård construction. After the last block, join the eight final words in order, most significant byte first. The result is 256 bits, conventionally written as 64 hexadecimal digits. FIPS 180-4, §6.2.2.

Results

The same bytes, the same result

We hashed koppa 1,000 times with our implementation and got one distinct digest. Below are three forward calculations. The empty input contains zero bytes. Neither word includes quotes, a space or a newline.

Each exact message has a repeatable 64-digit fingerprint.CSV
MessageSHA-256 (hex)
(empty)e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
koppa2e613d6561cf37d6d8adcc73beae6e9e4ddea4869fce4d8270182918c1a85c10
apple3a7bd3e2360a3d29eea436fcfb7e44c735d117c42d1c1835420b6b9942dd4f1b

Suppose someone hands you the digest beginning 3a7bd3e2 and tells you the input is in this little table. The full digest on the last row identifies apple among these three candidates. A dictionary lookup recognizes a known possibility this way. Its success comes from knowing the shortlist. For comparison, we drew one public 32-byte sample from the operating system. Its digest begins 2d9325c3 and matches none of the rows. If those 32 bytes were independently uniform and still secret, one exact guess would have a 1 in 2²⁵⁶ chance of naming the original. You can check the forward calculation from the recorded input and digest.

Change one bit

The bars show how many of the 256 output bits changed. The mean was 127.95294 bits (49.98%) and the sample standard deviation was 7.97623 bits. Under a model of 256 independent fair bit changes, the count has a binomial distribution, with mean 128 and standard deviation 8. The width of the curve describes variation from one message to the next.

Counts peak near 128 changed bits and follow the theoretical binomial curve
The bars count message pairs at each distance. The line is the expected count for 256 independent fair bit changes, with no fitted parameters.Open full-size figure

Our predeclared 95% band for the sample mean was 127.95042 to 128.04958 bits. The measured mean fell inside it. A separate check of the whole shape pooled the two tails through 110 and from 146. Pearson χ² was 30.7452 on 36 degrees of freedom, p = 0.71655. The curve fits this sample within its sampling variation. All 257 distances and model counts (CSV).

Are some output values favoured?

Among the original digests the uniform model predicts 12,500 occurrences of each byte value, from 0 to 255. We added up (observed − expected)² / expected across all values. The result was χ² = 274.63776, with 255 degrees of freedom and p = 0.19009518. Under the model, about 19% of samples would have a discrepancy at least this large. This measures consistency with uniformity. It does not give the probability that SHA-256 is random. Counts for every byte (CSV).

Each of 256 output positions lies close to the 50 percent reference line
Each dot is one bit position across 100,000 digests. The fraction of ones ranged from 49.524% to 50.465%. The vertical scale is enlarged to show those differences.Open full-size figure

The frequency test counts ones. The runs test counts uninterrupted stretches of equal bits, including runs that cross digest boundaries. We read each byte most significant bit first. Both tests passed our predeclared p ≥ 0.01 threshold on this single stream. The fraction of ones also met the runs test prerequisite, within 2/√n of one half for n bits. NIST SP 800-22, §§2.1 and 2.3.

Two different properties of the same stream passed their individual tests.5 columnsCSV
TestStatisticValuep-valueAt 0.01
FrequencyAbsolute imbalance / √n1.431720.15222362Pass
RunsRun count12,799,6000.87468629Pass

The 256 position rates are descriptive, with each bit count available here. The shape, byte, monobit and runs comparisons share data. Their p-values are individual results, with no joint significance claim.

Can the calculation run backwards?

There is no inverse equation that returns the original message in general. There are exactly 2²⁵⁶ possible digests. Even the set of 33-byte messages alone contains 2²⁶⁴ possibilities. Fitting them into fewer outputs forces some inputs to share an output. This is the pigeonhole principle. It says nothing about exactly how many messages land on any particular value. FIPS also places a finite limit on message length. Secure Hash Standard.

The 64 rounds mix the message into a running state. Each compression keeps only eight words and the digest omits the blocks and intermediate states. Mixing alone would be a poor explanation for one-wayness. Information is lost in compression, and computing any matching message for a given, unpredictable digest is a separate computational problem. SHA-256 is designed to make that infeasible. The generic alternative is guessing a possible input and comparing its forward fingerprint. NIST’s security strengths.

A preimage is any message for a given digest. A second preimage is a different message matching one specified message. A collision is any pair of different messages with the same digest. Here is a collision you can check by hand in a deliberately weak 16-bit toy checksum: add the byte values and keep the low 16 bits. Both ab and ba give 195, since 97 + 98 = 98 + 97. For full SHA-256, standardized in 2002, no computationally feasible way to find a collision or a preimage for a general target is publicly known after more than twenty years of public scrutiny. That history and the published security assessments are the defensive basis for trusting a file fingerprint. Original standard and current strengths.

How long is “infeasible”?

Our server computed 1,159,383 complete SHA-256 digests per second in a single Python loop, using OpenSSL and one fixed public 32-byte message. A separate timeit harness measured 1,199,794 per second, 3.49% higher. Both are medians of seven batches of one million on an Intel Xeon E-2236. These are rates for this workload, including Python overhead. Individual elapsed times and rates (CSV).

For an ideal 256-bit hash, matching a given digest takes about 2²⁵⁶ independent evaluations on average. That is a work scale, not a guaranteed stopping point. Finding any matching pair takes work on the order of 2¹²⁸, because the number of possible pairs grows roughly as the square of the number of outputs. This is the birthday effect. We divided each conventional work factor by our unrounded primary rate, then by 4.35 × 10¹⁷ seconds, about one age of the universe. NIST strength estimates and Planck cosmological parameters.

Both classical work scales exceed human timescales by many orders of magnitude.5 columnsCSV
GoalBitsHash evaluationsSecondsUniverse ages
Any pair1283.403e+382.935e+326.747e+14
Given digest2561.158e+779.987e+702.296e+53
Work increases exponentially with the number of bits and exceeds the age of the universe far below 128 bits
Each additional bit doubles the time. Equal vertical distances mean equal factors of time. The dots mark the 128-bit and 256-bit work scales at this server’s rate.Open full-size figure

Faster hardware shifts the line down. It does not change the doubling for each extra bit. These are extrapolations, with no attempt to observe a real break. Work and seconds plotted (CSV).

Checks

Confirmed in our implementation. Pass on 65 of 65 NIST short-message vectors and 64 of 64 long-message vectors. For example, the empty-message answer begins e3b0c442; the single byte d3 begins 28969cdf. We compared all 64 digits on every case. Pass on 2,048 of 2,048 seeded messages of varying lengths against Python’s OpenSSL-backed hashlib, plus 12 of 12 explicit padding-boundary cases. These are conformance checks on specified inputs. Official CAVP vectors, three input and result examples and all 129 computed results.

Two implementations give the same avalanche mean and byte statistic.4 columnsCSV
CalculationMean bitsByte chi-squareByte p
Reference and counts127.95294274.637760.19009518
OpenSSL and arrays127.95294274.637760.19009518

The second calculation read the same fingerprinted message-and-bit records. It hashed them with OpenSSL, unpacked and counted bits with NumPy, and evaluated the byte counts with SciPy. The reference calculation used word operations and exact integer counts. The exact mean and χ² agreed. SciPy’s stored binary64 χ² was 5.68 × 10⁻¹⁴ lower than the exact rational statistic rounded to binary64. SciPy’s floating-point p-value differed from the theoretical p-value by less than 10⁻¹⁵. Every displayed digit agrees.

Observed in the sample. One-bit changes followed the expected binomial shape. Byte counts, runs and the overall proportion of ones were consistent with the fair-bit model. The data establish those outcomes for our fixed seed. A finite collection of tests cannot prove randomness or cryptographic strength. Nor would our own failure to find a weakness prove security. Confidence depends on independent public analysis over time. NIST’s test limitations and Schneier’s law.

What it means in plain words

Unpredictable to whom? If you know the message, every bit is predictable. If the message is secret and sufficiently hard to guess, its fingerprint can look unpredictable to someone without it. A common word can be recognized even when its digest looks irregular. “Pseudo-random” here describes that appearance, not fresh randomness created by hashing.

Statistically even in what sample? The 256 byte values would be equally likely in a uniform model. Our measured frequencies fluctuated around that prediction. Even a perfectly balanced string can be predictable: repeating 01 gives exactly half ones, and you always know the next bit.

Can it be described more briefly? Kolmogorov complexity counts the bits in the shortest program that prints the data on a fixed description machine. The whole digest stream here has a short description: its seed, generator, hash algorithm and sample size. However irregular it looks, that recipe is much shorter than 25,600,000 bits. For one digest, describing “SHA-256 of X” also requires describing X and the computation. Formally, K(SHA-256(X)) ≤ K(X) + a fixed program overhead. It does not follow that every single 256-bit digest has a description shorter than 256 bits. Statistical tests cannot settle an individual string’s shortest description. Li and Vitányi.

Does nature supply real randomness? Yes, in the operational sense supported by quantum experiments. Quantum mechanics gives probabilities for which detector will register a photon or when an individual unstable atom will decay. Bell tests go further than an irregular-looking graph: separated observers choose measurement settings, then compare their outcomes. Local, preassigned answers with independent setting choices obey a mathematical bound. Hensen and colleagues measured a CHSH value of 2.42 ± 0.20 against a local bound of 2. A photonic experiment by Bierhorst and colleagues extracted 1,024 certified random bits under independent setting choices and the physical limit on superluminal signalling. Bell test and photonic randomness experiment.

There is an interpretation caveat. Bell violations exclude local hidden-variable explanations under those assumptions. Deterministic, nonlocal interpretations such as Bohmian mechanics remain possible. The experimental unpredictability claim and the philosophical claim that nature has no underlying determinism have different evidential requirements. Dürr and colleagues.

Where does a computer get randomness? Software starting from a fixed state repeats its output. A computer can sample electronic noise or collect unpredictable timing events. It may condition the samples before seeding a deterministic generator. Fresh uncertainty comes from the input. NIST on entropy sources.

What about passwords? Our measured rate is an advantage for checking large numbers of files. The same speed is a liability for a short, familiar password. Password storage uses a unique salt and a purpose-built password hashing scheme with a tunable cost, so each check takes deliberate work. NIST authentication guidance.

References

The forward standard, known-answer vectors and statistical test definitions specify what can be repeated. The 2002 standard, security strengths, comment on independent analysis and cosmological age support the time comparison and its limits.

The distinctions between randomness claims draw on algorithmic complexity, the CHSH experiment, photon-based randomness and quantum interpretation. The practical guidance comes from entropy sources and password storage.

Download reference list

  1. NIST, Secure Hash Standard (FIPS 180-4)

    Sections 4–6 specify length, bit functions, roots, scheduling and chaining.

    Opened 2026-11-29
  2. NIST CAVP, Secure Hashing — SHA test vectors for byte-oriented messages

    CAVS 11.0 SHA256ShortMsg and SHA256LongMsg inputs and expected outputs, available under Test Vectors.

    Opened 2026-11-29
  3. NIST, Hash Functions — Security Strengths of Approved Hash Functions

    The SHA-256 row assigns 128 bits for collision resistance and 256 for preimage resistance.

    Opened 2026-11-29
  4. NIST, Secure Hash Standard (FIPS 180-2, August 2002)

    Dates the earlier standard that specified SHA-256.

    Opened 2026-11-29
  5. NIST SP 800-22 Rev. 1a, A Statistical Test Suite for Random and Pseudorandom Number Generators for Cryptographic Applications

    Sections 2.1 and 2.3 define frequency and runs tests. The introduction explains the limitations of a test suite.

    Opened 2026-11-29
  6. Ming Li and Paul Vitányi, An Introduction to Kolmogorov Complexity and Its Applications

    The shortest effective description, machine dependence and incompressibility of finite strings.

    Opened 2026-11-29
  7. B. Hensen et al., Experimental loophole-free violation of a Bell inequality using entangled electron spins separated by 1.3 km

    The Nature experiment tested the CHSH local bound with independently chosen settings.

    Opened 2026-11-29. arXiv 1508.05949
  8. P. Bierhorst et al., Experimentally generated randomness certified by the impossibility of superluminal signals

    The Nature photonic Bell experiment extracted 1,024 bits under stated independence and locality conditions.

    Opened 2026-11-29
  9. D. Dürr et al., Quantum Equilibrium and the Role of Operators as Observables in Quantum Theory

    Bohmian mechanics supplies a deterministic interpretation of quantum measurement.

    Opened 2026-11-29. arXiv quant-ph/0308038
  10. NIST SP 800-90B, Recommendation for the Entropy Sources Used for Random Bit Generation

    Noise sources, conditioning and entropy assessment in physical random-bit generation.

    Opened 2026-11-29
  11. Planck Collaboration, Planck 2018 results. VI. Cosmological parameters

    Table 2 gives a model-dependent cosmological age of approximately 13.8 billion years. Times here use a rounded 4.35 × 10¹⁷ seconds.

    Opened 2026-11-29. arXiv 1807.06209
  12. NIST SP 800-63B-4, Digital Identity Guidelines — Authentication and Authenticator Management

    Password storage uses a salt and a suitable password hashing scheme with a cost factor.

    Opened 2026-11-29
  13. Bruce Schneier, “Schneier’s Law”

    An inventor’s failure to see a weakness is insufficient evidence for security.

    Opened 2026-11-29

Reproduce

The programs and recorded inputs are in code/ in the extracted archive. The original byte-oriented test vector ZIP belongs to NIST and is available from its Cryptographic Algorithm Validation Program. The README gives its address and fingerprint. The vector results are in tables/vector-results.csv and the bit-change distribution in tables/avalanche.csv. The optional billion-digit file is omitted because of its size. The koppa digit study supplies the series program to regenerate it. The archive records the digit fingerprint and the original machine timings.

Run the commands in code/README.md from the extracted code directory with Python 3.12, NumPy and SciPy. The calculation regenerates its input, verifies the NIST archive fingerprint, checks the reference implementation and rebuilds the tables and figures. Replaying the saved timings reproduces the time estimates. A fresh speed measurement varies with machine load.

To regenerate the corpus in Python 3.12, draw a message and then its bit index on each iteration. Index 0 is the most significant bit of the first byte. Append the index as one byte to each message when computing the corpus fingerprint.

import hashlib
import random

rng = random.Random(20261129)
digest = hashlib.sha256()
for _ in range(100_000):
    message = rng.randbytes(32)
    index = rng.randrange(256)
    digest.update(message)
    digest.update(bytes([index]))
print(digest.hexdigest())

On 29 November 2026 the SHA-256 of the input records, each comprising 32 message bytes then one changed-bit index, was 406b71ac512c78f14f4dd06d54df28ce2911e5176412fd9eca791c85a0818dfd.

Change log

29 November 2026. Recorded the forward implementation, conformance results, distribution tests, timings and independent calculations.

3 December 2026. The calculation programs and reproduction notes were made portable for the archived copy. No result changed.

What this leaves open

  • What evidence would change the published security assessment of a hash?
  • How much unpredictable information does a hardware noise source actually supply?

Our review

Rating 8.3 out of 10

  • Question 14 of 15
  • Evidence 21 of 25
  • Verification 13 of 15
  • Sources 14 of 15
  • Usefulness 16 of 20
  • Originality 5 of 10

The implementation passes 129 reference cases, but the avalanche sample measures a narrow property and cannot establish one-way security.

This is the centre's own review, not peer review by outside scholars; see Policies.

Cite this study

Titles are italic in Harvard, APA, MLA and Chicago.

First published .

Harvard

Qourat 2026, Is SHA-256 random, how is it calculated, and can it be reversed?, Research 111, Qourat Research and Development Centre, https://qourat.com/research/is-a-hash-random/

APA (7th edition)

Qourat. (2026). Is SHA-256 random, how is it calculated, and can it be reversed? (Research 111). Qourat Research and Development Centre. https://qourat.com/research/is-a-hash-random/

IEEE

[1] Qourat, “Is SHA-256 random, how is it calculated, and can it be reversed?” Qourat Research and Development Centre, Research 111, Nov. 30, 2026. [Online]. Available: https://qourat.com/research/is-a-hash-random/

MLA (9th edition)

Qourat. Is SHA-256 Random, How Is It Calculated, and Can It Be Reversed? Research 111, Qourat Research and Development Centre, 30 Nov. 2026, https://qourat.com/research/is-a-hash-random/.

Chicago (author-date)

Qourat. 2026. Is SHA-256 Random, How Is It Calculated, and Can It Be Reversed? Research 111. Qourat Research and Development Centre. https://qourat.com/research/is-a-hash-random/.

BibTeX

@techreport{qourat-111,
  author = {Qourat},
  title = {{Is SHA-256 random, how is it calculated, and can it be reversed?}},
  institution = {Qourat Research and Development Centre},
  number = {Research 111},
  year = {2026},
  date = {2026-11-30},
  url = {https://qourat.com/research/is-a-hash-random/}
}

Add the date you read the page if your style asks for one.