A credit freeze lasts until you lift it. It does not expire on its own, it is free to place and to lift, and it does not affect your credit score. While it is in place, nobody can open a new credit account in your name, including you.
To freeze your credit, contact all three nationwide credit bureaus: Equifax, Experian, and TransUnion. When you need a lender, landlord, employer, or insurer to check your credit, you can lift the freeze temporarily (or for a period you choose), ideally at just the bureau that will be checked, and then put it back. By law, a bureau must lift a freeze within one hour of a request made by phone or online, or within three business days of a request made by mail.
Source: FTC Consumer Advice: Credit Freezes and Fraud Alerts; see also CFPB: What is a credit freeze or security freeze?
Image: “Credit Cards In Wallet” by Chris Potter, CC BY 2.0, via Wikimedia Commons.