Crontab Expressions, Explained
After reading this you will be able to read any five-field cron expression out loud, predict its next run times, and build one from scratch without guessing at the syntax.
What a cron expression is
Cron is the scheduler built into Unix and Linux systems. It reads a file called a crontab, checks the clock once per minute, and runs any command whose schedule matches the current minute. The schedule is written as five fields separated by spaces. Here is one that runs at 9:30 every weekday morning:
Read left to right, the fields are minute, hour, day of month, month, and day of week. So 30 9 * * 1-5 means minute 30, hour 9, any day of the month, any month, and days of the week 1 through 5 (Monday through Friday). A cron daemon wakes up at 09:30 on Monday, sees a match, and fires the command.
The value * means "every value in this field." A comma lists values, so 1,15 in the day-of-month field means the 1st and the 15th. A hyphen makes a range, so 9-17 means every hour from 9 through 17. A slash adds a step: */5 in the minute field means every fifth minute (0, 5, 10, and so on).
When to use it and when not
Cron is the right tool for repeating work on a wall-clock schedule: a nightly database backup, an hourly cache refresh, a report emailed every Monday at 08:00. The Crontab Builder helps you produce that expression when you know the schedule in plain words but not the syntax.
Cron is the wrong tool for three cases. First, one-time jobs: use at or a queued task instead, because cron repeats forever until you remove the line. Second, sub-minute intervals: the smallest field is minutes, so you cannot schedule "every 30 seconds" directly. Third, jobs that must run exactly once even if the machine was asleep at the scheduled minute: standard cron simply skips a missed run. Tools like anacron or systemd timers cover that gap.
Cron uses the system timezone unless you set one explicitly. A job written as 0 2 * * * ("02:00 daily") can run at 02:00 twice on the night clocks fall back, and skip 02:00 entirely on the night clocks spring forward. If the exact wall-clock time matters, schedule outside the 01:00 to 03:00 window.
The five fields and their ranges
Each field accepts a fixed range of integers. Get the range wrong and cron either rejects the line or, worse on some systems, silently never matches.
| Field | Position | Range | Special notes |
|---|---|---|---|
| Minute | 1 | 0-59 | Most granular field |
| Hour | 2 | 0-23 | 24-hour clock, no AM/PM |
| Day of month | 3 | 1-31 | 1-based |
| Month | 4 | 1-12 | Names like JAN allowed on many crons |
| Day of week | 5 | 0-7 | 0 and 7 both mean Sunday |
The day-of-week field is the classic trap. Both 0 and 7 mean Sunday, so Sun-Sat can be written 0-6 or 1-7. Monday is always 1. When you build with dropdowns you never type these numbers, but you still see them in the generated expression, and you should recognize them.
How cron decides whether a minute matches
Once per minute cron takes the current time and asks a yes or no question for each of the five fields. The command runs only when the answer is yes for the minute, hour, and month fields, plus a special rule for the two day fields.
Here M, H, and \text{Mon} are true when the current minute, hour, and month appear in their fields. D is true when the day of month matches and W is true when the day of week matches. The symbol \wedge means AND, and \vee means OR.
The critical detail is that the two day fields are joined with OR, not AND, but only when both are restricted. If you write 0 0 13 * 5, the job runs on the 13th of every month AND on every Friday, not just Friday the 13th. To hit only Friday the 13th you need extra logic in the command itself. When one day field is *, the OR reduces to the other field, which is the case you usually want.
A worked example with the tool defaults
Building "every 5 minutes"
Load the Crontab Builder and press the demo button. The defaults produce the expression */5 * * * *. Walk through why it fires when it does.
- The minute field is
*/5. Cron starts at 0 and steps by 5, giving the set {0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55}. That is 12 matching minutes per hour. - The hour field is
*, so every hour from 0 through 23 qualifies. That is 24 hours. - Day of month, month, and day of week are all
*, so every day qualifies. - Total runs per day: 12 \times 24 = 288. Per week that is 288 \times 7 = 2016 runs.
Starting from 09:02, the next four runs are 09:05, 09:10, 09:15, and 09:20. Notice cron does not run five minutes after the current instant; it runs at the next clock minute divisible by 5. If you started the job at 09:04, the first run is still 09:05, only one minute later.
Reading the next-runs preview
The builder shows a live list of upcoming run times. Use it to catch mistakes the raw expression hides. Two patterns are worth checking every time.
First, uneven spacing from a step that does not divide 60. Write */7 in the minute field and the matches are 0, 7, 14, 21, 28, 35, 42, 49, 56, then back to 0 at the top of the next hour. The gap from 56 to the next 0 is only 4 minutes, not 7. The chart below shows the jump.
Second, check whether the day-of-month and day-of-week fields are both set. If the preview shows runs on days you did not expect, the OR rule from the matching formula is probably the reason.
Common mistakes
- Confusing hour 12 with noon versus midnight
- Cron uses a 24-hour clock. Midnight is
0, noon is12, and there is no such thing as24. Writing0 24 * * *is invalid on strict crons. - Expecting "every N minutes" from a fixed start
*/30runs at :00 and :30, tied to the clock, not 30 minutes after you save the crontab.- Assuming both day fields must match
- As shown above, restricted day-of-month and day-of-week fields combine with OR, so the job may run more often than you intended.
- Forgetting the environment
- Cron runs with a minimal
PATHand no shell profile. A command that works in your terminal can fail under cron because a binary is not found. Use absolute paths.
Test a new schedule with a harmless command first, such as appending the date to a log file. Watch the log for a few cycles, confirm the timing, then swap in the real command.
Related tools
Once you have an expression you can move between the schedule and the clock with a few related tools on this site.
- To explain an expression you already have and see its next runs, use the Cron Expression Parser.
- To convert a run time into a Unix timestamp or an ISO 8601 string, use the Unix Timestamp Converter.
- If a log line gives you a raw number and you are unsure of its unit, the Epoch Millis vs Seconds Detector tells you whether it is seconds or milliseconds.
- For jobs that stamp records with identifiers, the ID Decoder extracts the embedded timestamp, and the UUID / ULID / Nano ID Generator produces fresh ones in bulk.
Frequently asked questions
How do I run a job every 30 seconds with cron?
You cannot do it with a single cron line, because the minute is the smallest field. The common workaround is two lines that both run every minute, with the second one delaying itself: * * * * * command and * * * * * sleep 30; command.
What does the fifth field really mean when it is a number?
The fifth field is day of week. 0 and 7 both mean Sunday, 1 is Monday, and 6 is Saturday. Many crons also accept three-letter names like MON.
Why did my daily job run twice one night?
Daylight saving time. When clocks fall back, the hour from 01:00 to 02:00 repeats, so any job scheduled inside it can fire twice. Schedule outside 01:00 to 03:00 to avoid it.
Does the builder run cron on my machine?
No. It only produces the expression text for you to paste into a real crontab. Everything runs in your browser, and nothing you enter leaves your device.
What is the difference between */15 and 0,15,30,45?
Nothing in this case. Both match minutes 0, 15, 30, and 45. The step form is shorter, and the list form is clearer when the values are not evenly spaced.