To expand on the previous answers (and offer a small correction), CFR 14 part 61.65 states that:
(e) Logging pilot-in-command flight time.
(1) A sport, recreational, private, commercial, or airline transport
pilot may log pilot in command flight time for flights-
(i) When the pilot is the sole manipulator of the controls of an
which the pilot is rated, or has sport pilot privileges for that category and
class of aircraft, if the aircraft class rating is appropriate;
This has been interpreted by the FAA on several occasions as to mean that an SIC can log the time as a PIC when he is the one flying the aircraft. You can look for 'Legal Interpretation # 92-46' where this very same issue is addressed (they even specifically state that both the PIC and SIC can log PIC time in such cases).
Otherwise, as others have already mentioned, an SIC can log SIC time when he is a PNF and is performing the duties of an SIC (provided the type or operational certificate requires a two person crew).