An H-1B petition may be valid for up to three years. H-1B petition may be extended for an additional period of up to three years, to a maximum of six years. At the end of the sixth year, the individual must return home for a year before obtaining any new H-1B visas if the individual cannot change into another temporary or permanent visa category.
Recapture of time spent outside the U.S. while in H-1B status is available since the six year maximum only applies to time spent in H-1B status in the U.S.
In some limited circumstances you may be eligible for H-1B extensions past the six year limit. For example, if you have a labor certification application, visa petition or adjustment of status application pending for more than one year, you may receive a year-to-year extensions after the sixth year. If you are a beneficiary of an approved I-140 Petition and an immigrant visa is not available, extensions of three years may be available.