It is Latin for after the fact, and it names one of the oldest protections of fairness: the government cannot punish you today for something that was legal when you did it.
An ex post facto law is one that criminalizes an act after it was committed, or increases the punishment for a crime after the fact. The phrase is Latin, meaning from a thing done afterward. The Constitution bans such laws twice, for both the federal government and the states.
The principle is simple fairness. You can only follow the rules if you know what they are. A government that could declare past, legal actions criminal would leave no one safe, since anything you ever did might become a crime tomorrow.
The framers considered it fundamental. In Federalist No. 44, James Madison wrote that ex post facto laws are contrary to the first principles of the social compact, and to every principle of sound legislation. Hamilton called such retroactive lawmaking among the favorite tools of tyranny.
It has limits and nuances. The ban applies to criminal punishment, not every retroactive rule, so some civil laws can reach backward. But no government may make you a criminal now for something that broke no law when you did it.