If you are on Mac, you can have tools for this. These tools are ordering sprites in an efficient way and generates the possible minimum sprite sheet. Also they are generating CSS output for you automatically. Thus, you don't need to fight with coordinates or counting pixels. You can use Sprite Master for this.