To sign out of iCloud on your iPhone, go to Settings -> iCloud, scroll to the bottom of the screen, and select Sign Out. This will delete the iCloud account from your iPhone. It will not delete the account on any other devices you may have. Your iCloud data should still be available at https://www.icloud.com.
Once you select Sign Out, the iPhone will ask if you want to delete or keep the data on the iPhone. If you delete the data from the iPhone, all contacts and other iCloud data will be deleted from the iPhone. If you keep the iCloud data on the iPhone and sign in with a different Apple ID, the iCloud data (such as contacts and calendar data) can be merged to the iCloud account for the new Apple ID.
This article provides additional information about iCloud.
Posted in: iCloud