What are text codes used for in texting?

Text codes are often used to enter sweepstakes and contests. Text codes are also used for verification and security purposes, such as Google's 2-step verification system for email.