Understanding CRON Expressions: A Developer's Practical Guide
CRON expressions are one of those things every developer encounters but few take the time to learn properly. You copy one from Stack Overflow, tweak a number, and hope it fires at the right time. When it does not, you tweak another number and wait again.
This guide is the reference you can come back to. It covers the full CRON syntax, walks through practical patterns, and highlights the mistakes that trip people up most often.
What Is a CRON Expression?
A CRON expression is a string of five (or six) fields separated by spaces that defines a schedule. It originated in Unix-like operating systems for scheduling recurring tasks (cron jobs) but is now used in CI/CD pipelines, cloud functions, task queues, and countless other systems.
The standard five-field format looks like this:
┌───────────── minute (0–59)
│ ┌───────────── hour (0–23)
│ │ ┌───────────── day of month (1–31)
│ │ │ ┌───────────── month (1–12)
│ │ │ │ ┌───────────── day of week (0–7, where 0 and 7 are Sunday)
│ │ │ │ │
* * * * *
Each field accepts specific values, ranges, lists, and special characters.
The Five Fields Explained
1. Minute (0–59)
The minute within the hour when the task runs.
0— At the top of the hour30— At the half hour*/5— Every 5 minutes0,15,30,45— At four specific minutes
2. Hour (0–23)
The hour of the day in 24-hour format.
0— Midnight9— 9:00 AM14— 2:00 PM9-17— Every hour from 9 AM to 5 PM
3. Day of Month (1–31)
The calendar day.
1— The first of the month15— The 15th1,15— The 1st and 15th
4. Month (1–12 or JAN–DEC)
1orJAN— January6orJUN— June1-3— January through March
5. Day of Week (0–7 or SUN–SAT)
Both 0 and 7 represent Sunday.
1orMON— Monday1-5— Monday through Friday (weekdays)0,6— Saturday and Sunday (weekends)
Special Characters
| Character | Meaning | Example | Explanation |
|---|---|---|---|
* |
Any value | * * * * * |
Every minute |
, |
List | 1,15 * * * * |
At minute 1 and 15 |
- |
Range | 9-17 * * * * |
Every minute from hour 9 to 17 |
/ |
Step | */10 * * * * |
Every 10 minutes |
? |
No specific value (some systems) | 0 0 ? * MON |
Used in day-of-month when day-of-week is set |
Practical CRON Expression Examples
Here are the patterns you will use most often:
Run Every Minute
* * * * *
Useful for health checks or real-time processing queues.
Run Every Hour at Minute 0
0 * * * *
Standard for hourly reports or cache clearing.
Run Daily at Midnight
0 0 * * *
The classic daily job — database backups, log rotation, daily digests.
Run Every Weekday at 9:00 AM
0 9 * * 1-5
Perfect for business-hours tasks: daily standup reminders, opening reports.
Run Every Sunday at 2:00 AM
0 2 * * 0
Weekly maintenance windows: database optimization, weekly reports.
Run on the 1st of Every Month at Midnight
0 0 1 * *
Monthly billing runs, report generation, data archiving.
Run Every 15 Minutes
*/15 * * * *
Frequent polling tasks: checking external APIs, syncing data.
Run Every 6 Hours
0 */6 * * *
Periodic tasks that do not need hourly frequency.
Run at 8:30 AM on Weekdays
30 8 * * 1-5
Morning notification jobs, daily email summaries.
Run Quarterly (1st of Jan, Apr, Jul, Oct)
0 0 1 1,4,7,10 *
Quarterly reports, license renewals.
Common Mistakes and How to Avoid Them
Mistake 1: Confusing Day-of-Month and Day-of-Week
The expression 0 0 15 * 5 does not mean "the 15th if it is a Friday." In most cron implementations, when both day-of-month and day-of-week are specified, the job runs when either condition is true. So this runs on the 15th of every month and every Friday.
If you need "the 15th only when it falls on a Friday," you need application-level logic because standard cron cannot express that.
Mistake 2: Forgetting Time Zones
Cron jobs run in the server's time zone. If your server is in UTC and you schedule a job for 9:00 AM expecting your local time, it will run at the wrong hour. Always verify which time zone your cron daemon uses.
Mistake 3: Using */1 Instead of *
Both */1 and * mean "every unit." The first is just noisier. Use * for clarity.
Mistake 4: Overlapping Executions
If a job takes 10 minutes to run and is scheduled every 5 minutes, you will have overlapping instances. Use lock files, database flags, or tools like flock to prevent this:
*/5 * * * * /usr/bin/flock -n /tmp/myjob.lock /path/to/script.sh
Mistake 5: Not Logging Output
By default, cron jobs run silently. If something fails, you will not know unless you capture output:
0 0 * * * /path/to/script.sh >> /var/log/myjob.log 2>&1
Validating Your CRON Expressions
Writing a CRON expression and trusting it without verification is a recipe for surprises. Before deploying, always validate that the expression fires at the times you expect.
The CRON Calculator on ToolByte lets you:
- Enter any CRON expression
- See the next scheduled execution times
- Get a human-readable explanation of what the expression does
- Visually build expressions with an interactive interface
This is particularly valuable when working with complex schedules or when you inherit a cron job from someone else and need to understand what it does.
CRON in Modern Systems
While traditional cron runs on Linux servers, the same expression format appears in many modern tools:
- GitHub Actions —
scheduletrigger uses cron syntax - AWS CloudWatch Events / EventBridge — Supports cron expressions for Lambda scheduling
- Azure Functions — Timer triggers use CRON format (with a seconds field)
- Kubernetes CronJobs — Schedule pods using standard cron syntax
- Laravel — Task scheduling uses cron under the hood, though it provides a fluent API
Understanding cron syntax is a transferable skill that pays dividends across your entire infrastructure.
Quick Reference Cheat Sheet
| Schedule | Expression |
|---|---|
| Every minute | * * * * * |
| Every 5 minutes | */5 * * * * |
| Every hour | 0 * * * * |
| Every day at midnight | 0 0 * * * |
| Every Monday at 9 AM | 0 9 * * 1 |
| Weekdays at 8:30 AM | 30 8 * * 1-5 |
| 1st of every month | 0 0 1 * * |
| Every Sunday at 2 AM | 0 2 * * 0 |
| Every 6 hours | 0 */6 * * * |
| Twice daily (8 AM, 8 PM) | 0 8,20 * * * |
Conclusion
CRON expressions are a foundational piece of server-side development. Whether you are scheduling a nightly backup, triggering a CI pipeline, or sending a weekly email digest, the syntax is the same five fields with the same rules.
Take the time to learn the syntax properly instead of guessing and checking. Use the CRON Calculator on ToolByte to validate expressions before deploying them. It takes seconds and prevents the kind of scheduling surprises that are hard to debug after the fact.
For more developer tools and utilities, explore the full collection at ToolByte — built by Duo Dev Technologies for developers who value their time.
Category: Tools
Tags: CRON expressions, cron job, task scheduling, Linux cron, crontab, DevOps, server automation, developer tools, CRON calculator