Masonry basically makes sure that elements don't leave HUGE gaps between each other when arranged on a grid. This usually happens for CSS floated layouts if one element is bigger than the others. This elements ships the floating point, so a huge horizontal gap appears in the grid.
Masonry solves this problems by taking the vertical dimension into account when floating an element.
In its first versions, Masonry was a jQuery plugin, but with the recent versions, Masonry can be used as a standalone JS library as well.
There are lots of demos and examples on how to use Masonry included with the download package, along with various deviations on its concepts, and some extra support for infinite scrolling layouts, filtering, animations, and dynamic or responsive layouts.