In this structure, “were” is used in cases where you are entertaining a hypothetical, and “was” is for something that was true.
English grammar is often confusing in cases like this because verbs mostly don’t have distinct spellings/pronunciations for the subjunctive mood, even though the subjunctive conjugations are part of the grammar.
It also doesn’t help that “subjunctive” is kind of the “else” condition among the three verb moods, the other two being “indicative” and “imperative,” so you often notice that it’s the subjunctive by ruling out the other two.