abstract: We study stable solutions to two, closely related, nonlocal problems: the fractional minimal surfaces equation and the fractional Allen-Cahn equation. In particular, we establish optimal energy estimates, whose local analogue is still unknown. These estimates, together with other ingredients (such as density estimates and a monotonicity formula) allow to prove flatness of level sets. These results have been obtained in collaboration with X. Cabré, J. Serra, and E. Valdinoci.