If you search for golang length of map, golang map length, length of map golang, golang map len, golang len of map, golang get length of map, go map length, golang size of map, len of map golang, or go length of map, the usual answer is the built-in len: len(m) counts how many keys are in the map. That is different from summing items stored inside each value (for example scores in a slice per student). This page shows len, nil behavior, and how to count nested elements when that is what you really need. For map basics, see maps in Go; for loops, see for and range.
Tested with Go 1.24 on Linux.
golang map len: number of keys
len applied to a map[K]V returns an int: the count of key-value pairs.
package main
import "fmt"
func main() {
scoreRecord := map[string]float64{
"Ariana": 8.6,
"Bob": 9.3,
"Clover": 7.8,
"Daniel": 9,
}
fmt.Println(scoreRecord)
fmt.Println("len:", len(scoreRecord))
}Running the program prints the four-entry map and len: 4.
Nil maps and golang len of map
A nil map has length 0. You still cannot assign to keys until the map is initialized with make or a literal:
package main
import "fmt"
func main() {
var m map[string]int
fmt.Println("nil len:", len(m))
m = map[string]int{"a": 1}
fmt.Println("after literal len:", len(m))
}nil len: 0
after literal len: 1Counting values inside entries (not golang map length)
If each map value is itself a collection, len(m) still counts keys, not inner elements. Sum inner lengths only when that is the metric you want:
package main
import "fmt"
func main() {
scoreRecord := map[string][]float64{
"Ariana": {5.3, 7.3, 6.9},
"Bob": {8.3, 8.7, 9.2},
"Clover": {7.6, 9.2},
"Daniel": {8.8, 9.0, 8.9},
}
fmt.Println("keys:", len(scoreRecord))
n := 0
for _, scores := range scoreRecord {
n += len(scores)
}
fmt.Println("total scores stored:", n)
}keys: 4
total scores stored: 11Summary
Golang length of map and golang map len mean len(m) for the key count. Golang size of map in the informal sense is usually that same count, not bytes on the heap. len of a nil map is 0. If you need a total across nested slices or maps, loop and add lengths—do not confuse that total with len of the outer map.

