Does rooting wipe the /sdcard? I recently rooted my nexus 5 phone and lost all of my photos :( I was wondering what rooting actually does. Is it like formatting the disk and updating file tables or is it like deleting all the sectors? In the former case is it possible to recover my photos?

I used chainfire for rooting the phone. For that, I turned off the phone and turned it on while pressing +- volume buttons. Then I ran the script contained in http://download.chainfire.eu/363/CF-Root/CF-Auto-Root/CF-Auto-Root-hammerhead-hammerhead-nexus5.zip Later I realized that all of my apps, photos, etc are gone. I don't care about the apps because they were automatically installed after setup. Just need to recover my photos.
The Official XDA Discussion for CF Auto-Root (The tool OP linked) includes the following line: 


  Note that if your device had not been unlocked before, this procedure will wipe all your data!


So to answer your question:


Does rooting format the /sdcard/ partition?

No, rooting alone will not format the partition mounted at /sdcard/.
When I root for the first time, or root using a tool, could this happen?

Yes. When using a tool provided by a third party (EG: Not you or Google), then you're following the steps their tool defines.

When you first gain root, one of the steps involves unlocking the bootloader. This is really only necessary once, Unlocking the bootloader will perform a full factory reset, erasing everything.