We study the two membranes problem for different operators, possibly nonlocal. We prove a general result about the Hölder continuity of the solutions and we develop a viscosity solution approach to this problem. Then we obtain C1,γ regularity of the solutions provided that the orders of the two operators are different. In the special case when one operator coincides with the fractional Laplacian, we obtain the optimal regularity and a characterization of the free boundary.