The key principle is that the software should always correctly work at any point in the chain of commits, so you must squash commits that are "oops, fix X in previous commit".
Once that is satisfied, commits should be as small as possible, so that information about the grouping of changes is preserved.