The precise requirements for obtaining Indefinite Leave to Remain vary depending on a number of factors, including your age and current immigration status.
One of the main ILR requirements is residency - you must have been lawfully living in the UK for a certain length of time before you can apply, normally staying under one or more temporary visas. Your total qualifying period may cover times when you were lawfully resident in the UK under two different visas, for example if you initially entered on one type of visa and then switched to another type. You are usually able to apply for ILR within the final 28 days of your qualifying period, but no earlier.
The minimum period of residence in the UK that you must have completed before you can apply for ILR depends on your current visa status. In many cases you must have been living in the UK for a minimum period of 5 years (for example work permit, investor, minister of religion, writer, composer or artist, etc) - though there are exceptions that can raise or lower this minimum period.
For example, it may be possible to apply for permanent residence after just 2 years stay in the country if you are married or in a permanent unmarried relationship with a UK Citizen. And it may be possible to apply for permanent residence after a long-term lawful residence (10 years) or even partly unlawful residence (14 years) in the UK.
Additional requirements for ILR include passing the Knowledge of Language and the Life in the UK tests, as well as making sure you have no unspent convictions - including relatively minor offences such as traffic or motoring charges.
Although ILR is indefinite, it is still possible to have your ILR revoked if you break its conditions of issue. One of the main risks to your ILR status is if you leave the UK for a continuous period of two or more years, since this strongly suggests that the UK is not your main residence. In this situation it is possible that the Home Office may revoke your ILR status, because it was originally granted on the basis that you intended to 'remain' settled permanently in the UK. Because of this, if you wish to retain the right to stay in the UK but intend to travel abroad for long durations then you would be better off applying for full Citizenship, rather than just Indefinite Leave to Remain.