The method of rooting a device varies from make to make. An HTC or Sony phone will require a different method compared to a Samsung device. However, unrooting can be fairly easy. Ensure your device is fully charged and make a backup of all your contacts and data before proceeding.
The easiest way to unroot your device is by flashing an original, official firmware. Connect your device to your computer and use the manufacturer’s PC companion software to search for updates. If there is an update for your device, download and install it. The official firmware will overwrite your settings and your phone will be unrooted (your data may not be wiped).
Alternatively, you can also download an official firmware image to flash it manually. For Samsung devices, you can download official firm wares from the sammobile website. Once you have an image downloaded, copy it to your devices SD card and use Mobile Odin software to flash it. The new flash will result in your losing root (which is what you wanted).
If you rooted your device by flashing the Superuser zip file through recovery mode, you can flash the Superuser uninstall zip file (which should be available where you downloaded the install file from). Flashing the SU Uninstall file will also result in you losing root privileges.