While in an inn or anywhere in a capital city, your player portrait will begin to glow and your level circle will say zzz, indicating that you are resting. If you log off here, you will continue to rest while offline.
One bar of rested XP (5% of a level) is earned for every 8 hours spent resting. A maximum of 30 bars (150% of a level) may be earned. In other words, you can leave your character resting in an inn or capital city for up to 10 days (without gaining experience) before you earn the maximum amount of rest state, and a resting character stores up one full level of rest in 160 hours (6.67 days).
You also become rested while logged off in the wilderness, but the accumulation is slower. When logged off "outside," rest is gained at one fourth the rate in an inn, or one bar every 32 hours.
It may also be possible to engage the resting state while in ghost form, or dead.