What specific factors allowed the North to defeat the Confederacy? Was victory inevitable?

What specific factors allowed the North to defeat the Confederacy? Was victory inevitable?