Why do free and lshw show different RAM sizes?

In both cases, the difference is probably the amount of system RAM that's shared to the built-in graphics adapter. There is also some amount of RAM taken by the OS that doesn't show (it's usually a small amount, and varies depending on a number of factors, including kernel version and compiled-in drivers). This RAM isn't shown by free because it's not available for the OS to use at any time, but lshw is examining the hardware information, not the BIOS/OS reported RAM figures.