The Torah (Lev. 12:15) commands, "You shall count for yourselves -- from the day after the Shabbat, from the day when you bring the Omer of the waving -- seven Shabbats, they shall be complete." The phrase the "day after Shabbat" is interpreted as meaning the day after the first day of Passover, which is a "Shabbat" in the sense that work is prohibited.
The blessing for the counting is said at the end of the evening prayers but also may be recited during the night. Anyone who forgot to count the Omer at night may do so without the blessing during the following day and then resume reciting the blessing in the evening. Anyone who forgot to recite the counting throughout an entire 24-hour period should continue to count without the blessing and say, "Today is the 23rd day, which is three weeks and two days of the Omer."