Betting is the act of putting more chips into the pot that your opponents must either call by putting in their own chips or fold by discarding their hand. Some bets are blind (such as blinds in Hold'Em or antes in Stud), some bets are set in size (as in Limit games) and others can be as much as you have in front of you (as in No Limit games). But betting is the essence of poker: you bet that you have the best hand, and your opponent either puts up chips of their own or gets out of there.
When to Bet
When you bet, you're doing so for one of two reasons: either to build the pot by making your opponent call, or to win the pot by forcing an opponent to fold. Either way, the point is to win the pot! So you should always bet when you believe it increases your chances of winning, as well as the number of chips you'll win.
How to Bet
How you bet varies depending on the game you're playing.
Most games have blind bets, such as blinds or antes, before any cards are dealt. These are forced bets, and you don't have a choice: you have to pay up front. Most ante games have everyone post a small amount, whereas blind games only require one or two players to do so. Always know the stakes of these bets before you sit down.
In Limit games, how much you bet is set: you can bet the lower limit (on the first few rounds of betting) and then the upper limit (in later rounds of betting, or when special circumstances allow). Many times, you have the option between the lower bet and the higher bet, this rule varies from table to table.
In Pot-Limit games, you can bet anywhere from the minimum (usually the size of the big blind) all the way up to the size of the pot: you count the chips in the pot, and that's the maximum bet.
In No-Limit games, you bet anywhere from the minimum (again, usually the size of the big blind) all the way up to everything in front of you, the big play, all-in!
In all cases, you can state "bet" and then put chips in the pot. But remember, verbal actions are binding, so if you state the amount you bet, that's how much your opponents are obligated to call. And at the other end, if you say "bet" and then place chips in the pot without citing the amount, be careful: if you accidentally slipped your $100 chip at the bottom of a stack of $1s, your bet is binding!
About Bet Sizes
Betting in poker is about giving misinformation to your opponent: you want to bet in a way that makes them think how you want them to think. So, if you want your opponent to be afraid, you need to bet just enough for them to think you have the best hand, but not so much that they think you're bluffing. If you want your opponent to call, you want to bet enough to lure them in, but not so little that they think you're stringing them along. Every player, table, and hand is different, so learning how much to bet and when is one of the hardest, most nuanced parts of the game.