Usually when the ball goes out of bounds, the last team to touch the ball loses possession, similar to basketball. An exception is when it is ruled a shot. In that case, the team that backs up the shot, i.e., has a player closest to the ball where it goes out, retains possession. On offense, backing up the shot becomes the responsibility of the player who is behind goal line extended. That gives the offensive team an edge in retaining possession on a shot out of bounds, but it's not automatic.