To score a touchdown, one team must take the football into the opposite end zone. The touchdown is scored the instant the ball crosses the plane of the goal line—that is if any part of the ball is in the space on, above, or across the goal line—while in possession of a player whose team is trying to score in that end zone. The play is dead and the touchdown scores the moment the ball crosses the goal line in possession of a player, or the moment the ball comes into possession of an offensive player in the end zone (having established possession by controlling the ball and having one or both feet or another part of the body on the ground). The slightest part of the ball being over the goal line is sufficient for a touchdown to score. However only the ball—not a player's helmet, foot, or other part of the body—counts. Touching one of the pylons at either end of the goal line with the ball constitutes "breaking the plane" as well.
Touchdowns are usually scored by the offense by running or passing the ball. However, the defense can also score a touchdown if they have recovered a fumble or made an interception and return it to the opposing end zone. Special teams can score a touchdown on a kickoff or punt return, or on a return after a missed or blocked field goal attempt or blocked punt. In short, any play in which a player legally carries the ball across the goal line scores a touchdown, the manner in which he gained possession is inconsequential. In the NFL, a touchdown may be awarded by the referee as a penalty for a "Palpably Unfair Act" such as a player coming off the bench during a play and tackling the runner who would otherwise have scored.
A touchdown is worth six points. The scoring team is also awarded the opportunity for an extra point or a two-point conversion. Afterwards, the team that scored the touchdown kicks off to the opposing team, if there is any time left.
Unlike a try scored in rugby, and contrary to the event's name, the ball does not need to touch the ground when the player and the ball is inside the end zone, although in gridiron's early days the ball was required to be touched to the ground as in rugby, as rugby and gridiron were extremely similar sports at this point. This rule was changed to the modern-day iteration in 1889.
When the first uniform rules for American football were enacted by the newly formed Intercollegiate Football Association just following the 1876 Rugby season, a touchdown counted for 1/4 of a kicked goal (except in the case of a tie) plus it allowed the offense the chance to kick for goal by placekick or dropkick from a spot along a line perpendicular to the goal line and passing through the point where the ball was touched down, or through a process known as a "punt-out", where the attacking team would kick the ball from the point where it was touched down to a teammate. If the teammate could fair catch the ball, he could follow with a try for goal from the spot of the catch, or resume play as normal (in an attempt to touch down the ball in a spot more advantageous for kicking). The governing rule at the time read: "A match shall be decided by a majority of touchdowns. A goal shall be equal to four touchdowns, but in the case of a tie, a goal kicked from [after] a touchdown shall take precedence over four touchdowns." 
In 1881, the rules were modified so that a goal kicked from a touchdown took precedence over a goal kicked from the field in breaking ties.
In 1882, four touchdowns were determined to take precedence over a goal kicked from the field. Two safeties were equivalent to a touchdown.
In 1883, points were introduced to football, and a touchdown counted as four points. A goal after a touchdown also counted as four points.
In 1889, the provision requiring the ball to actually be touched to the ground was removed. A touchdown was now scored by possessing the ball beyond the goal line.
In 1897, the touchdown scored five points, and the goal after touchdown added another point.
In 1900, the definition of touchdown was changed to include situations where the ball becomes dead on or above the goal line.
In 1912, the value of a touchdown was increased to six points. The end zone was also added. Before the addition of the end zone, forward passes caught beyond the goal line resulted in a loss of possession and a touchback. (The increase from five points to six did not come until much later in Canada, and the touchdown remained only five points there until 1956.)
The ability to score a touchdown on the point-after attempt (two-point conversion) was added to NCAA football in 1958, high school football in 1969, the CFL in 1975 and the NFL in 1994.