How long you can stay in the U.S. on a visitor or some other type of visa is a frequent source of confusion. This can ultimately lead to unintended overstays and other immigration violations, which can bring harsh consequences. Part of the typical confusion is that you will probably see two different dates on the two documents associated with your U.S. entry: your visa and your Form I-94.
These dates mean very different things, as discussed here.
Your U.S. visa, which you will receive at a United States embassy or consulate (most likely in your home country) before you depart for the United States, will contain an expiration date. That date might be several months or years into the future. That's for your convenience: A U.S. visa is an entry document. By giving you ample time to pack your bags and enter the United States, it saves you (and the consulate) from a return visit if you don't manage to depart as soon as you thought you would.
In fact, you might receive a "multiple entry" visa, which can be used more than once. This is often the case with the B-2 tourist visa. It allows you to enter the United States many times over the years (up to ten years), until the visa has expired or is cancelled. Why would a visa be cancelled? Perhaps because you violated its terms, say, by staying in the U.S. longer than permitted, committing a crime while there, or taking a job without authorization.
The important thing to realize is that you are not allowed to stay in the U.S. up to the date the visa expires. Many people get this wrong. Staying through the whole period of your visa validity can result in your being removed (deported) from the U.S., and future immigration troubles if you attempt to return to the U.S. (whether or not you were removed).
Every time you arrive at the United States airport, border, or other port of entry, you will be issued a Form I-94 Arrival/Departure Record. Many years ago, all U.S. visitors received a paper card stapled in their passports. Today, however, this form has been automated and can be accessed and printed out from the Customs & Border Protection (CBP) website. The date listed there is the last date you are allowed to remain in the United States.
The departure date is crucial: You are allowed to stay in the U.S. only until that date, regardless of whatever date is written on your visa. For example, if you enter the U.S. as a B-2 tourist, the date will likely be six months into the future. If you enter on an H-1B or other work visa, it might be a year or more into the future.
If you enter as a student, you will probably see "D/S" instead of a date. That stands for "duration of status," and means you may stay until your studies are completed (so long as you do not violate the terms of your visa in the meantime).
If you stay in the U.S. past the expiration date shown on your I-94, then you are considered "out of status," and your visa is automatically cancelled.
There are further consequences to an overstay, as well. You will not be allowed to apply for a U.S. green card within the U.S. (adjustment of status) or for a change of status, even if you have become eligible for some type of green card or a different visa (with a few exceptions).
You can also be arrested by the U.S. immigration authorities, placed into court proceedings, and ultimately removed from the United States. This doesn't happen systematically, but it's a real risk.
If you leave the U.S., you will no longer be able to use the cancelled visa for travel to the United States, but will have to apply for a new visa first. You won't have any choice of where to apply, but will be limited to doing so at a U.S. consulate or embassy in your home country. If you leave after having been deported, your application to return won't even be considered for a number of years (unless you successfully apply for a waiver).
What's more, your overstay time in the U.S. can be classified as "unlawful presence." This leads to separate and troublesome consequences under the U.S. immigration laws, as described under Consequences of Overstaying on a Temporary U.S. Visa.
Various exceptions to these rules exist, as well as waivers of the bars on returning to the United States. But the exceptions are very limited and waivers difficult to obtain, so if you have already overstayed a visa, see an immigration attorney for a full analysis and for assistance with your future applications for a visa or green card.