To become a US citizen you will have to show continuous residence in this country. How long you must live here depends on the nature of your immigration application.
Because people's citizenship applications are based on different grounds -- for example: work, humanitarian grounds, or marriage to an American spouse -- the rules vary somewhat, and there are also limited exceptions to the continuous residence requirement. Let's look at the obligations, and when the clock starts ticking.
Your residence clock starts running on the day you become a Lawful Permanent Resident (LPR) and receive a green card. The date of receipt is written on your green card.
For people whose green card is based on a marriage to a US citizen spouse, the residence requirement is three years. For those whose immigration status is based on work or humanitarian grounds, then you must show five years continuous residence from the date on your green card.
So it really doesn't matter if you spent years in the US with no status or just arrived and immediately got engaged to an American. The date that counts for purposes of continuous residence is the one on your green card and not the one of your actual arrival in the US.
Continuous residence refers to your living situation and intent to reside in the US, rather than to travel. What that means is you can visit people abroad or go on business trips if you have LPR status. So long as you can prove that you have not broken the chain of continuous residence, you do not jeopardize citizenship.
But if you move with an intent to remain abroad, or spend more than six months abroad without showing you still live in the US, or travel for a year without applying for a resident re-entry visa, you jeopardize your continuous residence count. Similarly, if you apply for a benefit as a non-resident or fail to file taxes because you don't consider yourself a resident, the count could be disrupted.
Any LPR who needs to travel for work or family should certainly do so and just make sure that the dates are safe with respect to the continuous residence requirements. Anyone interested in seeing the world, should consider staying in the US, rather than risking a challenge to your continuous residence.
But remember, if you can show evidence of your intent to reside in the US, you can prove that your residence was continuous. Similarly, there are limited exceptions to the continuous residence requirement that apply to those who worked for the US Government abroad or certain other institutions.
Talk to a Lawyer
If you are concerned about continuous residence or any other aspect of the immigration process, speak to a lawyer. Many immigration attorneys consult for free or a minimal fee and will be happy to assess your case.