Solo has an accent when it means "only" and can be mistaken with "alone"when it means "only" and can be mistaken with "alone":
Compare this:
Voy a estar solo un día -> I'm going to stay alone for a day
To thisthese two sentences:
Voy a estar sólo un día -> I'm going to stay just one day
- Voy a estar solo un día. = I'm going to stay alone for a day.
- Voy a estar sólo un día. = I'm going to stay just one day.
When I learnt the rule, I was told "si puede sustituirse por únicamente, lleva tilde", but the actual rule is, "si puede sustituirse por únicamente y puede confundirse con sin compañía, lleva tilde". That said, I usually put the accent whenever it means "only".
You can find the The explanationexplanation by RAE in the DPD (Diccionario panhispánico de dudas).