Origin
The popular saying combines two distinct sources.
The biblical half
“The truth will set you free” comes from John 8:32. The verse appears within an exchange between Jesus and a particular audience — verse 31 specifies “the Jews who had believed Him.” The full immediate context (John 8:31–32, BSB):
So He said to the Jews who had believed Him, “If you continue in My word, you are truly My disciples. Then you will know the truth, and the truth will set you free.”
The KJV form (“the truth shall make you free”) is what gets cited most often. The verse is part of a longer discourse (John 8:31–47) that develops the theme of freedom and slavery — initially with the audience misunderstanding Jesus’s claim and replying that they have never been slaves to anyone (verse 33).
The popular use of “the truth will set you free” detaches the saying from its setting, where it is conditional (“If you continue in My word…”) and addressed to a particular audience.
The “miserable” half
The second half — “but first it will make you miserable” or close variants — is most commonly attributed to U.S. President James A. Garfield (1831–1881). Garfield was the 20th president, serving briefly in 1881 before his assassination, and an accomplished classical scholar earlier in his career.
The attribution is widely cited but is itself contested. Quote Investigator and other careful provenance research has not located the full saying in Garfield’s documented speeches, letters, or essays. The earliest verifiable English occurrences of the combined “truth will set you free, but first it will make you miserable” appear in mid-twentieth century American writing, sometimes cited to Garfield, sometimes uncited.
What is documented is that several writers in the late nineteenth and early twentieth centuries used variants of “the truth will make you free, but first it will hurt” or similar, often without attribution. The Garfield association may be folkloric rather than documentary.
How the two get joined
The combined saying functions as a useful piece of consolation for someone in difficulty: yes, the truth helps in the long run, but it is not painless to encounter. The piggy-backing of the second half onto the biblical first half lends the whole saying biblical authority, even though only the first half is actually in the Bible.
What this entry does not do
We do not adjudicate the question of whether the saying is good advice (it might be). We do document that the full saying is not biblical — only the first half is — and that even the second half’s Garfield attribution is contested in current scholarship.
The biblical half is real. The combined saying as a single quotation is not biblical and probably not Garfield’s either.