Let's imagine, for example, that your local town has a littering problem. Littering is entirely legal in town. A law is written to ban littering, but lawmakers want to catch perpetrators who have already been littering--so they make the law effective as of five years ago. This would be an ex post facto law.
Ex post facto laws are generally frowned upon because if it is possible to write ex post facto laws, there is no way of knowing whether one's actions are legal or illegal. Article I of the U.S. Constitution prohibits the passage of ex post facto laws, probably for this reason.